-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 6:45 am 
Newbie

Joined: Thu Sep 10, 2009 5:43 am
Posts: 15
Hello
I have a question aboout hibernate and oracle sequence.
I doing some bussiness method which adds about 100.000 records to db. But 1/3 of the time takes queries :
select S_ADDRESS.nextval from dual

How to resolve this problem


Best regards


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 6:54 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi mireksz,

Please post your mapping file here. It depends on how you have made the id element's generator class.

<id
name="identifier"
column="identifier"
type="long">
<generator class="sequence">
<param name="sequence">$sequence_name</param>
</generator>
</id>

Hope this helps.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 7:12 am 
Newbie

Joined: Thu Sep 10, 2009 5:43 am
Posts: 15
In my mappings I have

Code:
        <id name="idAddress">
            <column name="`ID_ADDRESS`"/>
            <generator class="sequence">
                <param name="sequence">S_ADDRESS</param>
            </generator>
        </id>


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 7:17 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Code:
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>


now have a look at the log , after adding these statements in cfg.xml file. Each time a new object is added , a query is fired.

Please get back here to know what happened.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 7:29 am 
Newbie

Joined: Thu Sep 10, 2009 5:43 am
Posts: 15
Code:
select S_ADDRESS.nextval from dual
Hibernate: /* insert Address */ insert into NEXT_TEST."ADDRESS" ("VERSION", "STREET", "HOUSE_NUMBER", "POST_CODE", "POST", "LOCALITY", "FLAT_NUMBER", "COUNTY", "COMMUNE", "CREATE_DATE", "KLU_UNIQ", "ID_ADDRESS_TYPE", "ID_CONTACT", "ID_COUNTRY", "ID_PROVINCE", "ID_ADDRESS") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

select S_ADDRESS.nextval from dual
Hibernate: /* insert Address */ insert into NEXT_TEST."ADDRESS" ("VERSION", "STREET", "HOUSE_NUMBER", "POST_CODE", "POST", "LOCALITY", "FLAT_NUMBER", "COUNTY", "COMMUNE", "CREATE_DATE", "KLU_UNIQ", "ID_ADDRESS_TYPE", "ID_CONTACT", "ID_COUNTRY", "ID_PROVINCE", "ID_ADDRESS") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


select S_ADDRESS.nextval from dual
Hibernate: /* insert Address */ insert into NEXT_TEST."ADDRESS" ("VERSION", "STREET", "HOUSE_NUMBER", "POST_CODE", "POST", "LOCALITY", "FLAT_NUMBER", "COUNTY", "COMMUNE", "CREATE_DATE", "KLU_UNIQ", "ID_ADDRESS_TYPE", "ID_CONTACT", "ID_COUNTRY", "ID_PROVINCE", "ID_ADDRESS") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


This inserts are in one transaction.
This select S_ADDRESS.nextval from dual takes 1/3 time of this task


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 8:07 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Each time the object is added, during insert it looks for the sequence value. Is that a problem inserting 100 records at a time ?

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 8:24 am 
Newbie

Joined: Thu Sep 10, 2009 5:43 am
Posts: 15
When I add 100.000 records the hibernate generates
100.000 select (select S_ADDRESS.nextval from dual) Can I cache this sequence or told hibernate to take for example 100 per select


Top
 Profile  
 
 Post subject: Re: Hibernate oracle sequence
PostPosted: Mon Aug 09, 2010 8:35 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Here every time the record is inserted, it needs to hit the database to acquire the identifier value. So there is no meaning in caching this query.

Also share your business scenario when 100 records are inserted.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


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