-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-to-many question
PostPosted: Tue Dec 02, 2003 11:28 am 
Newbie

Joined: Wed Oct 15, 2003 3:20 pm
Posts: 9
Location: Montreal
Hi,

I have a class containing a set of address :

<id column="ACTOR_ID" name="actorId" type="java.lang.Long">
<generator class="assigned"/>
</id>
<set name="address" table="ADDRESS" lazy="false" inverse="true">
<key>
<column name="ACTOR_ID" not-null="true" />
</key>
<one-to-many class="cgix.apei.domain.actor.Address"/>
</set>

However,
When I get an actor, I only get one address in the set even if I have a lot of them in the db for the same actor...

ex:
getActor(id).getAddress()
return a collection of one only, instead of many address like in the db.
Can someone help?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 12:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<key>
<column name="ACTOR_ID" not-null="true" />
</key>

ACTOR_ID is a column in Address table that link to Actor table pk, isn't it ?

You did something wrong. but there is not enough info in your post

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 12:45 pm 
Newbie

Joined: Wed Oct 15, 2003 3:20 pm
Posts: 9
Location: Montreal
Yes ACTOR_ID is in table ADDRESS.

CREATE TABLE ADDRESS (
ADDRESS_ID INTEGER NOT NULL,
ADDRESS_CITY VARCHAR2 (50),
ACTOR_ID INTEGER,
PRIMARY KEY ( ADDRESS_ID ) ) ;

and table actor looks like this

CREATE TABLE ACTOR (
ACTOR_ID INTEGER NOT NULL,
ACTOR_SHERPA_KEY VARCHAR2 (15),
PRIMARY KEY ( ACTOR_ID ) ) ;

Having a one to many of address in actor.hbm.xml

<class name="cgix.apei.domain.actor.Actor" schema="AVENTIS" table="ACTOR">
<id column="ACTOR_ID" name="actorId" type="java.lang.Long">
<generator class="assigned"/>
</id>
<set name="address" table="ADDRESS" lazy="false" inverse="true">
<key>
<column name="ACTOR_ID" not-null="true" />
</key>
<one-to-many class="cgix.apei.domain.actor.Address"/>
</set>

and address.hbm.xml

<class name="cgix.apei.domain.actor.Address" schema="AVENTIS" table="ADDRESS">
<id column="ADDRESS_ID" name="addressId" type="java.lang.Long">
<generator class="assigned"/>
</id>
<property column="ACTOR_ID" length="22" name="actorId" type="java.lang.Long"/>

I should be able to do getActor(id).getAddress() and get a collection of address but its only returning the first element in the db...

the hql is pretty simple:
String queryString = "select act from cgix.apei.domain.actor.Actor as act ";

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, and you're *sure* tha un Address, the actor_id reference several times th e actor you request ?

BTW you need a many-to-one mapping in the address class (you inverse="true" the one-to-many)

_________________
Emmanuel


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