Announcement Announcement Module
Collapse
No announcement yet.
Java Cast Exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      Hi,

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

      Thanks.

      Comment

      Working...
      X