-->
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.  [ 9 posts ] 
Author Message
 Post subject: not-null property references a null or transient value
PostPosted: Fri Oct 21, 2005 2:23 pm 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
Hibernate version:
3.0.5
Mapping documents:
Picture.hbm.xml:
Code:
<many-to-one name="gallery" column="gallery_id" class="Gallery" lazy="false" not-null="true" outer-join="auto" />


Gallery.hbm.xml:
Code:
<bag name="pictures" inverse="true" order-by="created desc" cascade="all" lazy="true">
           <key column="gallery_id" />
            <one-to-many class="Picture" />
        </bag>

Code between sessionFactory.openSession() and session.close():
Code:
Gallery gallery = galleryManager.getById(new Long(request.getParameter("galleryId")));
gallery.addPicture(pictureForm);
pictureManager.save(pictureForm);

where (Gallery.java):
Code:
public void addPicture(Picture picture) {      
    picture.setGallery(this);      
    pictures.add(picture);
}

Full stack trace of any exception that occurs:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: Picture._picturesBackref; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: Picture._picturesBackref
org.hibernate.PropertyValueException: not-null property references a null or transient value: Picture._picturesBackref
   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:108)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
   at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:598)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:595)
   at PictureManager.save(PictureManager.java:30)

Name and version of the database you are using:
PostgreSQL 8.03.


When I try to add picture to gallery I get exception. If it is my mistake or Hibernate bug? I read http://jroller.com/page/RickHigh?entry= ... l_property but I can't find how to fix my code... Any help? Thanks in advance.

--
Regards,
Luk


Top
 Profile  
 
 Post subject: Re: not-null property references a null or transient value
PostPosted: Fri Oct 21, 2005 2:49 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
What do you mapping files look like ?

The error is telling you that this field Picture._picturesBackref contains a NULL value and it's not allowed to.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 3:41 pm 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
The problem is that there is no such field _picturesBackref. Mapping between Gallery and Picture is in my first post.

--
Regards,
Luk


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 6:07 am 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
Any help?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 12:23 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Can you do what Preston has asked and post the mapping files for Gallery and Picture?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 2:24 pm 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
Here You are: :)
Picture.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="Picture" table="picture">
   
      <id name="id" column="id" type="long" unsaved-value="null">
         <generator class="native">
            <param name="sequence">picture_id</param>
            </generator>
      </id>            
      
      <property name="name" column="name" type="java.lang.String" />
      <property name="description" column="description" type="java.lang.String" />      
      <property name="path" column="path" type="java.lang.String" />
      <property name="fileName" column="file_name" type="java.lang.String" />
      <property name="rating" column="rating" type="java.lang.Double" />
      <property name="enabled" column="enabled" type="java.lang.Boolean" />
      <property name="visible" column="visible" type="java.lang.Boolean" />
      <property name="created" column="created" type="java.util.Date" />
      <property name="changed" column="changed" type="java.util.Date" />
      
      <many-to-one name="gallery" column="gallery_id" class="Gallery" lazy="false" not-null="true" outer-join="auto" />

   </class>      

</hibernate-mapping>




Gallery.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
   
<hibernate-mapping>

   <class name="Gallery" table="gallery">
   
      <id name="id" column="id" type="long" unsaved-value="null">
         <generator class="native">
            <param name="sequence">gallery_id</param>
            </generator>
      </id>            
      
      <property name="name" column="name" type="java.lang.String" />
      <property name="description" column="description" type="java.lang.String" />            
      <property name="enabled" column="enabled" type="java.lang.Boolean" />
      <property name="visible" column="visible" type="java.lang.Boolean" />
      <property name="created" column="created" type="java.util.Date" />
      <property name="changed" column="changed" type="java.util.Date" />
      
      <many-to-one name="author" column="author_id" class="Member" unique="true" not-null="true" lazy="false" outer-join="auto" />
      
      <bag name="pictures" inverse="true" order-by="created desc" cascade="all" lazy="true">
           <key column="gallery_id" />
            <one-to-many class="Picture" />
        </bag>
      
   </class>      

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 12:05 pm 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
Come on guys :) I belive that someone knows solution...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 4:29 am 
Newbie

Joined: Fri Oct 21, 2005 11:29 am
Posts: 6
So I guess it's Hibernate bug, right?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 3:45 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
luk wrote:
Come on guys :) I belive that someone knows solution...


Try swapping the order that picture and gallery are saved in. If picture has a reference to gallery, and you try to call session.save(picture) before calling sesison.save(gallery), then gallery is still transient, thus your exception message.

IMHO this is a crappy workaround for a bug in Hibernate; I think that checking for whether the related instances are transient should be delayed until session.flush()


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