I'm a rookie at using Hibernate, so please bear with me.
I have User object that has a one-to-many mapping to a Resume object. I am getting the exception below when trying to persist the resume.
I believe I might be doing something wrong with the addMethod method on my DAO. The passed in "resume" object already has a "user" object set on it.
public Resume addResume(Resume resume)
throws DAOException
{
User user = null;
Session ses = null;
try
{
ses = sessionFactory.openSession();
// validate that a user exists for this resume
if (resume.getUser() == null) {
throw new DAOException("No user assigned to resume!");
}
ses.save(resume);
ses.flush();
ses.connection().commit();
}
catch (Exception e)
{
try { ses.connection().rollback(); }
catch (Exception ex) { e.printStackTrace(); };
throw new DAOException(e);
}
finally
{
try { ses.close(); }
catch (Exception ex) { ex.printStackTrace(); };
}
return resume;
}
Testcase: testAddResume(org.apache.persistence.ApplicationDAOHibernateTest): Caused an ERROR
java.lang.ClassCastException
org.apache.persistence.DAOException: java.lang.ClassCastException
at org.apache.persistence.ApplicationDAOHibernate.addResume(ApplicationDAOHibernate.java:146)
at org.apache.persistence.ApplicationDAOHibernateTest.testAddResume(ApplicationDAOHibernateTest.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Caused by: java.lang.ClassCastException
at cirrus.hibernate.type.StringType.set(StringType.java:20)
at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:32)
at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:24)
at cirrus.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:394)
at cirrus.hibernate.persister.EntityPersister.insert(EntityPersister.java:476)
at cirrus.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:20)
at cirrus.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:1674)
at cirrus.hibernate.impl.SessionImpl.execute(SessionImpl.java:1654)
at cirrus.hibernate.impl.SessionImpl.flush(SessionImpl.java:1599)
at org.apache.persistence.ApplicationDAOHibernate.addResume(ApplicationDAOHibernate.java:139)
... 15 more