-->
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.  [ 2 posts ] 
Author Message
 Post subject: having a problem when updating composite-element property
PostPosted: Tue Feb 08, 2005 2:33 pm 
Newbie

Joined: Tue Feb 08, 2005 2:26 pm
Posts: 4
Using Hibernate 2.1.8 with Oracle.



I'm having a problem when updating an object that has a collection of "composite-element"
There is one field ( codeInitiateur, column = CODE_INITIATEUR_CTRL in my example ), in the composite element, that we don't keep the value,

we always ask a service to provide that value, as in the example below, But Hibernate uses this field to delete a collection of composite,

but the value returned for that field is not the value in the DB, so some records won't be deleted.

-------------------
public class AffaireAffiliationDetaillant
{
AffaireDetaillant detaillant;
AffaireCodeCompte codeCompte;
boolean indAffiliationPrimaire;

public String getCodeInitiateur()
{
// returns user ID logged in
IServiceContexteApplicatif service = ServicesManager.getServiceContexteApplicatif();
return service.getCodeUtilisateurInitiateur();
}

public void setCodeInitiateur(String initiateur)
{
// do nothing
}

-----------------
public class AffaireDetaillantReseauVtes extends AffaireDetaillant
{
private Collection affiliationsDet = new HashSet();

-----------------




When I update my object of class AffaireDetaillantReseauVtes ( that has a collection of AffaireAffiliationDetaillant ),

hibernate deletes all the elements of AffaireAffiliationDetaillant held in it's collection affiliationsDet
before re-inserting them all.

This is ok to me, BUT
when Hibernate create the query, to remove the elements ( in the background ),
It does not only take the two IDs ( this table represents a Link table for a many to many relation )
but also the value "codeInitiateur" and "indAffiliationPrimaire", the two <property> element of my composite element.

--> delete from DET.T_AFFILIATION_DET_L where ID_COC=? and IND_AFFILIATION_PRIM_AD=? and CODE_INITIATEUR_CTRL=? and ID_EA_DET=?

Question 1) Is there a way to tell hibernate to only use the two IDs for its delete query when deleting composite elements ?

or at least not using that CODE_INITIATEUR_CTRL value that I have ?

Question 2) Will such a query imply a full table scan, since only the two IDs are indexed ?



N.B. I tried implementing the Lifecycle interface, this would have saved me, but the onDelete() and onUpdate() are not called in this situation.




=====================================================================================

</hibernate-mapping>
<class name="com.iris.business.cc.detaillant.types.AffaireDetaillant" schema="DET" table="T_DETAILLANT">

<id name="id" column="ID_EA_DET" type="string" unsaved-value="null">
<generator class="foreign">
<param name="property">entiteAffaire</param>
</generator>
</id>

<!-- <timestamp name="dateDerniereMaj" column="DATE_DERN_MAJ_CTRL" /> -->
<property name="dateCreationLogique" type="timestamp" column="DATE_CREATION_LOG" />
<property name="dateDerniereMAJLogique" type="timestamp" column="DATE_DERN_MAJ_LOG" />
<property name="dateCreationAffLogique" type="timestamp" column="DATE_CREATION_AFF_LOG" />
<property name="dateDerniereAffMAJLogique" type="timestamp" column="DATE_DERN_MAJ_AFF_LOG" />
<property name="codeInitiateur" type="string" column="CODE_INITIATEUR_CTRL"/>
<property name="numero" type="string" column="NO_DET" not-null="true" unique="true" />
<property name="dateEmission" type="date" column="DATE_EMIS_NO_DET" not-null="true" />
<property name="dateAnnulation" type="date" column="DATE_ANNUL_NO_DET" />
<property name="raisonAnnulation" type="string" column="REF_RAIS_ANNUL_NO_DET" />
<property name="refModeGestionCaissier" type="string" column="REF_MODE_GESTION_CAIS_DET" />
<property name="dateDebutDisponibiliteCaissier" type="date" column="DATE_DEBUT_DISPON_CAIS_DET" />

<joined-subclass name="com.iris.business.cc.detaillant.types.AffaireDetaillantReseauVtes" schema="DET" table="T_DETAILLANT_VENTE">

<key column="ID_EA_DET" />

<property name="codeInitiateur" type="string" column="CODE_INITIATEUR_CTRL"/>

<!-- AffaireDetaillant inherited data -->
<property name="nom" type="string" column="NOM_DV" not-null="true" />
<property name="succursale" type="string" column="NO_SUCC_DV" />
<property name="adresseLivraisonIdentique" type="boolean" column="IND_MEME_ADR_LIVR_DV" not-null="true" />
<property name="remarquesEntentes" type="string" column="DESC_COMMENT_ENT_EJ_DV" />
<property name="typeCommerce" type="string" column="REF_TYPE_COMM_DV" />

<!-- AffaireDetaillantReseauVteOSBL inherited data -->
<property name="communicationOrale" type="string" column="REF_LANG_ORAL_DV" />
<property name="communicationEcrite" type="string" column="REF_LANG_ECRIT_DV" />
<property name="nonDivulgation" type="boolean" column="IND_NON_DIVULG_DET" not-null="true" />
<property name="statut" type="string" column="REF_STATUT_DET_DV" />
<property name="statutAnnulation" type="string" column="REF_STATUT_ANNUL_DV" />
<property name="ind24Heures7Jours" type="boolean" column="IND_24_HEURE_7_JOUR_DV" not-null="true" />
<property name="saison" type="string" column="REF_SAISON_OPER_DV" />
<property name="dateDebutOperation" type="date" column="DATE_DEBUT_OPER_DV" />



