-->
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.  [ 7 posts ] 
Author Message
 Post subject: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Wed Jan 13, 2016 1:37 pm 
Beginner
Beginner

Joined: Thu Nov 26, 2015 11:40 am
Posts: 33
I have an entity that is using "enhanced-sequence" as strategy. When I use optimizer as "pooled or pooled-lo" I am able insert the rows only if the increment_size value is 1.

If I set increment_size > 1 I see the following error:

Code:
Name:, Time:0, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["values next value for pooledLo_sequence"], Params:[()]
Name:, Time:0, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["values next value for pooledLo_sequence"], Params:[()]
FAILED: insertRows
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.madhu.hibernate.identifiers.jpa.PooledLoSequence#43]


Below is my entity class.

@Entity(name="pooled_lo_sequence_table")
Code:
public class PooledLoSequence {
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="pooledLo_seq")
   @GenericGenerator(name="pooledLo_seq", strategy="enhanced-sequence",
   parameters={
         @Parameter(name="sequence_name", value="pooledLo_sequence"),
         @Parameter(name="initial_value", value="1"),
         @Parameter(name="increment_size",value="2"),
         @Parameter(name="optimizer", value="pooled")
   })
   private Long id;
   
   public PooledLoSequence() {
   }
}


With the following test code.

Code:
      IntStream.range(0, 10).forEach(n -> {
         PooledLoSequence row = new PooledLoSequence();
         session.persist(row);
      });


The hibernate version I am using is 5.0.4 with Derby DB ver 10.12.1.1.

Not sure if I am missing anything or is it a new bug introduced in 5.x?


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Thu Jan 14, 2016 3:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I tested this on 5.0.4 and 5.0.6 and it works with HSQLDB, so it's not a problem related to the identifier generators.
So, it might be a Derby issue. Please add a JIRA issue and attach a test case to replicate this problem. Thanks.


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Thu Jan 14, 2016 1:55 pm 
Beginner
Beginner

Joined: Thu Nov 26, 2015 11:40 am
Posts: 33
While creating the sequence I used
Quote:
create sequence...increment by 1
which is not matching with
Quote:
increment_size property of @Parameter, which is 2 in my case.
.

So I am wondering, whether the value of "increment_size" property should match the "increment by" value used while creating the sequence for pooled and pooled-lo strategy? and how about hilo strategy?


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Thu Jan 14, 2016 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
There's no correlation between the name of the parameter and the SQL keywords for creating a sequence.


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Fri Jan 15, 2016 12:20 am 
Beginner
Beginner

Joined: Thu Nov 26, 2015 11:40 am
Posts: 33
I think I missed putting clear information in my earlier question. I am trying to understand the difference between "pooled" and "pooled-lo" and going through your link http://vladmihalcea.com/hibernate-hidden-gem-the-pooled-lo-optimizer/.

I see that you are using a JDBC insert along with hibernate session persist to demonstrate the sequence generation with "pooled vs pooled-lo".

Two things I notice is, that the sequence value is increment by 5 each time a JDBC insert performed (11, 16, 21, 26 etc). This could be because while creating this sequence in the database the "increment by" might be set as 5. Is my assumption correct?

Second one I notice is, the "increment_size" value is set as 5 in the Hibernate domain classes (PooledSequenceIdentifier/PooledLoSequenceIdentifier) as well. So ,should this "increment_size" value be equal to "increment by" value or is it just a coincidence? Because when I try with scenarios where "increment by" < "increment_size" and I see the code failing with exception
Code:
FAILED: insertRows
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.madhu.hibernate.identifiers.jpa.PooledLoSequence#43]


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Fri Jan 15, 2016 1:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The SQL insert was because I wanted to demonstrate that the pooled/pooled-lo are inter operable with other processes that use the sequence directly.

The sequence is incremented with the increment_size, that's correct.
In case you are creating the DB schema manually, the sequence must use the same "increment by" as the "increment_size" too.
Hibernate does that when using the hbm2ddl too.


Top
 Profile  
 
 Post subject: Re: Optimizer pooled/-lo not working with increment_size > 1
PostPosted: Fri Jan 15, 2016 1:53 am 
Beginner
Beginner

Joined: Thu Nov 26, 2015 11:40 am
Posts: 33
Thanks Vlad, that really helped.


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