-->
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.  [ 11 posts ] 
Author Message
 Post subject: Self referencing Class + JUnit + not-null property/transient
PostPosted: Fri Aug 20, 2004 3:29 am 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
Hi,

I have a class class InvolvedParty and that has a FK to itself, so a self referencing link. Now when I try to add an involvedParty with or without a referencing other involvedParty, a not-null property references a null or transient value exception is thrown.

I have tried a lot of configuration setting but I am rather new at Hibernate so for now I'm out of ideas.

Thanks in advance


Hibernate version:
2.1.6 + XDoclet

Mapping documents:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="domain.InvolvedParty"
table="involved_party"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>

<property
name="relation"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="relation"
/>

<bag
name="involvedPartyRelations"
lazy="false"
inverse="true"
cascade="all"
>

<key
column="RELATION_ID"
>
</key>

<one-to-many
class="domain.InvolvedParty"
/>
</bag>

<many-to-one
name="involvedPartyRelation"
class="domain.InvolvedParty"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="ID"
not-null="true"
/>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateSystemException: not-null property references a null or transient value: domain.InvolvedParty.involvedPartyRelation; nested exception is net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: domain.InvolvedParty.involvedPartyRelation
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: domain.InvolvedParty.involvedPartyRelation
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1277)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:928)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:775)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1388)
at org.springframework.orm.hibernate.HibernateTemplate$13.doInHibernate(HibernateTemplate.java:315)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:176)
at org.springframework.orm.hibernate.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:312)
at .dao.hibernate.InvolvedPartyDAOImpl.create(InvolvedPartyDAOImpl.java:23)
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.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:151)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:120)
at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:99)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:140)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:153)
at $Proxy5.create(Unknown Source)
at dao.hibernate.InvolvedPartyDAOImplTest.testCrud(InvolvedPartyDAOImplTest.java:152)
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:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
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:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Name and version of the database you are using:
Microsoft SQL Server 7 Standard Edition

JUnit test:
InvolvedParty involvedPartyA = new InvolvedPart();
//... setting data
involvedPartyA.addInvolvedPartyRelation(involvedPartyB);
Create the involved party
...

InvolvedParty class:
private InvolvedParty involvedPartyRelation;
private List involvedPartyRelations = new ArrayList();

public void setInvolvedPartyRelations(List involvedPartyRelations) {
this.involvedPartyRelations = involvedPartyRelations;
}

public void addInvolvedPartyRelation(InvolvedParty involvedParty) {
involvedPartyRelations.add(involvedParty);
involvedParty.setInvolvedPartyRelation(involvedParty);
}

public InvolvedParty getInvolvedPartyRelation() {
return involvedPartyRelation;
}

public void setInvolvedPartyRelation(InvolvedParty involvedParty) {
this.involvedPartyRelation = involvedParty;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 11:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
InvolvedParty involvedPartyA = new InvolvedPart();
session.save(involvedPartyA);
involvedPartyA.addInvolvedPartyRelation(involvedPartyB);

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Still the same exception
PostPosted: Fri Aug 20, 2004 11:25 am 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
Thanks for the help, but offcoarse I already tried that :) and with no success :( I still have the same exception.

I really have no idea what is causing this. What are the possible reasons such an exception is thrown?

Thanks in advance

Maarten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 11:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
how do you get involvedPartyB?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: InvolvedPartyB
PostPosted: Fri Aug 20, 2004 11:43 am 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
I'm not sure what you lmean by get so here I go:
- InvolvedPartyB is also a newly created object like involvedPartyA, so with no ID.

My InvolvedParty class like like this:

...
/**
* Returns the involved parties to which this party has a relation
* @return The involved parties to which this party has a relation
* @hibernate.bag lazy="false" cascade="all" inverse="true"
* @hibernate.collection-key column="RELATION_ID"
* @hibernate.collection-one-to-many class="com.gudrun.gdp3000.business.involvedparty.domain.InvolvedParty"
*/
public List getInvolvedPartyRelations() {
return involvedPartyRelations;
}

/**
* Sets the involved parties to which this party has a relation
* @param involvedPartyRelations The involved parties to which this party has a relation
*/
public void setInvolvedPartyRelations(List involvedPartyRelations) {
this.involvedPartyRelations = involvedPartyRelations;
}

/**
*


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Have you tried:
InvolvedParty involvedPartyA = new InvolvedPart();
InvolvedParty involvedPartyB = new InvolvedPart();
session.save(involvedPartyB );
involvedPartyA.addInvolvedPartyRelation(involvedPartyB);

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Still the same exception
PostPosted: Fri Aug 20, 2004 11:57 am 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
Yep, tried it and got the same exception.

but he fails on the first save, so it wouldn't matter that it would be A or B that is saved first. So I just cannot save an InvolvedParty object with or without its self-reference :(

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
in order to be sav"able", the id of your objects must be = -1 (see unsaved value), i think if you try to debug, you'll see before calling save that the id property is = to 0.
So you may change unsaved value to 0

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: ID
PostPosted: Fri Aug 20, 2004 12:07 pm 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
My id's are initialized on -1, I am not sure what you mean by
Quote:
So you may change unsaved value to 0

How/where can or must I change the unsaved value?

Grtz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
oh, take a look at this
Code:
<many-to-one
name="involvedPartyRelation"
class="domain.InvolvedParty"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="ID"
not-null="true"
/>


set not-null=false no? and are you sure of the column name? it is the same as the class identifier ?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Thx
PostPosted: Mon Aug 23, 2004 3:05 am 
Newbie

Joined: Mon Dec 22, 2003 4:49 am
Posts: 16
Well it seemed the mappig was indeed wrong, thx for the help. I found working with self-associations confusing :)

Grtz

Maarten


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