-->
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: many-to-many question
PostPosted: Mon Oct 20, 2003 10:24 am 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
I have a many-to-many relationship between Person and Car, where the Person_Car table contains extra columns...

I read the "Hibernate Users FAQ - Tips & Tricks"
http://www.hibernate.org/118.html#A12
Quote:
I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?


Person <---> Person_Car (codPerson,codCar,date DATE) <----> Car

Code:
create table Person_Car(
codPerson NUMBER(19,0) not null,
codCar NUMBER(19,0) not null, primary key (codPerson, codCar),
date DATE
)


and I tried to do it, but it didn't work fine...

In Person table, I put the following code:
Code:
<set name="cars" table="Person_Car">
         <key column="codAluno" />
          <composite-element class="hibernate.PersonCar">
           <property name="date" type="java.util.Date"/>
           <many-to-one name="car" class="hibernate.CarVO"/>
         </composite-element>
</set>


when I ran the "net.sf.hibernate.tool.hbm2java.CodeGenerator" to generate the classes, the class Person_Car was created...

Code:
/** @author Hibernate CodeGenerator */
public class PersonCar implements Serializable {

    /** nullable persistent field */
    private java.util.Date data;

    /** nullable persistent field */
    private hibernate.CarVO car;


I'm confused because I wanted that a PersonCar class had a field referencing Person, too.

How can I do this?

thanks

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 1:52 pm 
Newbie

Joined: Thu Oct 16, 2003 7:22 pm
Posts: 12
I haven't tried this myself, but i read somewhere else that you should be able to specify the parent field by using
Code:
<parent name="person" />

inside of your <composite-element> tag


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 4:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
From the DTD

<!-- The parent element maps a property of the component class as a pointer back to the owning entity. -->

<!ELEMENT parent EMPTY>
<!ATTLIST parent name CDATA #REQUIRED>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 7:14 am 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
Thanks guys!

_________________
Ricardo Lecheta


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.