-->
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: HibernateSystemException creating entities in cascade.
PostPosted: Mon Aug 29, 2005 9:01 am 
Newbie

Joined: Mon Aug 29, 2005 7:20 am
Posts: 2
Hi Folks,

I am using Hibernate and Spring 1.2.1 for trying to map an one-to-many association between two simple classes (composition) and navigable in both sides. I mean, Person<->---------*PersonDetails.

The following lines, it shows the Java code I am testing.

Set<PersonDetail> personDetailSet = new HashSet<PersonDetail>();

PersonDetail personDetail1 = PersonDetail.Factory.getInstance();
personDetail1.setAddress("Lane1");
personDetail1.setEmail("xxxx@yyyyy.zz");
personDetail1.setTelf("112233");
personDetail1.setMobile("77777");

personDetailSet.add(personDetail1);

PersonDetail personDetail2 = PersonDetail.Factory.newInstance();

personDetail2.setAddress("Lane2");
personDetail2.setEmail("aaaa@bbbbbbb.cc");
personDetail2.setTelf("112233-2");
personDetail2.setMobile("777772");

personDetailSet.add(personDetail2);

Person person = Person.Factory.getInstance();

person.setName("Joe");
person.setSurname("Smith");
person.setAge(new Integer(33));
person.setCcnumber("11334112");
person.setSs(new Integer(33442222));

person.setPersonDetails(personDetailSet);

Person response = personDao.create(person);


When I run the code I always get the same stack trace and I have no clue where to start.

Please, drop a few words if you have any idea what's going on in my example.


Thanks.

NOTE: This is ONLY a sample test and my idea was test the cascade functionality.

Hibernate version:
3.0.4
Mapping documents:
person.hbm.xml
<?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 default-cascade="none">
<class name="examples.PersonImpl" table="TBL_PERSONS" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="native">
</generator>
</id>
<property name="name" type="java.lang.String">
<column name="NAME" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<property name="surname" type="java.lang.String">
<column name="SURNAME" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<property name="age" type="java.lang.Integer">
<column name="AGE" not-null="true" unique="false" sql-type="INTEGER"/>
</property>
<property name="ss" type="java.lang.Integer">
<column name="SS" not-null="true" unique="false" sql-type="INTEGER"/>
</property>
<property name="ccnumber" type="java.lang.String">
<column name="CCNUMBER" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<set name="personDetails" order-by="PERSON_FK" lazy="false" fetch="select" inverse="true" cascade="all">
<key foreign-key="TBL_PERSONDETAILS_PERSON_FKC">
<column name="PERSON_FK" sql-type="BIGINT"/>
</key>
<one-to-many class="examples.PersonDetailImpl"/>
</set>
</class>
</hibernate-mapping>

persondetails.hbm.xml
<?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 default-cascade="none">
<class name="examples.PersonDetailImpl" table="TBL_PERSONDETAILS" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="native">
</generator>
</id>
<property name="email" type="java.lang.String">
<column name="EMAIL" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<property name="telf" type="java.lang.String">
<column name="TELF" not-null="false" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<property name="mobile" type="java.lang.String">
<column name="MOBILE" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
</property>
<many-to-one name="person" class="examples.PersonImpl" fetch="select" cascade="none" foreign-key="TBL_PERSONDETAILS_PERSON_FKC" lazy="true">
<column name="PERSON_FK" not-null="true" sql-type="BIGINT"/>
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: examples.PersonDetailImpl.person; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: examples.PersonDetailImpl.person
org.hibernate.PropertyValueException: not-null property references a null or transient value: examples.PersonDetailImpl.person
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:235)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:362)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:159)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
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:541)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:538)
at examples.PersonDaoBase.create(PersonDaoBase.java:82)
at examples.PersonDaoBase.create(PersonDaoBase.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:288)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.create(Unknown Source)
at com.tecnomen.examples.testPersonDao.testPerson(testPersonDao.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Name and version of the database you are using:
MySQL 4.1.12a-nt
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 10:58 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
You need to call PersonDetail.setPerson() (you need to set both sides of your relationships). See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#tutorial-associations-usingbidir


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 12:34 pm 
Newbie

Joined: Mon Aug 29, 2005 7:20 am
Posts: 2
Hi nathanmoon,

Clear enough. It works. !!


Thanks a million for your reply.


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.