-
1. Re: Hibernate sequence generator not working as expected
smarlow Jan 19, 2015 10:07 AM (in response to valsaraj007)1 of 1 people found this helpfulRead about the Hibernate settings that might be important related to your issue here https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-Hibernateproperties
By default, JPA applications will deploy with hibernate.id.new_generator_mappings=true, while pure Hibernate applications will deploy with hibernate.id.new_generator_mappings=false.
Quoting from the above:
In Hibernate 4.x, if new_generator_mappings is true:
- @GeneratedValue(AUTO) maps to org.hibernate.id.enhanced.SequenceStyleGenerator
- @GeneratedValue(TABLE) maps to org.hibernate.id.enhanced.TableGenerator
- @GeneratedValue(SEQUENCE) maps to org.hibernate.id.enhanced.SequenceStyleGenerator
In Hibernate 4.x, if new_generator_mappings is false:
- @GeneratedValue(AUTO) maps to Hibernate "native"
- @GeneratedValue(TABLE) maps to org.hibernate.id.MultipleHiLoPerTableGenerator
- @GeneratedValue(SEQUENCE) to Hibernate "seqhilo"
In summary, I think that you used to use org.hibernate.id.MultipleHiLoPerTableGenerator (for TABLE) and now are getting org.hibernate.id.enhanced.TableGenerator. You could try setting hibernate.id.new_generator_mappings=false in your persistence.xml (as a persistence unit property).
Scott
-
2. Re: Hibernate sequence generator not working as expected
valsaraj007 Jan 20, 2015 1:18 AM (in response to smarlow)Hi Scott,
Here is the persistence.xml file of my JPA application:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="em" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/AppDS</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.show_sql" value="false"></property>
<property name="hibernate.hbm2ddl.auto" value="update"></property>
</properties>
</persistence-unit>
</persistence>
Should I add setting hibernate.id.new_generator_mappings=false here?
Thanks!
-
3. Re: Re: Hibernate sequence generator not working as expected
smarlow Jan 20, 2015 11:14 AM (in response to valsaraj007)Yes, here is an example that you could try.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="em" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/AppDS</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.show_sql" value="false"></property>
<property name="hibernate.id.new_generator_mappings" value="false"></property>
<property name="hibernate.hbm2ddl.auto" value="update"></property>
</properties>
</persistence-unit>
</persistence>
-
4. Re: Hibernate sequence generator not working as expected
valsaraj007 Apr 28, 2017 5:52 AM (in response to smarlow)Hi Scott,
I checked this in WildFly 10.1. It is working fine with hibernate.id.new_generator_mappings=false but there is warning in log.
HHH90000015: Found use of deprecated [org.hibernate.id.MultipleHiLoPerTableGenerator] table-based id generator; use org.hibernate.id.enhanced.TableGenerator instead.
See Hibernate Domain Model Mapping Guide for details.
...
2017-04-27 17:52:01,422 WARN [org.hibernate.orm.deprecation] (ServerService Thread Pool -- 76)
HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.
See Hibernate Domain Model Mapping Guide for details.
When I set hibernate.id.new_generator_mappings=true, warning disappeared but the table id generated is not as in previous order. It's creating id with negative values.
Any option to solve this?
Thanks!