<set name="affiliationsDet" schema="DET" table="T_AFFILIATION_DET_L" lazy="true" where="IND_AFFILIATION_PRIM_AD=1" cascade="save-update" >

<key column="ID_EA_DET" />

<composite-element class="com.iris.business.cc.detaillant.types.AffaireAffiliationDetaillant">

<property name="codeInitiateur" type="string" column="CODE_INITIATEUR_CTRL"/>

<property name="indAffiliationPrimaire" column="IND_AFFILIATION_PRIM_AD" type="boolean" not-null="true" />

<many-to-one name="codeCompte" column="ID_COC" class="com.iris.business.cc.detaillant.types.AffaireCodeCompte" not-null="true" />

</composite-element>
</set>

<joined-subclass
</class>
</hibernate-mapping>

=====================================================================================
SQL> desc DET.T_AFFILIATION_DET_L

Name Null? Type
----------------------------------------- -------- ----------------------------
ID_COC NOT NULL NUMBER(28)
ID_EA_DET NOT NULL NUMBER(28)
IND_AFFILIATION_PRIM_AD NOT NULL NUMBER(1)
CODE_INITIATEUR_CTRL NOT NULL VARCHAR2(20)
NO_VERSION_CTRL NOT NULL NUMBER(6)
DATE_CREATION_CTRL NOT NULL TIMESTAMP(6)
DATE_DERN_MAJ_CTRL NOT NULL TIMESTAMP(6)

====================================================================================




SystemOut O Hibernate: delete from DET.T_AFFILIATION_DET_L where ID_COC=? and IND_AFFILIATION_PRIM_AD=? and CODE_INITIATEUR_CTRL=? and ID_EA_DET=?

SystemOut O SDEBUG --> value( 1 ) = 107240000150403
SystemOut O SDEBUG --> value( 2 ) = true
SystemOut O SDEBUG --> value( 3 ) = 6was002 <-- this one is not the existing data in DB, record won't be deleted, BD = 7was002

SystemOut O SDEBUG --> value( 4 ) = 107320000050403

SystemOut O SDEBUG --> value( 1 ) = 107240000150403
SystemOut O SDEBUG --> value( 2 ) = true
SystemOut O SDEBUG --> value( 3 ) = 6was002
SystemOut O SDEBUG --> value( 4 ) = 110960000410403

SystemOut O SDEBUG --> value( 1 ) = 107240000150403
SystemOut O SDEBUG --> value( 2 ) = true
SystemOut O SDEBUG --> value( 3 ) = 6was002
SystemOut O SDEBUG --> value( 4 ) = 110740000000403

SystemOut O SDEBUG --> value( 1 ) = 107240000150403
SystemOut O SDEBUG --> value( 2 ) = true

SystemOut O SDEBUG --> value( 3 ) = 6was002 <-- this one is not the existing data in DB, record won't be deleted, BD = 7was002

SystemOut O SDEBUG --> value( 4 ) = 108480000180403



SystemOut O SDEBUG --> value( 1 ) = 107240000150403

SystemOut O SDEBUG --> value( 2 ) = true

SystemOut O SDEBUG --> value( 3 ) = 6was002

SystemOut O SDEBUG --> value( 4 ) = 107310000000403



SystemOut O Hibernate: insert into DET.T_AFFILIATION_DET_L (ID_COC, IND_AFFILIATION_PRIM_AD, CODE_INITIATEUR_CTRL, ID_EA_DET) values (?, ?, ?, ?)



SystemOut O SDEBUG --> value( 1 ) = 107240000150403

SystemOut O SDEBUG --> value( 2 ) = true

SystemOut O SDEBUG --> value( 3 ) = 6was002

SystemOut O SDEBUG --> value( 4 ) = 107310000000403



SystemOut O SDEBUG --> value( 1 ) = 107240000150403 <--+

SystemOut O SDEBUG --> value( 2 ) = true |__ won't be inserted, because it was not previously deleted.

SystemOut O SDEBUG --> value( 3 ) = 6was002 |
SystemOut O SDEBUG --> value( 4 ) = 108480000180403 <--+

JDBCException W net.sf.hibernate.util.JDBCExceptionReporter SQL Error: 1, SQLState: 23000
JDBCException E net.sf.hibernate.util.JDBCExceptionReporter ORA-00001: unique constraint (DET.CPK_AFFILIATION_DET_L) violated

JDBCException E net.sf.hibernate.util.JDBCExceptionReporter could not insert collection rows: [com.iris.business.cc.detaillant.types.AffaireCodeCompte.collAffiliationsDetetaillants#107240000150403]

JDBCException E net.sf.hibernate.util.JDBCExceptionReporter TRAS0014I: L'exception suivante a été consignée : java.sql.SQLException: ORA-00001: unique constraint (DET.CPK_AFFILIATION_DET_L) violated

thanks


Top
 Profile  
 
 Post subject: online waiting thanks
PostPosted: Tue Feb 08, 2005 2:38 pm 
Newbie

Joined: Tue Feb 08, 2005 2:26 pm
Posts: 4
i am waiting your reply


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.