Hi I have a big problem againts
a using hibernate 2.8
this is my code
Code:
public InnerClass batch(List<Infogene> liste) throws HibernateException {
Session session = null;
List list = null;
Transaction tx = null;
int nbEnrModifie=0;
int nbEnrEnregistre=0;
String mgsError = null;
try {
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
AvinfogePojo pojo= null;
for (Infogene element : liste) {
mgsError=" le num de dossier est :" + element.getNoDossier();
if(("3496".trim()).equals(element.getNoDossier().trim()))
mgsError=" le num de dossier est :" + element.getNoDossier();
/*list =session
.createQuery(
" select from AvinfogePojo as base where base.id.noDossier = ?")
.setString(0, element.getNoDossier().trim()).list();*/
list = session
.find("from AvinfogePojo as base where base.id.noDossier = ?",element.getNoDossier().trim(),Hibernate.STRING);
if(list.size()>0)
{
pojo = (AvinfogePojo) list.get(0);
updatePojo(element,pojo);
session.update(pojo);
nbEnrModifie++;
}
else
{
pojo = this.creerPojo(element);
session.save(pojo);
nbEnrEnregistre++;
}
}
tx.commit();
InnerClass rep = new InnerClass();
rep.setNbEnrEnregistre(nbEnrEnregistre);
rep.setNbEnrModifie(nbEnrModifie);
rep.setNbEnrModifie(nbEnrModifie);
return rep;
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
throw new ServiceException(e.getMessage()+ mgsError, e);
}
finally {
HibernateUtil.closeSession();
}
}
and the console
Quote:
11:55:48,648 DEBUG SessionImpl:1537 - find: from AvinfogePojo as base where base.id.noDossier = ?
11:55:48,648 DEBUG QueryParameters:119 - parameters: [3496]
11:55:48,648 DEBUG SessionImpl:2267 - flushing session
11:55:48,648 DEBUG SessionImpl:2467 - Flushing entities and processing referenced collections
11:55:48,648 DEBUG SessionImpl:2808 - Processing unreferenced collections
11:55:48,648 DEBUG SessionImpl:2822 - Scheduling collection removes/(re)creates/updates
11:55:48,648 DEBUG SessionImpl:2291 - Flushed: 1 insertions, 0 updates, 0 deletions to 2 objects
11:55:48,648 DEBUG SessionImpl:2296 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
11:55:48,664 DEBUG Printer:75 - listing entities:
11:55:48,664 DEBUG Printer:82 - ca.canassistance.pojo.AvinfogePojo{groupeClient=2541, idAccident=N, idUser=STAR, dtModif=20090218, noCertificatSam=2564784, doubleAss=, id=AvinfogeId{noDossier=5419, noGroupe=052104, noCertificat=2564784, dtEvenement=20060208}}
11:55:48,664 DEBUG Printer:82 - ca.canassistance.pojo.AvinfogePojo{groupeClient=, idAccident=N, idUser=STAR, dtModif=20090218, noCertificatSam=214554245254, doubleAss=, id=AvinfogeId{noDossier=5814, noGroupe=052645, noCertificat=2145542452, dtEvenement=20060428}}
11:55:48,664 DEBUG SessionImpl:2321 - changes must be flushed to space: AVINFOGE
11:55:48,664 DEBUG SessionImpl:1819 - Need to execute flush
11:55:48,664 DEBUG SessionImpl:2380 - executing flush
11:55:48,664 DEBUG EntityPersister:447 - Inserting entity: [ca.canassistance.pojo.AvinfogePojo#ca.canassistance.pojo.AvinfogeId@42294161]
11:55:48,664 DEBUG BatcherImpl:204 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:55:48,664 DEBUG SQL:230 - insert into AVINFOGE (IG_ID_DOUBLE_ASS, IG_GROUPE_CLIENT, IG_NO_CERTIFICAT_SAM, IG_ID_USER, IG_DT_MODIF, IG_ID_ACCIDENT, IG_NO_GROUPE, IG_NO_CERTIFICAT, IG_DT_EVENEMENT, IG_NO_DOSSIER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
11:55:48,664 DEBUG BatcherImpl:253 - preparing statement
11:55:48,664 DEBUG EntityPersister:382 - Dehydrating entity: [ca.canassistance.pojo.AvinfogePojo#ca.canassistance.pojo.AvinfogeId@42294161]
11:55:48,664 DEBUG StringType:46 - binding '' to parameter: 1
11:55:48,664 DEBUG StringType:46 - binding '' to parameter: 2
11:55:48,664 DEBUG StringType:46 - binding '214554245254' to parameter: 3
11:55:48,664 DEBUG StringType:46 - binding 'STAR' to parameter: 4
11:55:48,664 DEBUG IntegerType:46 - binding '20090218' to parameter: 5
11:55:48,664 DEBUG StringType:46 - binding 'N' to parameter: 6
11:55:48,664 DEBUG StringType:46 - binding '052645' to parameter: 7
11:55:48,664 DEBUG StringType:46 - binding '2145542452' to parameter: 8
11:55:48,664 DEBUG IntegerType:46 - binding '20060428' to parameter: 9
11:55:48,664 DEBUG StringType:46 - binding '5814' to parameter: 10
11:55:48,664 DEBUG BatcherImpl:28 - Adding to batch
11:55:48,664 DEBUG BatcherImpl:50 - Executing batch size: 1
11:55:48,664 DEBUG JDBCExceptionReporter:49 - SQL Exception
java.sql.BatchUpdateException: ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10698)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1821)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1578)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1527)
at ca.canassistance.model.dao.AvinfogeDAO.batch(AvinfogeDAO.java:210)
at ca.canassistance.service.AvingogeServicePersistance.batch(AvingogeServicePersistance.java:72)
at ca.canassistance.batch.MettreJourInfogene.<init>(MettreJourInfogene.java:139)
at ca.canassistance.batch.MettreJourInfogene.main(MettreJourInfogene.java:809)
11:55:48,664 WARN JDBCExceptionReporter:57 - SQL Error: 1, SQLState: 23000
11:55:48,664 ERROR JDBCExceptionReporter:58 - ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
11:55:48,664 WARN JDBCExceptionReporter:57 - SQL Error: 1, SQLState: 23000
11:55:48,664 ERROR JDBCExceptionReporter:58 - ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
11:55:48,664 DEBUG BatcherImpl:211 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:55:48,664 DEBUG BatcherImpl:275 - closing statement
11:55:48,664 DEBUG JDBCExceptionReporter:49 - Could not execute JDBC batch update
java.sql.BatchUpdateException: ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10698)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1821)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1578)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1527)
at ca.canassistance.model.dao.AvinfogeDAO.batch(AvinfogeDAO.java:210)
at ca.canassistance.service.AvingogeServicePersistance.batch(AvingogeServicePersistance.java:72)
at ca.canassistance.batch.MettreJourInfogene.<init>(MettreJourInfogene.java:139)
at ca.canassistance.batch.MettreJourInfogene.main(MettreJourInfogene.java:809)
11:55:48,664 WARN JDBCExceptionReporter:57 - SQL Error: 1, SQLState: 23000
11:55:48,664 ERROR JDBCExceptionReporter:58 - ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
11:55:48,664 WARN JDBCExceptionReporter:57 - SQL Error: 1, SQLState: 23000
11:55:48,664 ERROR JDBCExceptionReporter:58 - ORA-00001: unique constraint (FACTCAN.AVINFOGE_INDEX1) violated
11:55:48,664 ERROR SessionImpl:2400 - Could not synchronize database state with session
1) It is no possible that is (FACTCAN.AVINFOGE_INDEX1) violated
first my not doing a insert. it is a Find
2) I don t know what is the process of hibernate for the sql execute
I check in my that base and the no problem with IG_NO_DOSSIER 3496
FACTCAN.AVINFOGE_INDEX1
Code:
CREATE UNIQUE INDEX "FACTCAN"."AVINFOGE_INDEX1" ON "FACTCAN"."AVINFOGE" ("IG_NO_GROUPE", "IG_NO_CERTIFICAT", "IG_DT_EVENEMENT", "IG_NO_DOSSIER")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "FACTCAN" ;
CREATE INDEX "FACTCAN"."AVINFOGE_INDEX2" ON "FACTCAN"."AVINFOGE" ("IG_NO_DOSSIER")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "FACTCAN" ;
if a look for the error
hibernate try to Inserting IG_NO_DOSSIER 5814
Quote:
12:07:30,564 DEBUG SQL:230 - insert into AVINFOGE (IG_ID_DOUBLE_ASS, IG_GROUPE_CLIENT, IG_NO_CERTIFICAT_SAM, IG_ID_USER, IG_DT_MODIF, IG_ID_ACCIDENT, IG_NO_GROUPE, IG_NO_CERTIFICAT, IG_DT_EVENEMENT, IG_NO_DOSSIER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
12:07:30,564 DEBUG BatcherImpl:253 - preparing statement
12:07:30,564 DEBUG EntityPersister:382 - Dehydrating entity: [ca.canassistance.pojo.AvinfogePojo#ca.canassistance.pojo.AvinfogeId@42294161]
12:07:30,564 DEBUG StringType:46 - binding '' to parameter: 1
12:07:30,564 DEBUG StringType:46 - binding '' to parameter: 2
12:07:30,564 DEBUG StringType:46 - binding '214554245254' to parameter: 3
12:07:30,564 DEBUG StringType:46 - binding 'STAR' to parameter: 4
12:07:30,564 DEBUG IntegerType:46 - binding '20090218' to parameter: 5
12:07:30,564 DEBUG StringType:46 - binding 'N' to parameter: 6
12:07:30,564 DEBUG StringType:46 - binding '052645' to parameter: 7
12:07:30,564 DEBUG StringType:46 - binding '2145542452' to parameter: 8
12:07:30,564 DEBUG IntegerType:46 - binding '20060428' to parameter: 9
12:07:30,564 DEBUG StringType:46 binding '5814' to parameter: 10
12:07:30,564 DEBUG BatcherImpl:28 - Adding to batch
12:07:30,564 DEBUG BatcherImpl:50 - Executing batch size: 1
IG_NO_DOSSIER = 5814
and this is not the IG_NO_DOSSIER try to execute
even of that I check in my dataBase for IG_NO_DOSSIER = 5814 and
evething is ok there is no (FACTCAN.AVINFOGE_INDEX1) violated
for this to.
by a why make a find not a insert
my pojo
Code:
package ca.canassistance.pojo;
import java.io.Serializable;
import java.util.List;
import net.sf.hibernate.HibernateException;
import ca.canassistance.model.Infogene;
import ca.canassistance.model.dao.AvinfogeDAO;
/**
* 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 AvinfogePojo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2444185467393453780L;
// fields
private java.lang.String doubleAss;
private java.lang.String groupeClient;
private java.lang.String noCertificatSam;
private java.lang.String idUser;
private java.lang.Integer dtModif;
private java.lang.String idAccident;
private AvinfogeId id;
private AvinfogeDAO dao;
// constructors
public AvinfogePojo(String doubleAss, Integer dtEvenement,
String groupeClient, String noDossier, String noCertificatSam,
String noCertificat, String noGroupe, String idUser,
Integer dtModif, String idAccident) {
AvinfogeId avinfogeId = new AvinfogeId();
avinfogeId.setDtEvenement(dtEvenement);
avinfogeId.setNoCertificat(noCertificat.trim());
avinfogeId.setNoDossier(noDossier);
avinfogeId.setNoGroupe(noGroupe);
this.setDoubleAss(doubleAss);
this.setGroupeClient(groupeClient);
this.setNoCertificatSam(noCertificatSam);
this.setIdUser(idUser);
this.setDtModif(dtModif);
this.setIdAccident(idAccident);
this.setId(avinfogeId);
}
public AvinfogePojo() {
initialize();
}
public AvinfogePojo(Infogene infogene) {
AvinfogeId id = new AvinfogeId();
id.setDtEvenement(infogene.getDtEvenement());
id.setNoCertificat(infogene.getNoCertificat().trim());
id.setNoDossier(infogene.getNoDossier());
id.setNoGroupe(infogene.getNoGroupe());
this.setId(id);
this.setDoubleAss(infogene.getIdDoubleAss());
// this.setDtModif(avinfoge.getModif);
this.setGroupeClient(infogene.getGroupeClient());
this.setIdAccident(infogene.getIdAccident());
this.setNoCertificatSam(infogene.getNoCertificatSam());
// avinfoge.getn
}
protected void initialize() {
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public java.lang.String getDoubleAss() {
return doubleAss;
}
public void setDoubleAss(java.lang.String doubleAss) {
this.doubleAss = doubleAss;
}
public java.lang.Integer getDtModif() {
return dtModif;
}
public void setDtModif(java.lang.Integer dtModif) {
this.dtModif = dtModif;
}
public java.lang.String getGroupeClient() {
return groupeClient;
}
public void setGroupeClient(java.lang.String groupeClient) {
this.groupeClient = groupeClient;
}
public AvinfogeId getId() {
return id;
}
public void setId(AvinfogeId id) {
this.id = id;
}
public java.lang.String getIdAccident() {
return idAccident;
}
public void setIdAccident(java.lang.String idAccident) {
this.idAccident = idAccident;
}
public java.lang.String getIdUser() {
return idUser;
}
public void setIdUser(java.lang.String idUser) {
this.idUser = idUser;
}
public java.lang.String getNoCertificatSam() {
return noCertificatSam;
}
public void setNoCertificatSam(java.lang.String noCertificatSam) {
this.noCertificatSam = noCertificatSam;
}
public boolean estDansLaBase(String cleDossier) throws HibernateException {
if (dao == null)
this.setDao(new AvinfogeDAO());
List l = this.getDao().find(cleDossier);
if (l != null)
return true;
return false;
}
public AvinfogeDAO getDao() {
return dao;
}
public void setDao(AvinfogeDAO 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(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final AvinfogePojo other = (AvinfogePojo) 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;
}
}
my hbm
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="ca.canassistance.pojo">
<class
name="AvinfogePojo"
table="AVINFOGE"
>
<composite-id name="id" class="ca.canassistance.pojo.AvinfogeId">
<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"
/>
<property
name="groupeClient"
column="IG_GROUPE_CLIENT"
type="string"
not-null="false"
length="8"
/>
<property
name="noCertificatSam"
column="IG_NO_CERTIFICAT_SAM"
type="string"
not-null="false"
length="20"
/>
<property
name="idUser"
column="IG_ID_USER"
type="string"
not-null="false"
length="4"
/>
<property
name="dtModif"
column="IG_DT_MODIF"
type="integer"
not-null="false"
length="8"
/>
<property
name="idAccident"
column="IG_ID_ACCIDENT"
type="string"
not-null="false"
length="1"
/>
</class>
</hibernate-mapping>