Tutorials for Hibernate, EJB 2, EJB 3
Struts, JavaServerfaces (JSF)
Tomcat, JBoss, Myeclipse, Eclipse and other

bugs-and-exceptions » org.hibernate.PropertyValueException

Sprache / Language

Navigation
org.hibernate.PropertyValueException: not-null property references a null or transient value 

 

Solution

The relation from customer to order was not properly set before saving the order.

getSession().lock(customer, LockMode.UPGRADE);
order.setCustomer(customer);
getSession().save(order);

was used instead of

getSession().lock(customer, LockMode.UPGRADE);
customer.getOrders().add(order);
order.setCustomer(customer);
getSession().save(order);

 

<hibernate-mapping package="de.laliluna.webstock">
  <class name="Order" table="torder">
    <id name="id">
      <generator class="sequence">
        <param name="sequence">torder_id_seq</param>
      </generator>
    </id>

 

    <many-to-one name="customer" class="Customer"></many-to-one>

  </class>

</hibernate-mapping>

Exception Message

Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value: de.laliluna.webstock.Order._ordersBackref
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)




Java Persistence and Hibernate Training

I offer training on Hibernate and Java Persistence (Glassfish with Oracle Toplink or JBoss).
Get more information.

Consulting / Development

I am a freelancer and can be booked for your projects. In cooperation with other specialists, you have even access to a development team of highly qualified experts.
Get more information.

Hibernate and Java Persistence Developer Guide
Hibernate Buch cover klein

XML and Annotations, Performance chapter, Hibernate search, Integration with Spring, EJB3 and JSF
Available as up to date ebook
Get more information.

News 
Window Id - Practical use cases (Blog) (Jan. 18, 2010)
GWT tip - better exception logging on the server (Blog) (Dec. 18, 2009)
Sandheap theory (Blog) (Dec. 04, 2009)
Oh JavaFX, Oh JavaFX - why don't you progress? (Blog) (Dec. 01, 2009)
Devoxx 2009 Presentation (Nov. 18, 2009)
Window Id Browser Extension (Blog) (Nov. 13, 2009)
Performance Tuning Tips for Hibernate and Java Persistence (Jan. 27, 2009)
Hibernate / Java Persistence eBook update (Jan. 27, 2009)
Hibernate Search with Lucene (Jan. 12, 2009)
Notes from the Devoxx Conference (Dec. 16, 2008)
Copyright (c) 2004-2009 by Sebastian Hennebrueder, laliluna.de Impressum