-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help with PropertyValueException: property references a null
PostPosted: Wed Nov 30, 2005 2:26 pm 
Newbie

Joined: Fri Nov 18, 2005 6:31 pm
Posts: 4
Location: Indiana, USA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1RC3

I have 2 persistent objects "A" and "B". There exists a many-to-one relationship from B to A.

Mapping file for "B":
<many-to-one name="account" update="false" class="com.mycompany.A">
<column name="ACCT_ID" not-null="true" />
</many-to-one>

Code:
1) I retrieve an A within one Hibernate Session and close:
Code:
Session session = HibernateUtil.getSession();
    Criteria c = session.createCriteria(A.class).add(
        Restrictions.eq("accountId", "2100"));
    A acct = (A) c.uniqueResult();
    HibernateUtil.closeSession();

2) I then set "A" onto B by:
Code:
B b = new B();
b.setAccount(acct);

3) When I try and save B, via session.saveOrUpdate(), I get:
Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.mycompany.B.account


I successfully retrieve "A" from the database and close the session. However, in the debug, Hibernate is not setting the "accountId" column in the prepared statement and then I get the "null" error.

Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:20 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Code:
<many-to-one name="account" update="false" class="com.mycompany.A">
<column name="ACCT_ID" not-null="true" />
</many-to-one>

have you mapped column ACCT_ID in B - you have update=false, but you have to maping with another property, maybe

try with update="true"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.