Tuesday, April 15, 2014

question about casting

Hi,

Can you please explain the casting rule on this example? Why does it cause exception?

Thanks

The userProfileDO is the object extracted from database through hibernate
ArrayList<Contact> tmpContactList = (ArrayList<Contact>) userProfileDO.getContacts();


//warning message: List is a raw type. References to generic type List<E> should be parameterized
    public List getContacts()
    {
        return this.contacts;
    }

The above ArrayList<Contact> casting caused exception
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.project.frontpage.client.serialize.UserProfile com.rentorama2.frontpage.client.rpc.Access.getUserProfile(long) throws com.project.frontpage.client.serialize.LoginServiceException' threw an unexpected exception: java.lang.ClassCastException: org.hibernate.collection.PersistentList cannot be cast to java.util.ArrayList
......
Caused by: java.lang.ClassCastException: org.hibernate.collection.PersistentList cannot be cast to java.util.ArrayList
    at com.project.frontpage.server.dao.UserProfileDAO.getUserProfile(UserProfileDAO.java:250)
    at com.project.frontpage.server.impl.AccessImpl.getUserProfile(AccessImpl.java:655)

No comments:

Post a Comment