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