-->
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: insert into table with n entries leads to n updates
PostPosted: Tue Aug 02, 2005 4:41 am 
Newbie

Joined: Wed Sep 22, 2004 10:10 am
Posts: 15
Location: Darmstadt, Germany
Hello dear forum,

I have a problem in my application (a GIS Server) that occurs when inserting data into a table that contains several Oracle Spatial columns mapped by UserTypes. What happens is that when inserting a new row, the Hibernate log shows that for each row currently saved in that table, an update statement follows after the insert statement. Needless to say, this is extremely slow, and I don't really have an idea why this happens. Any help would be greatly appreciated, especially points what might actually trigger this behaviour in Hibernate (maybe the spatial reference system conversion that oracle 10g does internally when inserting data?). Please find the environment/error information below.

Best Regards & thanks in advance, Thorsten

Hibernate version: 2.1.8

Mapping documents: Grid.hbm.xml:
Code:
<?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>
<class name="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.Grid" table="GRID">

    <id name="id" type="long" column="ID">
        <generator class="native" />
    </id>

    <property name="name" type="java.lang.String" column="NAME" />

    <property name="description" type="java.lang.String" column="DESCRIPTION" />

    <property name="xSpacing" type="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.usertypes.SDOPoint2DType" column="X_SPACING" />

    <property name="ySpacing" type="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.usertypes.SDOPoint2DType" column="Y_SPACING" />

    <property name="xCount" type="long" column="X_COUNT" />

    <property name="yCount" type="long" column="Y_COUNT" />

    <property name="llPoint" type="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.usertypes.SDOPoint3DType" column="LL_POINT" />

   <property name="mbb" type="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.usertypes.SDOSurface2DType" column="MBB" />

    <property name="zCoord" type="de.fhg.igd.CityServer3D.dbLayer.models.geobase21.hibernate.usertypes.DoubleArrayType" column="Z_COORD" />

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
/**
     * This is a DAO method. Each DAO is equipped with a reference to a hibernate session by DAO Factory, which also manages opening/closing of sessions.
     */
    public void putGrid(Grid grid) throws HibernateException {
      this.getSession().saveOrUpdate(grid);
    }


Name and version of the database you are using: Oracle 10g with Spatial Extension

The generated SQL (show_sql=true):
Code:
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into GRID (NAME, DESCRIPTION, X_SPACING, Y_SPACING, X_COUNT, Y_COUNT, LL_POINT, MBB, Z_COORD, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update GRID set NAME=?, DESCRIPTION=?, X_SPACING=?, Y_SPACING=?, X_COUNT=?, Y_COUNT=?, LL_POINT=?, MBB=?, Z_COORD=? where ID=?
Hibernate: update GRID set NAME=?, DESCRIPTION=?, X_SPACING=?, Y_SPACING=?, X_COUNT=?, Y_COUNT=?, LL_POINT=?, MBB=?, Z_COORD=? where ID=?
...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 4:52 am 
Newbie

Joined: Tue May 17, 2005 4:54 am
Posts: 15
Location: Germany, Karlsruhe
Hi,

in the first place, try to set an unsaved-value in your mapping.
This helps Hibernate find out whether your transient objects are dirty or not. As there is no such value currently set, the object to be inserted is probably considered dirty and thus there are UPDATE-Statements committed.

There is a FaQ topic on this:
http://www.hibernate.org/116.html#A39

I hope this was helpful, if so, please rate this post positive :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 6:00 am 
Newbie

Joined: Wed Sep 22, 2004 10:10 am
Posts: 15
Location: Darmstadt, Germany
Hi,

and thanks for your post. I actually assigned a unsaved-value most of the time, but forgot in this case - thanks for pointing that out. In any way, this unfortunately did not solve the problem. There is one additional thing I have noticed that might give one or another a hint: When going through the logs, before the first insert statement is sent away, this appears:

Code:
2005-08-02 11:26:42,631 DEBUG Cache:741 GRID now: 1122974802631
[i]2005-08-02 11:26:42,635 DEBUG Cache:742 GRID Creation Time: 1122974802630 Next To Last Access Time: 0
2005-08-02 11:26:42,638 DEBUG Cache:744 GRID mostRecentTime: 1122974802630
2005-08-02 11:26:42,641 DEBUG Cache:745 GRID Age to Idle: 120000 Age Idled: 1
2005-08-02 11:26:42,644 DEBUG Cache:769 net.sf.hibernate.cache.UpdateTimestampsCache: Is element with key GRID expired?: false[/i]
Hibernate: insert into GRID (NAME, DESCRIPTION, X_SPACING, Y_SPACING, X_COUNT, Y_COUNT, LL_POINT, MBB, Z_COORD, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update GRID set NAME=?, DESCRIPTION=?, X_SPACING=?, Y_SPACING=?, X_COUNT=?, Y_COUNT=?, LL_POINT=?, MBB=?, Z_COORD=? where ID=?


Later on, this cache check apparently does not happen. I also noticed something else that is interesting: Beforehand, I always deleted the database entries created so far and started anew. This time, I accidently left the old entries in the table and it started with one insert and one update anyway. So it is possibly not one update statement per entry in the table, but one statement per object inserted in the current session. Any explanations for this phenomenon?

Thanks again,

Thorsten


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 8:21 am 
Newbie

Joined: Wed Sep 22, 2004 10:10 am
Posts: 15
Location: Darmstadt, Germany
FYI, should anyone have the same issue coming up: The problem was solved when forcing a flush() and commiting a transaction after each insert.

Best Regards,

Thorsten


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.