From: Matt R. <ma...@ra...> - 2002-12-22 10:48:24
|
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(ApplicationDAOH ibernate.java:146) at org.apache.persistence.ApplicationDAOHibernateTest.testAddResume(Applica tionDAOHibernateTest.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.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.jav a:394) at cirrus.hibernate.persister.EntityPersister.insert(EntityPersister.java:4 76) 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(ApplicationDAOH ibernate.java:139) ... 15 more |
From: Konstantin P. <kpr...@ya...> - 2002-12-22 13:59:37
|
--- Matt Raible <ma...@ra...> wrote: > 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. > It looks that it does not like your classes... Unfortunately you did not provided line numbers in yur snippet - si I can not say what exactly offendet hibernate... regards, ===== Konstantin Priblouda ( ko5tik ) Freelance Software developer < http://www.pribluda.de > < play java games -> http://www.yook.de > < render charts online -> http://www.pribluda.de/povray/ > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com |
From: Matt R. <ma...@ra...> - 2002-12-22 17:48:45
|
I got it to work by looking at your example Konstantin. Thanks! Now I'm having a problem where I want to set a unique contraint on name and userId in my resume table. Following Konstantin's example, I have my one-to-many relationship information on my User class, and the Resume class just has a userId column. In other words, the Resume knows nothing about the relationship (right). Is it possible to change my getResume's xdoclet tags to handle this? /** * Returns the resumes. * @return Set * * @hibernate.set role="resumes" table="resume" * @hibernate.collection-key column="id" length="32" * @hibernate.collection-one-to-many class="org.apache.persistence.Resume" * @ejb.persistence */ public Set getResumes() { return resumes; } Thanks, Matt > -----Original Message----- > From: hib...@li... > [mailto:hib...@li...] On > Behalf Of Konstantin Priblouda > Sent: Sunday, December 22, 2002 7:00 AM > To: Matt Raible > Cc: hibernate-devel > Subject: Re: [Hibernate] Problem using Xdoclet to generate > relationships [newbie] > > > > --- Matt Raible <ma...@ra...> wrote: > > 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. > > > > It looks that it does not like your classes... > Unfortunately you did not provided line numbers in yur > snippet - si I can not say what exactly offendet > hibernate... > > regards, > > ===== > Konstantin Priblouda ( ko5tik ) Freelance Software developer > < http://www.pribluda.de > < play java games -> http://www.yook.de > < render charts online -> http://www.pribluda.de/povray/ > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list hib...@li... https://lists.sourceforge.net/lists/listinfo/hibernate-devel |
From: Konstantin P. <kpr...@ya...> - 2002-12-22 18:28:29
|
--- Matt Raible <ma...@ra...> wrote: > I got it to work by looking at your example > Konstantin. Thanks! > > Now I'm having a problem where I want to set a > unique contraint on name > and userId in my resume table. Following > Konstantin's example, I have > my one-to-many relationship information on my User > class, and the Resume > class just has a userId column. In other words, the > Resume knows > nothing about the relationship (right). > > Is it possible to change my getResume's xdoclet tags > to handle this? Give XDoclet GUI a spin - it provides [rudientary] help in tagging your classes... And also some explanations. regards, ===== Konstantin Priblouda ( ko5tik ) Freelance Software developer < http://www.pribluda.de > < play java games -> http://www.yook.de > < render charts online -> http://www.pribluda.de/povray/ > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com |