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