Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi all. This error is pretty weird, I can't quite work out what's going on. The _backref thingy is particularly bizarre. If I take the page object out (ie if I don't set the pages property), the questionnaire saves ok. If I take the not-null off the <key> element, I get a foreign key constraint violation, as expected.
Any help greatly appreciated.
Cheers
Tom
Hibernate version: 3.0.5
Mapping documents:
(ids, versions and other irrelevant stuff removed for simplicity)
Code:
<class name="Questionnaire" table="Questionnaire" lazy="false">
<list name="pages" cascade="all">
<key column="pag_qun_id" not-null="true" />
<list-index column="pag_Number" base="1"/>
<one-to-many class="Page"/>
</list>
</class>
<class name="Page" table="Page" lazy="false">
<!-- the value of this is set by the mapping in the questionnaire class -->
<property name="pageNumber" column="pag_Number" update="false" insert="false"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
Questionnaire qr = new Questionnaire();
List<Page> pages = new ArrayList<Page>();
Page currentPage = new Page();
pages.add(currentPage);
qr.setPages(pages);
// saved here in a spring DAO etc using merge(q). Saves the questionnaire fine if I don't add a page
Full stack trace of any exception that occurs:Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: participate.model.questionnaire.Page._pagesBackref
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:236)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:157)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:104)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:544)
at org.hibernate.engine.Cascades$6.cascade(Cascades.java:176)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:264)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:149)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:104)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:54)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:539)
at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:665)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:662)
at participate.persistence.questionnaire.QuestionnaireDAOHibernate.saveQuestionnaire(QuestionnaireDAOHibernate.java:54)
at participate.persistence.questionnaire.QuestionnaireDAOHibernate$$FastClassByCGLIB$$5d58c319.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:661)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:606)
at participate.persistence.questionnaire.QuestionnaireDAOHibernate$$EnhancerByCGLIB$$ee6f6438.saveQuestionnaire(<generated>)
at participate.persistence.questionnaire.QuestionnaireDAOTest.testCreate(QuestionnaireDAOTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Name and version of the database you are using: MS SQL Server 2000
The generated SQL (show_sql=true): not an SQL exception, didn't get that far
Debug level Hibernate log excerpt:Code:
2005-06-20 21:35:31,202 DEBUG SessionImpl opened session at timestamp: 4584526361403392
2005-06-20 21:35:31,212 DEBUG ConnectionManager opening JDBC connection
2005-06-20 21:35:31,212 DEBUG JDBCTransaction begin
2005-06-20 21:35:31,212 DEBUG JDBCTransaction current autocommit status: true
2005-06-20 21:35:31,222 DEBUG JDBCTransaction disabling autocommit
2005-06-20 21:35:31,222 DEBUG AbstractSaveEventListener transient instance of: participate.model.questionnaire.Questionnaire
2005-06-20 21:35:31,222 DEBUG DefaultMergeEventListener merging transient instance
2005-06-20 21:35:31,222 DEBUG Cascades processing cascade ACTION_MERGE for: participate.model.questionnaire.Questionnaire
2005-06-20 21:35:31,222 DEBUG Cascades cascade ACTION_MERGE for collection: participate.model.questionnaire.Questionnaire.pages
2005-06-20 21:35:31,222 DEBUG Cascades$6 cascading to merge: participate.model.questionnaire.Page
2005-06-20 21:35:31,232 DEBUG AbstractSaveEventListener transient instance of: participate.model.questionnaire.Page
2005-06-20 21:35:31,232 DEBUG DefaultMergeEventListener merging transient instance
2005-06-20 21:35:31,232 DEBUG AbstractSaveEventListener saving [participate.model.questionnaire.Page#<null>]
2005-06-20 21:35:31,262 DEBUG AbstractSaveEventListener executing insertions
2005-06-20 21:35:31,262 DEBUG Versioning Seeding: 1
2005-06-20 21:35:31,272 DEBUG JDBCTransaction rollback
2005-06-20 21:35:31,272 DEBUG JDBCContext before transaction completion
2005-06-20 21:35:31,282 DEBUG SessionImpl before transaction completion
2005-06-20 21:35:31,282 DEBUG JDBCTransaction re-enabling autocommit
2005-06-20 21:35:31,282 DEBUG JDBCTransaction rolled back JDBC Connection
2005-06-20 21:35:31,282 DEBUG JDBCContext after transaction completion
2005-06-20 21:35:31,282 DEBUG ConnectionManager aggressively releasing JDBC connection
2005-06-20 21:35:31,282 DEBUG ConnectionManager closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-06-20 21:35:31,282 DEBUG SessionImpl after transaction completion
2005-06-20 21:35:31,292 DEBUG ConnectionManager opening JDBC connection
2005-06-20 21:35:31,292 DEBUG SessionImpl closing session
2005-06-20 21:35:31,292 DEBUG ConnectionManager closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-06-20 21:35:31,292 DEBUG JDBCContext after transaction completion
2005-06-20 21:35:31,292 DEBUG ConnectionManager aggressively releasing JDBC connection
2005-06-20 21:35:31,292 DEBUG SessionImpl after transaction completion
2005-06-20 21:35:31,302 DEBUG ConnectionManager running Session.finalize()