-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: beginner pb : Could not synchronize database state with s...
PostPosted: Mon Aug 30, 2004 5:03 am 
Newbie

Joined: Tue Aug 17, 2004 9:07 am
Posts: 4
Hibernate version: 2.1.4




Name and version of the database you are using: MS SQL server 2000, with jtds 0.8.1

Debug level Hibernate log excerpt:

hello,

new beginner pb with hibernate:

il try to delete a record from a table GEO_T_Adr, whose id is a int id.
here is the trace:
Full stack trace of any exception that occurs:


INFO [main] (DataFacadeBase.java:407) - Searching Id: 4
Hibernate: select geotadr0_.AdrId as AdrId5_, geotadr0_.AdrNom as AdrNom5_, geotadr0_.AdrNomRes as AdrNomRes5_, geotadr0_.AdrLi1 as AdrLi15_, geotadr0_.AdrLi2 as AdrLi25_, geotadr0_.AdrLi3 as AdrLi35_, geotadr0_.AdrVille as AdrVille5_, geotadr0_.AdrVbGroup as AdrVbGroup5_, geotadr0_.AdrFilliale as AdrFilli9_5_, geotadr0_.AdrCons as AdrCons5_, geotadr0_.AdrFrn as AdrFrn5_, geotadr0_.AdrTit as AdrTit5_, geotadr0_.AdrFab as AdrFab5_, geotadr0_.AdrDist as AdrDist5_, geotadr0_.AdrMnst as AdrMnst5_, geotadr0_.AdrAutres as AdrAutres5_, geotadr0_.AdrSieDate as AdrSieDate5_, geotadr0_.Replicable_ALL as Replica18_5_, geotadr0_.AdrRefPays as AdrRefPays5_, geotpay1_.PaysId as PaysId0_, geotpay1_.PaysNom as PaysNom0_, geotpay1_.PaysRnvDelai as PaysRnvD3_0_, geotpay1_.PaysDocOfc as PaysDocOfc0_, geotpay1_.PaysDosPlan as PaysDosP5_0_, geotpay1_.PaysDosFrais as PaysDosF6_0_, geotpay1_.PaysRnv as PaysRnv0_, geotpay1_.PaysRegAdm as PaysRegAdm0_, geotpay1_.PaysSec as PaysSec0_, geotpay1_.PaysRefReg as PaysRefReg0_, bastper2_.PersId as PersId1_, bastper2_.PersNom as PersNom1_, bastper2_.PersFct as PersFct1_, bastper2_.PersIni as PersIni1_, bastper2_.Replicable_ALL as Replicab5_1_, bastper2_.PersRefSvc as PersRefSvc1_, bastsvc3_.SvcId as SvcId2_, bastsvc3_.SvcNom as SvcNom2_, bastsvc3_.SvcType as SvcType2_, bastsvc3_.Replicable_ALL as Replicab4_2_, bastreg4_.RegId as RegId3_, bastreg4_.RegNom as RegNom3_, bastreg4_.Replicable_ALL as Replicab3_3_, bastreg4_.RegRefZone as RegRefZone3_, bastzone5_.ZoneId as ZoneId4_, bastzone5_.ZoneNom as ZoneNom4_, bastzone5_.Replicable_ALL as Replicab3_4_ from GEO_T_Adr geotadr0_ left outer join GEO_T_Pays geotpay1_ on geotadr0_.AdrRefPays=geotpay1_.PaysId left outer join BAS_T_Pers bastper2_ on geotpay1_.PaysSec=bastper2_.PersId left outer join BAS_T_Svc bastsvc3_ on bastper2_.PersRefSvc=bastsvc3_.SvcId left outer join BAS_T_Reg bastreg4_ on geotpay1_.PaysRefReg=bastreg4_.RegId left outer join BAS_T_Zone bastzone5_ on bastreg4_.RegRefZone=bastzone5_.ZoneId where geotadr0_.AdrId=?
INFO [main] (DataFacadeBase.java:417) - org.virbac.rai.datas.beans.GeoTAdrfound : org.virbac.rai.datas.beans.GeoTAdr@1295fe8[adrId=4]
INFO [main] (DataFacadeBase.java:280) - Deleting object : 4
Hibernate: delete from GEO_T_Adr where AdrId=?
ERROR [main] (SessionImpl.java:2375) - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:599)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.virbac.rai.datas.facades.DataFacadeBase.deleteRow(DataFacadeBase.java:283)
at testDeleteClass.main(testDeleteClass.java:120)


this table (GEO_T_Adr) is linked to others tables, as you can see in the xml:

Mapping documents: GeoTAdr.hbm.xml


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="org.virbac.rai.datas.beans.GeoTAdr"
table="GEO_T_Adr"
>

<id
name="adrId"
type="java.lang.Integer"
column="AdrId"
>
<generator class="assigned" />
</id>

