-->
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: Set not working with composite keys (with Spring)
PostPosted: Wed Jan 19, 2005 6:47 am 
Newbie

Joined: Wed Jan 19, 2005 5:46 am
Posts: 6
Hi All
I have a problem with a many-to-one Set with composite ids.
When the system reads the rows for the Set i got a null pointer exception.
I dont have this problem with other classes without composite ids.
Thanks for any help
Regards Rene Huguet


Hibernate version: 2.1.7
With the Spring framework

Mapping documents:

Amendment with one-to-many Set amendPersons:

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

<!-- Created Mon Oct 11 13:52:45 CEST 2004 -->
<hibernate-mapping package="sibe.model">

<class
name="Amendment"
table="TAMENDMENT"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id>
<key-property name="fkRequestId" column="FKREQUESTIID" />
<key-property name="sequence" column="ISEQUENCE" />
</composite-id>

<timestamp
column="TLASTUPDATETIMESTAMP"
name="lastUpdateTimestamp"
/>

<property name="requestStatusCode" type="java.lang.String">
<column
name="SREQUESTSTATUSCODE"
length="2"
not-null="true"
/>
</property>
<property name="requestDate" type="java.sql.Timestamp">
<column
name="DREQUESTDATE"
not-null="true"
/>
</property>
<property name="startDate" type="java.sql.Timestamp">
<column
name="DSTARTDATE"
/>
</property>
<property name="endDate" type="java.sql.Timestamp">
<column
name="DENDDATE"
/>
</property>
<property name="lastUpdateUser" type="java.lang.String">
<column
name="SLASTUPDATEUSER"
length="8"
not-null="true"
/>
</property>

<set name="amendPersons" table="TAMEND_PERS" inverse="true" lazy="true" cascade="none">
<key>
<column name="FKREQUESTIID" />
<column name="FKAMENDISEQ" />
</key>
<one-to-many class="AmendPers" />
</set>
</class>
</hibernate-mapping>

AmendPersons:

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

<!-- Created Mon Oct 11 13:52:45 CEST 2004 -->
<hibernate-mapping package="sibe.model">

<class
name="AmendPers" table="TAMEND_PERS"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id>
<key-property name="fkRequestId"
column="FKREQUESTIID" />
<key-property name="fkAmendSeq"
column="FKAMENDISEQ" />
<key-property name="fkPersonId"
column="FKPERSONIID" />
</composite-id>

<timestamp
column="TLASTUPDATETIMESTAMP"
name="lastUpdateTimestamp"
/>

<property name="socialNumber" type="java.lang.String">
<column
name="SSOCIALNUMBER"
length="20"
not-null="true"
/>
</property>
<property name="lastName" type="java.lang.String">
<column
name="SLASTNAME"
length="30"
not-null="true"
/>
</property>
<property name="firstName" type="java.lang.String">
<column
name="SFIRSTNAME"
length="30"
not-null="true"
/>
</property>
<property name="lastUpdateUser" type="java.lang.String">
<column
name="SLASTUPDATEUSER"
length="8"
not-null="true"
/>
</property>
</class>
</hibernate-mapping>


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

JUnit Test:

public void testGetAmendPersons02() throws Exception {
LOG.info("testGetAmendPersons02: Start");
Integer amendmentId = new Integer("182");
Integer sequence = new Integer("1");
Amendment amendment = null;

amendment = amendmentDao.getAmendmentById(amendmentId, sequence);

assertTrue(amendment != null);

Iterator iter = amendment.getAmendPersons().iterator();
for (iter = amendment.getAmendPersons().iterator(); iter.hasNext();) {
AmendPers amendPers = (AmendPers) iter.next();
assertTrue(amendmentId.equals(amendPers.getFkRequestId().toString()));
LOG.info("AmendPers: " + amendPers.toString());
}
}


Full stack trace of any exception that occurs:

Null Pointer exception at:
Iterator iter = amendment.getAmendPersons().iterator();



net.sf.hibernate.collection.set class
The set is null
/**
* @see java.util.Set#iterator()
*/
public Iterator iterator() {
read();
return new IteratorProxy( set.iterator() );
}


java.lang.NullPointerException
at net.sf.hibernate.collection.Set.iterator(Set.java:131)
at sibe.dao.hibernate.amendment.GetAmendPersonsTests01.testGetAmendPersons02(GetAmendPersonsTests01.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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: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)


In addition i got the message:
com.sun.jdi.InvocationException occurred invoking method.


Name and version of the database you are using:
Oracle 9.2.0.3
Oracle jdbc driver: 10.1.0.2

The generated SQL (show_sql=true):

Sql for the Set amendPers:
select amendperso0_.FKREQUESTIID as FKREQUES1___, amendperso0_.FKAMENDISEQ as FKAMENDI2___, amendperso0_.FKPERSONIID as FKPERSON3___, amendperso0_.FKREQUESTIID as FKREQUES1_0_, amendperso0_.FKAMENDISEQ as FKAMENDI2_0_, amendperso0_.FKPERSONIID as FKPERSON3_0_, amendperso0_.TLASTUPDATETIMESTAMP as TLASTUPD4_0_, amendperso0_.SSOCIALNUMBER as SSOCIALN6_0_, amendperso0_.SLASTNAME as SLASTNAME0_, amendperso0_.SFIRSTNAME as SFIRSTNAME0_,
amendperso0_.SLASTUPDATEUSER as SLASTUP18_0_ from TAMEND_PERS amendperso0_ where amendperso0_.FKREQUESTIID=? and amendperso0_.FKAMENDISEQ=?


Debug level Hibernate log excerpt:


_________________
René Huguet
rene.huguet@besonet.ch


Top
 Profile  
 
 Post subject: Re: Set not working with composite keys (with Spring)
PostPosted: Mon Jan 24, 2005 4:28 am 
Newbie

Joined: Wed Jan 19, 2005 5:46 am
Posts: 6
Hi All
My problem is solved with the following statement.

Code:
from Amendment amendment
left join fetch amendment.amendPersons amendPers
where amendment.fkRequestId = :reqId
and amendment.sequence = :sequence


Thanks to jiseller.
His one-to-many example was the solution.
But the one-to-many set is not read lazily even with
Code:
<set name="amendPersons" table="TAMEND_PERS" inverse="true" lazy="true" cascade="none">

René

_________________
René Huguet
rene.huguet@besonet.ch


Top
 Profile  
 
 Post subject: Re: Set not working with composite keys (with Spring)
PostPosted: Mon Jan 24, 2005 12:52 pm 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
rhuguet wrote:
Hi All
My problem is solved with the following statement.


I solved it by moving to hibernate 3 beta 1 ;-)

HD.


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.