-->
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.  [ 6 posts ] 
Author Message
 Post subject: hbm bug concerning the update order on different tables ?
PostPosted: Thu Jun 02, 2005 10:33 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
Hello,

i have a problem concering the order in which update / insert statements
on different tables are executed by hibernate. What i do not understand is
why hibernate executes statements for insert/update in a different
order when i change the fetchmode of my criteria query !!
(hibernate 3.0.5)

The first criteria is :

Code:
Criteria crit = session.createCriteria( AwGeschaeft.class )
.setFetchMode( "SetOfAwBesicherung", FetchMode.SELECT );
List g = crit.list();


performs the updates in the following order (first AW_GESCHAEFT table,
then AW_BESICHERUNG table) :

Code:
Hibernate: update BA2_DEV.AW_GESCHAEFT set MARKTWERT=?, ART=? where BANK_ID=? and STICHTAG=? and LAUFKENNUNG_NR=? and KONTO_NR=? and KONTO_NR_SUB=?
Hibernate: update BA2_DEV.AW_BESICHERUNG set ABLAUFDATUM=? where BANK_ID=? and STICHTAG=? and LAUFKENNUNG_NR=? and KONTO_NR=? and KONTO_NR_SUB=? and SICHERUNGS_ID=?


The second criteria is (only different fetch mode) :

Code:
Criteria crit = session.createCriteria( AwGeschaeft.class )
.setFetchMode( "SetOfAwBesicherung", FetchMode.JOIN );
List g = crit.list();


performs the following updates (different order of tables, first
the AW_BESICHERUNG table then the AW_GESCHAEFT table) :

Code:
Hibernate: update BA2_DEV.AW_BESICHERUNG set ABLAUFDATUM=? where BANK_ID=? and STICHTAG=? and LAUFKENNUNG_NR=? and KONTO_NR=? and KONTO_NR_SUB=? and SICHERUNGS_ID=?
Hibernate: update BA2_DEV.AW_GESCHAEFT set MARKTWERT=?, ART=? where BANK_ID=? and STICHTAG=? and LAUFKENNUNG_NR=? and KONTO_NR=? and KONTO_NR_SUB=?


why does hibernate perform the statement in a different order on the
tables ? is this a bug ? is there a way to influence the table order ?

regards,
Andreas



Hibernate version: 3.0.5

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

<class name="AwGeschaeft" table="AW_GESCHAEFT" schema="BA2_DEV" lazy="false">
<composite-id name="id" class="AwGeschaeftId">
<key-property name="BankId" type="java.lang.Short">
<column name="BANK_ID" scale="3" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="Stichtag" type="java.lang.Integer">
<column name="STICHTAG" scale="8" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="LaufkennungNr" type="java.lang.Byte">
<column name="LAUFKENNUNG_NR" scale="2" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="KontoNr" type="java.lang.Long">
<column name="KONTO_NR" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="KontoNrSub" type="java.lang.Long">
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
</composite-id>
<property name="Marktwert" type="java.math.BigDecimal">
<column name="MARKTWERT" scale="20" precision="4" not-null="false" sql-type="NUMBER" />
</property>
<property name="Art" type="java.lang.Long">
<column name="ART" scale="10" precision="0" not-null="false" sql-type="NUMBER" />
</property>

<set name="SetOfAwBesicherung" fetch="join"
inverse="true">
<key>
<column name="BANK_ID" scale="3" precision="0" not-null="false" />
<column name="STICHTAG" scale="8" precision="0" not-null="false" />
<column name="LAUFKENNUNG_NR" scale="2" precision="0" not-null="false" />
<column name="KONTO_NR" scale="15" precision="0" not-null="false" />
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="false" />
</key>
<one-to-many class="AwBesicherung" />
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="AwBesicherung" table="AW_BESICHERUNG" schema="BA2_DEV" lazy="false">
<composite-id name="id" class="AwBesicherungId">
<key-property name="BankId" type="java.lang.Short">
<column name="BANK_ID" scale="3" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="Stichtag" type="java.lang.Integer">
<column name="STICHTAG" scale="8" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="LaufkennungNr" type="java.lang.Byte">
<column name="LAUFKENNUNG_NR" scale="2" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="KontoNr" type="java.lang.Long">
<column name="KONTO_NR" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="KontoNrSub" type="java.lang.Long">
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="true" sql-type="NUMBER" />
</key-property>
<key-property name="SicherungsId" type="java.lang.String">
<column name="SICHERUNGS_ID" scale="100" precision="0" not-null="true" sql-type="VARCHAR2" />
</key-property>
</composite-id>

