-->
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.  [ 1 post ] 
Author Message
 Post subject: Question on behaviour of @TableGenerator
PostPosted: Fri Oct 19, 2007 12:28 pm 
Newbie

Joined: Fri Oct 12, 2007 5:18 pm
Posts: 10
Hi,

I have a question about the behaviour of the @TableGenerator. I will start by describing the behaviour that I want to achieve and then I will talk about the behaviour I observed.

I would like to have the same behaviour as having a single database sequence to generate all my IDs, with an increment of 1. The reason I don't use a sequence is because I want to make the application portable to RDBMS's that don't support sequences. The reason I don't use an allocationSize of 1 is because I don't want to hit the database for every new ID.

So, I started by using a single table generator definition used by all my entities with the default allocationSize of 50. Unfortunately, this setup doesn't achieve the desired behaviour. Let's say the server has just been restarted. A first request comes in and in the business logic that is invoked, 5 different new entities are created. When the flush occurs, I noticed that for each entity, the MultipleHiLoPerTableGenerator asks for a new hi value. I would have expected that only the creation of the first entity would request a new hi value and the creation of the other 4 entities would have continued from there. By digging a little bit, I realized that since each entity persister has its own instance of the table generator, the lo value is local to an entity persister, not to the whole application. The end result is that for a particular entity, whenever the server starts or the lo value is greater than the allocationSize, the id will suddenly jump by "number of entities in my system * allocationSize". It's not that big of a problem but still not what I expected.

My question is: is this a bug in Hibernate or the desired behaviour or a bug with my table generator configuration?

Here's what I configured in my orm.xml file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
        http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0">

    <table-generator name="moxxiTableGenerator" table="ID_GENERATOR" pk-column-name="GENERATOR_NAME"
                     pk-column-value="MOXXI_ID_GENERATOR" value-column-name="GENERATOR_COUNTER"/>
</entity-mappings>


Thanks a lot for your input.

Hibernate Core version: 3.2.5
Hibernate Entity Manager version: 3.3.1
Hibernate Annotations version: 3.3.0


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.