<property
name="adrNom"
type="java.lang.String"
column="AdrNom"
length="50"
/>
<property
name="adrNomRes"
type="java.lang.String"
column="AdrNomRes"
unique="true"
length="50"
/>
<property
name="adrLi1"
type="java.lang.String"
column="AdrLi1"
length="50"
/>
<property
name="adrLi2"
type="java.lang.String"
column="AdrLi2"
length="50"
/>
<property
name="adrLi3"
type="java.lang.String"
column="AdrLi3"
length="50"
/>
<property
name="adrVille"
type="java.lang.String"
column="AdrVille"
length="50"
/>
<property
name="adrVbGroup"
type="java.lang.Boolean"
column="AdrVbGroup"
length="1"
/>
<property
name="adrFilliale"
type="java.lang.Boolean"
column="AdrFilliale"
length="1"
/>
<property
name="adrCons"
type="java.lang.Boolean"
column="AdrCons"
length="1"
/>
<property
name="adrFrn"
type="java.lang.Boolean"
column="AdrFrn"
length="1"
/>
<property
name="adrTit"
type="java.lang.Boolean"
column="AdrTit"
length="1"
/>
<property
name="adrFab"
type="java.lang.Boolean"
column="AdrFab"
length="1"
/>
<property
name="adrDist"
type="java.lang.Boolean"
column="AdrDist"
length="1"
/>
<property
name="adrMnst"
type="java.lang.Boolean"
column="AdrMnst"
length="1"
/>
<property
name="adrAutres"
type="java.lang.Boolean"
column="AdrAutres"
length="1"
/>
<property
name="adrSieDate"
type="java.sql.Timestamp"
column="AdrSieDate"
length="23"
/>
<property
name="replicableAll"
type="java.lang.String"
column="Replicable_ALL"
length="50"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to AmmTDo -->
<set
name="ammTDosByDosRefDist"
lazy="true"
inverse="true"
>
<key>
<column name="DosRefDist" />
</key>
<one-to-many
class="org.virbac.rai.datas.beans.AmmTDo"
/>
</set>
<!-- bi-directional one-to-many association to AmmTDo -->
<set
name="ammTDosByDosRefFab"
lazy="true"
inverse="true"
>
<key>
<column name="DosRefFab" />
</key>
<one-to-many
class="org.virbac.rai.datas.beans.AmmTDo"
/>
</set>
<!-- bi-directional one-to-many association to GeoTInt -->
<set
name="geoTInts"
lazy="true"
inverse="true"
>
<key>
<column name="IntRefAdr" />
</key>
<one-to-many
class="org.virbac.rai.datas.beans.GeoTInt"
/>
</set>
<!-- bi-directional many-to-one association to GeoTPay -->
<many-to-one
name="geoTPay"
class="org.virbac.rai.datas.beans.GeoTPay"
not-null="true"
>
<column name="AdrRefPays" />
</many-to-one>

</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

public void deleteRow(Integer id, String tableName) throws HibernateException{

try {
String sFullPathTableName = DATA_BEANS_PATH+tableName;
Class c = Class.forName(sFullPathTableName);
Object o = c.newInstance();

o=retreiveObjectById(id, sFullPathTableName);

session = HibernateUtil.currentSession();
tx = null;
if(logger.isInfoEnabled())
logger.info(DATA_HIBERNATE_INFO_DELETINGOBJECT+id);
tx = session.beginTransaction();
session.delete(o);
tx.commit();
if(logger.isInfoEnabled())
logger.info(DATA_HIBERNATE_INFO_OBJECTDELETED);
HibernateUtil.closeSession();


}
catch (HibernateException e) {
if(tx != null) tx.rollback();
logger.error(DATA_HIBERNATE_ERROR_REQUESTFAILED+"\t"+"retreiveObjectById("+id+", "+tableName+")\tMessage: "+e.getMessage());
throw e;

} catch (ClassNotFoundException e) {
logger.warn(DATA_HIBERNATE_WARN_OBJECTNOTFOUND+"\t"+"deleteRow("+id+", "+tableName+")\tMessage: "+e.getMessage());


}
catch (Exception e) {
logger.warn("Exception caught: "+e.getMessage());

}

}


private Object retreiveObjectById(Integer id, String fullPathTableName) throws HibernateException {

session = HibernateUtil.currentSession();
tx = null;

Class cTableClass;
Object o = null;

if(logger.isInfoEnabled())
logger.info(DATA_HIBERNATE_INFO_SEARCHINGID+ id);

try {
cTableClass = Class.forName(fullPathTableName);
tx = session.beginTransaction();
o = session.load(cTableClass, id);
tx.commit();

HibernateUtil.closeSession();
if(logger.isInfoEnabled())
logger.info(fullPathTableName+DATA_HIBERNATE_INFO_OBJECTFOUND+o.toString());


} catch (ClassNotFoundException e) {
logger.warn(DATA_HIBERNATE_WARN_OBJECTNOTFOUND+"\t"+"retreiveObjectById("+id+", "+fullPathTableName+")\tMessage: "+e.getMessage());

}
catch (HibernateException e) {
if(tx != null) tx.rollback();
logger.error(DATA_HIBERNATE_ERROR_REQUESTFAILED+"\t"+"retreiveObjectById("+id+", "+fullPathTableName+")\tMessage: "+e.getMessage());
throw e;

}

return o;
}




please help !!

geordy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 11:01 am 
Newbie

Joined: Tue Aug 17, 2004 9:07 am
Posts: 4
another thing to be said:

my database, which is a ms sql server, use triggers to cascade delete, and when i remove those triggers the probleme disappear, but i have to let those triggers on, so what can i do to synchronize hibernate with db?


please help!!

geordy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 8:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you expect a row to be deleted by a trigger, you must make sure you do NOT delete it via Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 3:01 am 
Newbie

Joined: Tue Aug 17, 2004 9:07 am
Posts: 4
thanks, but if you take a look at my code, you can see there is now deletion via hibernate, i ve tried specifying cascade = "none" but of course it is the default behavior, so i do not know what to do, please help !!!!

geordy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.