-->
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.  [ 3 posts ] 
Author Message
 Post subject: INSERT members of a child list without an UPDATE
PostPosted: Fri Sep 30, 2005 2:48 pm 
Newbie

Joined: Mon Dec 13, 2004 6:30 pm
Posts: 5
I have a system where we are batching up Hibernate objects and logging
them to the database asynchronously. We are inserting a continuous
stream of many objects. The resulting rows are only accessed with SQL
on an infrequent basis from other processes.

I noticed our system getting bogged down logging one of these types of
objects with a mapping similar to:

Code:
<hibernate-mapping default-lazy="false">   
    <class name="Foo" table="FOO" mutable="false">   
        <id name="id" column="ID" type="java.lang.Long">   
            <generator class="native"/>
        </id>

        <list name="bars" lazy="false" cascade="all-delete-orphan">
            <key column="FOO_ID"/>
            <index column="POSITION"/>
            <one-to-many class="Bar"/>
        </list>

        <!-- a bunch of properties -->
    </class>

    <class name="Bar" table="BAR" mutable="false">   
        <id name="id" column="ID" type="java.lang.Long">   
            <generator class="native"/>
        </id>

        <property name="baz" type="int" update="true" insert="true"
                  column="BAZ"/>
    </class>
</hibernate-mapping>


Looking at the Hibernate logs, I see that first see my parent object
Foo inserted, then each Bar object in the child list gets its
properties inserted, then each Bar row is updated with the id of its
parent and position in the list.

Code:
30 11:25:57.515 DEBUG [SQL] insert into FOO (ID) values (?)
30 11:25:57.518 DEBUG [SQL] insert into BAR (BAZ, ID) values (?, ?)
30 11:25:57.518 DEBUG [SQL] insert into BAR (BAZ, ID) values (?, ?)
30 11:25:57.518 DEBUG [SQL] insert into BAR (BAZ, ID) values (?, ?)
30 11:25:57.528 DEBUG [SQL] update BAR set FOO_ID=?, POSITION=? where ID=?
30 11:25:57.528 DEBUG [SQL] update BAR set FOO_ID=?, POSITION=? where ID=?
30 11:25:57.528 DEBUG [SQL] update BAR set FOO_ID=?, POSITION=? where ID=?

I have since discovered that the reason we were getting bogged down
doing these updates was that Postgres 7.4.7 doesn't know that it can
use an int8 index when presented with an int4 literal. My experiments
suggest that this has been fixed in Postgres 8. This will fix the
immediate problem.

Still, I would like to make the Hibernate classes we use in this
fashion to only use INSERT. I have enough problems, the less I can
have the database bogged down doing unnecessary work, the better.

Is there any way to add a child list to the database with no UPDATEs?
It seems like that is just the algorithm you use to persist a graph of
objects, but perhaps there is another way to avoid the UPDATE.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:06 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Make it a bi-directional association, and use inverse="true" on your <list> tag (see http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#example-parentchild-bidir)

_________________
nathan


Top
 Profile  
 
 Post subject: works except for the list index
PostPosted: Fri Sep 30, 2005 4:48 pm 
Newbie

Joined: Mon Dec 13, 2004 6:30 pm
Posts: 5
Hi, this works except for the list index part. Doesn't look like i can do that with an inverse association, unless I let the object know its list position, which is ugly but maybe acceptable in this situation.


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