-->
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: Optimizing sequence read using seq.nextval
PostPosted: Mon Jul 12, 2004 11:15 am 
Newbie

Joined: Mon Jun 07, 2004 11:17 am
Posts: 4
Hi,

Hibernate makes two SQL statements when used along with a DB generated sequence.

1) Read sequence value
2) Insert the record...

Is it possible to use a dynamic insert...like that can be used in a regular SQL?

insert into tableA (id, a, b) values (seq.nextval, 10, 20)

Any suggestions? I am using Oracle,

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Trouble with that is that Hibernate doesn't know the generated pk after the insert.

I think oracle has some kind of "insert ... returning ..." syntax that we could support in future.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i think it is not possible, it may have many undesired impacts.
select nextval is done when calling session.save(obj)

insert is done when flush() (or commit with flushmode=auto) is called.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:30 am 
Newbie

Joined: Mon Jun 07, 2004 11:17 am
Posts: 4
Thanks Gavin.

Is there any workaround...I generate around 100,000 records and now it essentially makes it 200,000 DB round trips.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:32 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate is not the right tool for mass data operations. I'd recommend the data import tools of the database for this. (In Oracle, I'd usually also tune the transaction settings and REDO logs for such an import.)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:37 am 
Newbie

Joined: Mon Jun 07, 2004 11:17 am
Posts: 4
Hi Anthony,

Thanks for your reply.

Your reply states that sequence is read when I call session.save() and insert will happen when I call flush/commit.

But from the output it looks like:

select sequence
insert record
select sequence
insert record
select sequence
insert record
select sequence
insert record
select sequence
insert record

If it works the way you have specified it will be a performance boost...is there some special setting I have to take care?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
try to temporary set flushmode = never, and call flush before commit.
But i don't think that in your case, it will change something... you'll have n select nextval and at flushtime n inserts...
http://www.hibernate.org/hib_docs/api/n ... tFlushMode

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:46 am 
Newbie

Joined: Mon Jun 07, 2004 11:17 am
Posts: 4
Hi Anthony,

Thanks for your reply.

I have used "Hibernate Synchronizer" and noticed the implementation is something like after each call to save() a commit is performed.

I think this could be the problem.

I will test this hypothesis and post my results.

Thanks for the feedbacks.


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.