-->
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.  [ 3 posts ] 
Author Message
 Post subject: not-null property references a null or transient value...
PostPosted: Wed Jun 27, 2007 1:16 pm 
Newbie

Joined: Wed May 31, 2006 12:58 pm
Posts: 14
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!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 11:39 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Try the following:

1) For each stone, set its road i.e. stone.setRoad(road)
2) <many-to-one name="road" class="Road" column="ROAD_ID" not-null="true" />

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 5:14 am 
Newbie

Joined: Wed May 31, 2006 12:58 pm
Posts: 14
himawan wrote:
1) For each stone, set its road i.e. stone.setRoad(road)

I do it already.

himawan wrote:
2) <many-to-one name="road" class="Road" column="ROAD_ID" not-null="true" />

Does not help :-(


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