-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: not-null property references a null or transient value error
PostPosted: Mon Jun 20, 2005 8:23 am 
Newbie

Joined: Mon Jun 20, 2005 7:54 am
Posts: 3
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()


Top
 Profile  
 
 Post subject: _backref?
PostPosted: Sat Jul 09, 2005 5:13 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
Did you ever figure out what _backref meant? I'm facing the same situation... no clue where to start. Thanks!


Top
 Profile  
 
 Post subject: Re: _backref?
PostPosted: Sun Jul 10, 2005 11:57 am 
Newbie

Joined: Mon Jun 20, 2005 7:54 am
Posts: 3
Nope. I posted a bug here: http://opensource.atlassian.com/project ... se/HHH-659 but it got rejected with no explanation of what I was supposedly doing wrong, and it despite the fact that I posted an isolated test case as requested it was completely ignored. Not exactly encouraging people to try to do the right thing. :(

We're just avoiding merge() now because I clearly don't understand how it works, and it doesn't do what the javadoc says.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is no test case attached to that issue, just some code written into a comments box. This is certainly not considered the "right thing".

As for the actual exception, it is telling you that Hibernate cannot find any Questionnaire associated with the session that owns the Page. The "null or transient value" is the Questionnaire foreign key that is needed to insert the Page instance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:57 pm 
Newbie

Joined: Mon Jun 20, 2005 7:54 am
Posts: 3
gavin wrote:
There is no test case attached to that issue, just some code written into a comments box. This is certainly not considered the "right thing".


As mentioned in the comment, I couldn't see anywhere to attach/upload files, assuming that that is preferred. There's no "Attach file" link under the Operations heading in JIRA. Perhaps my JIRA user doesn't have the appropriate permissions? How would you prefer to receive such code? Having gone to the effort to build an isolated test case I would have been more than happy to make it available in another way had I been asked / instructed.

gavin wrote:
As for the actual exception, it is telling you that Hibernate cannot find any Questionnaire associated with the session that owns the Page. The "null or transient value" is the Questionnaire foreign key that is needed to insert the Page instance.


The Questionnaire object is what was actually passed to the merge() method. The only reason that the Page object is being examined for a merge is that it's a child object of the Questionnaire which was passed in, so hibernate must know about it.

There's no link from the page to the questionnaire here, the collection is not inverse. Perhaps that's the problem? If it were inverse and we had a property on the child pointing back to the parent then we could declare it not-null to force the parent to get saved first? Is that necessary? Since hibernate is complaining, it would seem to already understand that that's needed.

If cascade=merge (or indeed cascade=all) doesn't cover a case of two transient objects in this relationship being passed to merge() then what exactly does it mean?

It has to be said that the error message itself is pretty cryptic. It refers to a non-existant property on the Page object. As a user I looked at it and said "It's complaining about a non-existant property being null, wtf? The only thing that it could possibly be referring to is the Questionnaire, but I've just passed that to hibernate, so it can't not know about it."

If I truly am doing that isn't allowed then fair enough, but it would be nice to understand why passing two transient objects in this relationship to save() works, but passing them to merge() doesn't, given the javadoc for merge().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I think I understand the issue now, and, frankly, I'm not really very fussed by it.

http://opensource.atlassian.com/project ... se/HHH-749

(Note that nobody else seems to be having any problems attaching files. Perhaps you weren't logged in.)


Top
 Profile  
 
 Post subject: Problem also occurs with bidirectional
PostPosted: Thu Dec 22, 2005 3:53 pm 
Newbie

Joined: Fri Mar 26, 2004 1:01 pm
Posts: 12
I got the same problem with a bidirectional association, FWIW. It is fixed in 3.1, thank goodness.

I had an entity with a bidirectional, one-to-many association, cascade all delete orphan, inverse false. If I tried to save it using session.merge(), I got the same not-null property references a null or transient value error described above. After much playing around I saw this post, upgraded to 3.1, and everything works exactly as I expected it would:

Hibernate fetches a copy of my entities from the database, then generates the needed updates, inserts, and deletes.

Thanks, Gavin!


Top
 Profile  
 
 Post subject: Try save()
PostPosted: Mon Mar 20, 2006 6:59 pm 
Newbie

Joined: Tue Aug 09, 2005 4:01 am
Posts: 7
You can try using save() if object is persisted (test id for unsaved-value) and only then making a merge() on the object

_________________
Regards,
Alexander Kamburov

wise_guybg at yahoo.com


Top
 Profile  
 
 Post subject: Re: not-null property references a null or transient value error
PostPosted: Mon Apr 12, 2010 3:13 pm 
Newbie

Joined: Tue Jan 05, 2010 2:33 pm
Posts: 15
Set not-null="false" for values which can be null in your object


Top
 Profile  
 
 Post subject: Re: not-null property references a null or transient value error
PostPosted: Mon Sep 13, 2010 4:47 pm 
Newbie

Joined: Tue Jan 05, 2010 2:33 pm
Posts: 15
WHat do you have set as the primary key in your mappings file? I had this problem when I was using "assigned" for my identity.

I changed to this :

Code:
  <id name="id" type="int">
                <column name="INT_ID" />
                <generator class="identity" />
            </id>


Now things are operating smoothly.

Hope this helps.

Spunog


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.