Hibernate version:
2.1
Mapping documents:
Code:
<class name="Road" table="T_ROAD">
<id name="key" column="ID" type="integer" unsaved-value="null">
<generator class="sequence">
<param name="sequence">T_ROAD_SEQUENCE</param>
</generator>
</id>
<version name="version" column="VER" />
<bag name="stoneList" inverse="true" cascade="all" lazy="true"
where="UPPER(nvl(stoneList0_.active,'Y')) = 'Y'">
<key column="ROAD_ID"/>
<one-to-many class="Stone"/>
</bag>
</class>
<class name="Stone" table="T_STONE">
<id name="key" column="STONE_ID" type="integer" unsaved-value="null">
<generator class="sequence">
<param name="sequence">T_STONE_SEQUENCE</param>
</generator>
</id>
<version name="version" column="VER" />
<many-to-one name="road" column="ROAD_ID" not-null="true" />
</class>
Code between sessionFactory.openSession() and session.close():
I create a new Road with the collection of new Stones. Each object here has 'null' in the ID property and version=1 (of the primitive 'int' type).
When I call session.save(Road) I get the following exception.
Full stack trace of any exception that occurs:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: Stone.road
at HibernateAdapter.closeSession(HibernateAdapter.java:166)
at HibernateAdapter.executeUpdate(HibernateAdapter.java:116)
at HibernateAdapter.execute(HibernateAdapter.java:69)
at HibernateAdapter.save(HibernateAdapter.java:201)
at BaseHibernateDAO.save(BaseHibernateDAO.java:200)
at HibernateRoadDAO.createRoad(HibernateRoadDAO.java:281)
at RoadServiceBean.createRoad(RoadServiceBean.java:196)
...
Name and version of the database you are using:
Oracle 9
Ok, I have tried to delete the
not-null="true" constraint from the 'many-to-one' element in the Stone's mapping.
After that I get:
java.lang.NullPointerException
at net.sf.hibernate.type.IntegerType.next(IntegerType.java:52)
at net.sf.hibernate.engine.Versioning.increment(Versioning.java:25)
at net.sf.hibernate.impl.SessionImpl.getNextVersion(SessionImpl.java:2645)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2579)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2478)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2280)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2259)
at HibernateAdapter.closeSession(HibernateAdapter.java:166)
at HibernateAdapter.executeUpdate(HibernateAdapter.java:116)
at HibernateAdapter.execute(HibernateAdapter.java:69)
at HibernateAdapter.save(HibernateAdapter.java:201)
at BaseHibernateDAO.save(BaseHibernateDAO.java:200)
at HibernateRoadDAO.createRoad(HibernateRoadDAO.java:281)
at RoadServiceBean.createRoad(RoadServiceBean.java:196)
...
I have already looked through a dozens of web-pages related to the similar exceptions but I still do not understand what is happening...
So, any help will be greatly appreciated!