Results 1 to 3 of 3

Thread: Java Cast Exception

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Posts
    25

    Default Java Cast Exception

    Hello,

    I have a problem with a findByPrimaryKey method which I have in my

    Data Access Object File. The method returns a java List and I am casting

    to a list in my code but I get java.lang.ClassCastException. ANY idea why the exception could be occurring? - many thanks.

    List heldPrice = (List)

    super.getHandle().findByPrimaryKey(item.getComposi te_id);

    The handle is fine and composite_id passed appears to have been built correctly. It is made up of three fields.

    The composite_id was set using the setter method for it on the Item object.

    Item is a DB Table and has a object representation as Item with itemDAO being the data access mapping file.

    the itemDAO has the following method:

    public final List findByPrimayKey(final ItemPK itemPK)
    throws finderDAOException{

    Object [] ObjectArray = ( itemPK.getItem(),
    itemPK.getItemDate,
    itemPK.getSource()};
    Type[] Array = { Hibernate.BIG_DECIMAL,

    Hibernate.BIG_DECIMAL,

    Hibernate.String};

    return get HibernateTemplate().find(
    " from Item item where item.composite_id.item = ?" +
    " and item.composite_id.itemDate =?" +
    " and item.composite_id.itemSource =?",
    ogbjectArry,
    typrArray);
    }
    }
    }

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Aslam,

    Have you checked the error output to see what class it the compiler says you are trying to cast what class? You might you've accidentally imported a different List class. There should be no problem casting from java.util.List to java.util.List.

    Rob

  3. #3
    Join Date
    Sep 2004
    Posts
    25

    Default

    Hi,

    You are right. Someone changed the DAO object and the casting needed changng from List to aspecif user class!

    Thanks.

Similar Threads

  1. class cast exception while lookup
    By kannak7 in forum Data
    Replies: 1
    Last Post: Oct 22nd, 2005, 04:51 PM
  2. Replies: 3
    Last Post: Oct 5th, 2005, 08:39 AM
  3. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  4. Replies: 0
    Last Post: Jul 11th, 2005, 05:49 PM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •