-->
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.  [ 6 posts ] 
Author Message
 Post subject: JDBC batching, IDENTITY generator, and StatelessSession
PostPosted: Wed Aug 30, 2017 7:37 am 
Newbie

Joined: Wed Aug 30, 2017 7:29 am
Posts: 4
Greetings!

Docs wrote:
Hibernate disables insert batching at the JDBC level transparently if you use an identity identifier generator.

i guess because batch inserts can not return many generated values
but for Stateless sessions they can be ignored, right?
So, may be that rule can be muted for StatlessSessions?

Bless you..


Top
 Profile  
 
 Post subject: Re: Batching, IDENTITY, StatelessSession
PostPosted: Wed Aug 30, 2017 8:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The reason why IDENTITY generated does not mix with JDBC batch inserts is because by the time flush comes, Hibernate already executed the inserts to know the entity identifier upon attaching the entity to the currently running Persistence Context.

However, because the StatelessSession does not have a Persistence Context, it has no way of delaying the inserts so that they can be batched during flushing, right?

Prior to joining the Hibernate team, I've been also involved in developing enterprise applications using Hibernate, especially Batch Processors. However, there was no instance where we ever needed to use the StatelessSession which has many inconveniences:

- does not implement a first-level cache
- nor interact with any second-level cache
- nor does it implement transactional write-behind or automatic dirty checking
- nor do operations cascade to associated instances
- Collections are ignored by a stateless session.
- bypass Hibernate's event model and interceptors (not very good for Envers either).
- vulnerable to data aliasing effects, due to the lack of a first-level cache.

So, we've been using the standard Session for all our batch processing. For more details about the best way of batching using JPA and Hibernate, check out this article.


Top
 Profile  
 
 Post subject: Re: Batching, IDENTITY, StatelessSession
PostPosted: Wed Aug 30, 2017 8:32 am 
Newbie

Joined: Wed Aug 30, 2017 7:29 am
Posts: 4
vlad wrote:
However, because the StatelessSession does not have a Persistence Context, it has no way of delaying the inserts so that they can be batched during flushing, right?


Absolutely, it seems hibernate doing mistake extending that rule for StatelesSession too
StatelessSession inconveniences is not subject of my question, but thanks for that.

IDENTIY in my solution potentially can provide better performance
Because SequenceStyleGenerator has extra queries to sequences


Top
 Profile  
 
 Post subject: Re: JDBC batching, IDENTITY generator, and StatelessSession
PostPosted: Wed Aug 30, 2017 8:47 am 
Newbie

Joined: Wed Aug 30, 2017 7:29 am
Posts: 4
In case of Oracle RDBMS
Identity is just wrapper under Sequence


Top
 Profile  
 
 Post subject: Re: JDBC batching, IDENTITY generator, and StatelessSession
PostPosted: Wed Aug 30, 2017 8:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
That's the case for PostgreSQL as well. However, it's much more efficient for Hibernate to use a SEQUENCE than IDENTITY.


Top
 Profile  
 
 Post subject: Re: JDBC batching, IDENTITY generator, and StatelessSession
PostPosted: Wed Aug 30, 2017 8:54 am 
Newbie

Joined: Wed Aug 30, 2017 7:29 am
Posts: 4
I got it, thank you very much!


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