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