Thanks for you answer, here is the mapping file for PlateType:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andromas.bgp.web.core.model.platetype">
<class name="PlateType" table="PLATES">
<id name="id" type="long" column="ID">
<generator class="native" />
</id>
<property name="creationDate" type="calendar" column="CREATION_TIME"
not-null="true"></property>
<property name="modificationDate" type="calendar" column="MODIFICATION_TIME"></property>
<property name="barcode" type="string" column="BARCODE"></property>
<property name="creator" type="string" column="CREATOR"
not-null="true"></property>
<property name="noBarcode" type="boolean" column="NOBARCODE"></property>
<list name="wells" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="PARENT_PLATE" not-null="true"/>
<list-index column="index"/>
<one-to-many class="com.andromas.bgp.web.core.model.platetype.WellInfo"/>
</list>
</class>
</hibernate-mapping>
And this is for the Well :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andromas.bgp.web.core.model.platetype">
<class name="WellInfo" table="WELLS">
<composite-id name="id"
class="com.andromas.bgp.web.core.model.platetype.WellInfoIdType">
<key-many-to-one name="parentPlate" column="PARENT_PLATE" class="com.andromas.bgp.web.core.model.platetype.PlateType"></key-many-to-one>
<key-property name="name" column="NAME" type="string" />
</composite-id>
<property name="index" type="long" column="INDEX" not-null="true"></property>
<property name="wellOrder" type="integer" column="WELL_ORDER" not-null="true"></property>
<property name="barcode" type="string" column="BARCODE"></property>
<property name="method" type="string" column="METHOD" not-null="true"></property>
<property name="needAcquisition" type="boolean" column="NEED_ACQUISITION"></property>
<property name="identificationResult" type="string" column="RESULT"></property>
</class>
</hibernate-mapping>
And what i want to do is to update a value of a well inside the DB, with the following code:
Code:
private void updateWellRecord(WellInfo wellToUpdate) {
logger.debug("well To Insert is acquisition() " + wellToUpdate.isNeedAcquisition());
logger.debug("Is is : " + wellToUpdate.getId());
logger.debug("wellToUpdate.getId() method " + wellToUpdate.getMethod());
logger.debug("wellToUpdate.getId() barcode " + wellToUpdate.getBarcode());
if (wellToUpdate.getId() == null ||
wellToUpdate.getId().getName() == null ||
wellToUpdate.getBarcode() == null ||
wellToUpdate.getMethod() == null) {
logger.warn("Well information not complete, cannot insert object in database at the moment");
return;
}
SessionFactory sessionFactory = (SessionFactory) HibernateUtil.getSessionFactory();
Session updateSession = sessionFactory.openSession();
updateSession.beginTransaction();
PlateType plate = (PlateType)updateSession.load(PlateType.class, wellToUpdate.getIndex());
plate.getWells().add(wellToUpdate);
updateSession.update(plate);
updateSession.getTransaction().commit();
updateSession.close();
}