-->
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: Avoid multiple DB Calls during sequence generation
PostPosted: Fri Dec 17, 2004 3:25 pm 
Newbie

Joined: Fri Dec 17, 2004 3:08 pm
Posts: 3
Hi,

I'm using the Oracle sequence generation to insert a new row into my detail tables.
I noticed that Hibernate generates 2 calls to the db for each insert..
1. To generate sequence.nextval
2. The actual insert

Is there any way that I could reduce this to just one call, and still continue using sequences? We have a home-grown persistence layer that I want to replace and that uses the sequence.nextval within the insert statement, thereby reducing one call. This is having a decent performance impact if I try to insert 100 + rows (about 2 seconds slower).

Thank you for your help..

Hibernate version: 2.1

Code:
Mapping documents:
    <id
        name="tradeOrderDetailId"
        type="java.lang.Integer"
        column="TRADE_ORDER_DETAIL_ID"
    >
        <meta attribute="field-description">
           @hibernate.id
            generator-class="sequence"
            type="java.lang.Integer"
            column="TRADE_ORDER_DETAIL_ID"

           @hibernate.generator-param
           name="sequence"
           value="trade_order_detail_seq"
        </meta>
        <generator class="sequence">
            <param name="sequence">trade_order_detail_seq</param>
        </generator>
    </id>


Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):

[java] Hibernate: select trade_order_detail_seq.nextval from dual
[java] Hibernate: insert into TRADE_ORDER_DETAIL (TRADER_NAME, SUIT_CHECK, SOLICITATION, SETTLEMENT_TYPE, DEALER_PR
ICE, QTY_TYPE, PRICING_METHOD, CUSTOMER_CONTACT, ORDER_DURATION, NOTIFY_ISSUER, IS_PROJECTED_SETTLEMENT, INFLATION_ACCRU
AL, INDEX_FACTOR, FACTOR_DATE, COMMISSION_TYPE, CREATION_DATE, UPDATE_DATE, CREATED_BY, DEALER_CONTACT, EXCHANGE, OPEN_Q
TY, QUOTE_DISCOUNT, RECORD_LOCKED_TIME, INVENTORY_ACCOUNT, COMMENTS, AGENT_DEALER, ERROR_CODE, ERROR, NUMBER_OF_SUB_ACCO
UNTS, CHANNEL, CONFIRM_MESSAGE, IS_BOOKED, UPDATED_BY, LORD_MESSAGE, BOOKING_MESSAGE, TRADE_ORDER_ID, TRADE_ORDER_DETAIL
_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 3:29 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://blog.hibernate.org/cgi-bin/blosx ... find&path=

pretty sure this overhead is not only due to the sequence call.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 5:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate need to get the id of the generated value somehow otherwise your object won't be equal to what is stored in the db.

I don't know if the JDBC3 generatedkeys can be used here ? (haven't played with that yet - but that is supported in H2)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 10:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
using SeqHiLo would also be a possibility


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.