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.