Hi everybody! I have a problem when I try to associate two tables in of a database. These are my two files of mapping:
<?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="configuracion.PhDevice" table="PHDEVICES">
<id name="idd" column="DEVICE_ID"/>
<property name="idt"/>
<property name="maker"/>
<property name="model"/>
<set name="c" table="CLIENTS_PHDEVICE">
<key column="DEVICE_ID"/>
<many-to-many column="CLIENT_ID" class="configuracion.Client"/>
</set>
<many-to-one name="dt" column="ID_type" lass="configuracion.DevType"/> <!--ID_type-->
</class>
</hibernate-mapping>
<?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="configuracion.DevType" table="DEVTYPES">
<id name="ID_type" column="DEVTYPE_ID"/>
<property name="type"/>
<property name="caracteristics"/>
<set name = "pd" inverse="true">
<key column = "ID_type" />
<one-to-many class="configuracion.PhDevice"/>
</set>
</class>
</hibernate-mapping>
and the method I use is this:
public void addDevType2PhDevice (String idtA , String idtB){
this.createAndStoreDevType("idt 1", "movil" , "IMEI_versionflex..");
this.createAndStorePhDevice("idd 1", "idt 1", "Motorola", "V3x");
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
DevType dt = (DevType) session.load(DevType.class, idtA);
PhDevice pd = (PhDevice) session.load(PhDevice.class, "idt 1");
dt.getPd().add(pd);
session.getTransaction().commit();
}
When I run the program I there aren't any error, but the tables are like this:
DEVICE_ID IDT MAKER MODEL ID_TYPE
idd 1 idt 1 Motorola V3x (null)
DEVTYPE_ID TYPE CARACTERISTICS
idt 1 movil IMEI_versionflex...
Why is null in the ID_TYPE column???
thank you very much for your time
|