<many-to-one name="AwGeschaeft" class="AwGeschaeft" update="false" insert="false"
>
<column name="BANK_ID" scale="3" precision="0" not-null="false" />
<column name="STICHTAG" scale="8" precision="0" not-null="false" />
<column name="LAUFKENNUNG_NR" scale="2" precision="0" not-null="false" />
<column name="KONTO_NR" scale="15" precision="0" not-null="false" />
<column name="KONTO_NR_SUB" scale="15" precision="0" not-null="false" />
</many-to-one>
<property name="Ablaufdatum" type="java.util.Date">
<column name="ABLAUFDATUM" scale="7" precision="0" not-null="false" sql-type="DATE" />
</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Now what do the forum rules say about using the phase "bug in Hibernate"?

Normally I would deliberately NOT answer this question because you did that.

As per the documentation, Hibernate does not guarantee any special ordering of updates, UNLESS you specify hibernate.order_updates.

Now, as punishment, you are required to go and read

(1) the forum rules
(2) the reference documentation, from cover to cover

before making any more posts here.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 11:30 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
Hello Gavin,

thanks for the reply, but hibernate.order_updates does solve my problem.
The problem is that all the inserts have to be made to the AW_GESCHAEFT table
before any insert into the AW_BESICHERUNG table is made (because of foreign
key constraints). What i need is an order (update/insert) by table not by pk.

In my mapping AwGeschaeft i have a set association to AwBesicherung, and from
AwBesicherung i have a many-to-one association to my AwGeschaeft. I load an
AwGeschaeft and save it. I thought hibernate would know that it always has to
update the (changed) AwGeschaeft first, before it updates all the AwBesicherung
that are associated with the AwGeschaeft. Depending on the fetching strategy
hibernate first updates the AW_GESCHAEFT table and then the AW_BESICHERUNG table,
changing the fetch stategy the tables are updated the other way round. I thought
hibernate would know because of the mapping, which updates (ordered by table) have
to be made first, to avoid db constraint violations.


Sorry if i could not make that clear in my first post.

thanks,
Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 11:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Then use cascade save.

I thought I told you to read the documentation before posting here? You clearly did not have time to do that, and hence you are still asking questions that are answered in the documentation!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 2:46 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
actually i tried that with all possible cascade attributes values.
also with all kinds of inverse and not-null attributes, too. nothing worked.

not considering that, what i do not understand is why does hibernate
have a different update order (concerning the table order) when i only change
the fetch strategy ? fetch mode join results in a different update order
than fetch mode select. how is this possible ? having noticed this behaviour, i am wondering if the cascade attribute really tells hibernate
the correct update order, if i can change the update order by changing the
fetch mode.

regards,
Andreas


Top
 Profile  
 
 Post subject: same here
PostPosted: Fri Jun 03, 2005 9:47 am 
Newbie

Joined: Fri Jun 03, 2005 9:21 am
Posts: 1
Hi there,

I've got exactly the same problem as andyw. I've been studying all available Hibernate-documentation for a couple of days now and could not come up with a solution.

  • i've got two tables + two classes
  • the first table is the parent-table
  • the second table is the child table which needs an existing parent-table entry. to ensure this, there is a foreign-key constraint.
  • both are related through a SET <-> MANY-TO-ONE declaration in my hibernate mapping-files

Option #1
  • for fast loading-purposed I'm using 'fetch="join"'. This is absolutely necessary, since our application's performance is inacceptable, otherwise.
  • the set-attribute has 'cascade="save-update"' set.
  • loading works fine, but saving always tries to save the child-entry first.

Option #2 (as Gavin proposed)
  • same setting as above, but 'cascade="none".
  • same result. even the cascadition is performed in the same way. is there something else that might be enforcing the use of cascaditions?

Option #3
  • since outer-join-fetching and saving do not seem to work together, I've changed the declaration to 'fetch="select"'
  • and 'cacade="none"'
  • this time - when saving - there is still cascadition, but the statements are send to the database in the correct order (first creating the entry in table1 then creating the entry in table table2).


As far as I see it, this is the same situation as described above... even the same outcome ;-)
And I'm out of Ideas...

Any help is greatly appreciated.


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