Hi I have a problem to update my row
my hbm
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="pojo">
<class
name="InfogenePojo"
table="INFOGENE"
lazy="false"
>
<composite-id name="id" class="InfogeneId">
<key-property name="noGroupe" column="IG_NO_GROUPE" type="string" length="6"/>
<key-property name="noCertificat" column="IG_NO_CERTIFICAT" type="string" length="10"/>
<key-property name="dtEvenement" column="IG_DT_EVENEMENT" type="integer" length="8"/>
<key-property name="noDossier" column="IG_NO_DOSSIER" type="string" length="6"/>
</composite-id>
<property
name="doubleAss"
column="IG_ID_DOUBLE_ASS"
type="string"
not-null="false"
length="1"
lazy="false"
/>
<property
name="groupeClient"
column="IG_GROUPE_CLIENT"
type="string"
not-null="false"
length="8"
lazy="false"
/>
<property
name="noCertificatSam"
column="IG_NO_CERTIFICAT_SAM"
type="string"
not-null="false"
length="20"
lazy="false"
/>
<property
name="idUser"
column="IG_ID_USER"
type="string"
not-null="false"
length="4"
lazy="false"
/>
<property
name="dtModif"
column="IG_DT_MODIF"
type="integer"
not-null="false"
length="8"
lazy="false"
/>
<property
name="idAccident"
column="IG_ID_ACCIDENT"
type="string"
not-null="false"
length="1"
lazy="false"
/>
</class>
</hibernate-mapping>
pojo
Code:
package pojo;
import java.io.Serializable;
public class InfogeneId implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5624859234341440063L;
private Integer dtEvenement;
private String noDossier;
private String noCertificat;
private String noGroupe;
public static long getSerialVersionUID() {
return serialVersionUID;
}
public Integer getDtEvenement() {
return dtEvenement;
}
public void setDtEvenement(final Integer dtEvenement) {
this.dtEvenement = dtEvenement;
}
public String getNoCertificat() {
return noCertificat;
}
public void setNoCertificat(final String noCertificat) {
this.noCertificat = noCertificat.trim();
}
public String getNoDossier() {
return noDossier;
}
public void setNoDossier(final String noDossier) {
this.noDossier = noDossier;
}
public String getNoGroupe() {
return noGroupe;
}
public void setNoGroupe(final String noGroupe) {
this.noGroupe = noGroupe;
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result
+ ((noCertificat == null) ? 0 : noCertificat.hashCode());
result = PRIME * result
+ ((noDossier == null) ? 0 : noDossier.hashCode());
result = PRIME * result
+ ((noGroupe == null) ? 0 : noGroupe.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final InfogeneId other = (InfogeneId) obj;
if (noCertificat == null) {
if (other.noCertificat != null) {
return false;
}
} else if (!noCertificat.equals(other.noCertificat)) {
return false;
}
if (noDossier == null) {
if (other.noDossier != null) {
return false;
}
} else if (!noDossier.equals(other.noDossier)) {
return false;
}
if (noGroupe == null) {
if (other.noGroupe != null) {
return false;
}
} else if (!noGroupe.equals(other.noGroupe)) {
return false;
}
return true;
}
}
package pojo;
import java.io.Serializable;
import InfogeneDAO;
/**
* This class has been automatically generated by Hibernate Synchronizer. For
* more information or documentation, visit The Hibernate Synchronizer page at
* http://www.binamics.com/hibernatesync or contact Joe Hudson at
* joe@binamics.com.
*
* This is an object that contains data related to the AVINFOGE table. Do not
* modify this class because it will be overwritten if the configuration file
* related to this class is modified.
*
* @hibernate.class table="AVINFOGE"
*/
public class InfogenePojo implements Serializable, InterfacePojo {
/**
*
*/
private static final long serialVersionUID = -2444185467393453780L;
// fields
private String doubleAss;
private String groupeClient;
private String noCertificatSam;
private String idUser = "STAR";
private Integer dtModif;
private String idAccident;
private InfogeneId id;
private InfogeneDAO dao;
private boolean persister = false;
public boolean isPersister() {
return persister;
}
public void setPersister(boolean persister) {
this.persister = persister;
}
// constructors
public InfogenePojo(final String doubleAss, final Integer dtEvenement,
final String groupeClient, final String noDossier,
final String noCertificatSam, final String noCertificat,
final String noGroupe, final String idUser, final Integer dtModif,
final String idAccident) {
final InfogeneId infogeneId = new InfogeneId();
infogeneId.setDtEvenement(dtEvenement);
infogeneId.setNoCertificat(noCertificat.trim());
infogeneId.setNoDossier(noDossier);
infogeneId.setNoGroupe(noGroupe);
this.setDoubleAss(doubleAss);
this.setGroupeClient(groupeClient);
this.setNoCertificatSam(noCertificatSam);
this.setIdUser(idUser);
this.setDtModif(dtModif);
this.setIdAccident(idAccident);
this.setId(infogeneId);
}
public InfogenePojo() {
initialize();
}
protected void initialize() {
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getDoubleAss() {
return doubleAss;
}
public void setDoubleAss(final String doubleAss) {
this.doubleAss = doubleAss;
}
public Integer getDtModif() {
return dtModif;
}
public void setDtModif(final Integer dtModif) {
this.dtModif = dtModif;
}
public String getGroupeClient() {
return groupeClient;
}
public void setGroupeClient(final String groupeClient) {
this.groupeClient = groupeClient;
}
public InfogeneId getId() {
return this.id;
}
public void setId(final InfogeneId id) {
this.id = id;
}
public String getIdAccident() {
return idAccident;
}
public void setIdAccident(final String idAccident) {
this.idAccident = idAccident;
}
public String getIdUser() {
return idUser;
}
public void setIdUser(final String idUser) {
this.idUser = idUser;
}
public String getNoCertificatSam() {
return noCertificatSam;
}
public void setNoCertificatSam(final String noCertificatSam) {
this.noCertificatSam = noCertificatSam;
}
public InfogeneDAO getDao() {
return dao;
}
public void setDao(final InfogeneDAO dao) {
this.dao = dao;
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result
+ ((doubleAss == null) ? 0 : doubleAss.hashCode());
result = PRIME * result + ((dtModif == null) ? 0 : dtModif.hashCode());
result = PRIME * result
+ ((groupeClient == null) ? 0 : groupeClient.hashCode());
result = PRIME * result + ((id == null) ? 0 : id.hashCode());
result = PRIME * result
+ ((idAccident == null) ? 0 : idAccident.hashCode());
result = PRIME * result + ((idUser == null) ? 0 : idUser.hashCode());
result = PRIME * result
+ ((noCertificatSam == null) ? 0 : noCertificatSam.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final InfogenePojo other = (InfogenePojo) obj;
if (dao == null) {
if (other.dao != null) {
return false;
}
} else if (!dao.equals(other.dao)) {
return false;
}
if (doubleAss == null) {
if (other.doubleAss != null) {
return false;
}
} else if (!doubleAss.equals(other.doubleAss)) {
return false;
}
if (dtModif == null) {
if (other.dtModif != null) {
return false;
}
} else if (!dtModif.equals(other.dtModif)) {
return false;
}
if (groupeClient == null) {
if (other.groupeClient != null) {
return false;
}
} else if (!groupeClient.equals(other.groupeClient)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (idAccident == null) {
if (other.idAccident != null) {
return false;
}
} else if (!idAccident.equals(other.idAccident)) {
return false;
}
if (idUser == null) {
if (other.idUser != null) {
return false;
}
} else if (!idUser.equals(other.idUser)) {
return false;
}
if (noCertificatSam == null) {
if (other.noCertificatSam != null) {
return false;
}
} else if (!noCertificatSam.equals(other.noCertificatSam)) {
return false;
}
return true;
}
public void setId(Object id) {
this.id = (InfogeneId) id;
}
}
and the code
Code:
public void traite(final List<InfogenePojo> liste)
throws HibernateException {
logger
.info("debut de la methode traite de la classe"
+ this.getClass());
Session session = null;
try {
int i = 0;
for (final InfogenePojo element : liste) {
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
if (element.isPersister()) {
session.update(element);
} else {
session.save(element);
}
if (i % 20 == 0) {
session.flush();
session.clear();
}
i++;
}
session.getTransaction().commit();
} catch (final HibernateException e) {
HibernateUtil.getSessionFactory().getCurrentSession()
.getTransaction().rollback();
setCodeRetour(8);
logger
.error("Erreur dans l'ecriture des donnees de la table Infogene");
throw new ServiceException(e.getMessage(), e);
} finally {
HibernateUtil.getSessionFactory().close();
}
}
I don t anderstand
why session.update(element);
doesn t work
Can someone help me please