Finally I have mapped it with a intermediate class like this:
The class User:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="data.User" table="USERS">
<id name="userId" type="long">
<generator class="increment"/>
</id>
<property name="age"/>
<property name="firstname"/>
<property name="lastname"/>
<set name="alquiladas" table="ALQUILER" inverse="true">
<key column="userUID"/>
<one-to-many class="data.Alquiler"/>
</set>
</class>
</hibernate-mapping>
The class Film:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="data.Pelis" table="PELIS">
<id name='peliId" type="long">
<generator class="increment"/>
</id>
<property name="descripcion"/>
<set name="alquiler" table="ALQUILER" inverse="true">
<key column="pistaUID"/>
<one-to-many class="data.Alquiler"/>
</set>
</class>
</hibernate-mapping>
And the intermediate class:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="data.Alquiler" table="ALQUILER">
<composite-id>
<key-property name="userId" column="userUID" />
<key-property name="peliId" column="peliUID"/>
<key-property name="fecha"/>
</composite-id>
<many-to-one name="userId" class="data.User" update="false" insert="false" fetch="select" cascade="persist,save-update">
<column name="userUID" not-null="true" />
</many-to-one>
<many-to-one name="pistaId" class="data.Pistas" update="false" insert="false" fetch="select" cascade="persist,save-update">
<column name="peliUID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
But now the problem is that I don't know how to insert Alquileres in the database
|