Skip to content

Instantly share code, notes, and snippets.

@scottmarlow
Created April 30, 2012 15:00
Show Gist options
  • Select an option

  • Save scottmarlow/2559042 to your computer and use it in GitHub Desktop.

Select an option

Save scottmarlow/2559042 to your computer and use it in GitHub Desktop.
hibernate.id.new_generator_mappings
If you use the @GeneratedValue(AUTO) annotation in your applications, you are using the default strategy for generating unique index values. For applications that you are migrating to JBoss Enterprise Application Platform 6, changes should be considered before deploying with the @GeneratedValue(AUTO) annotation. New applications that use the @GeneratedValue(AUTO) annotation, should set the hibernate.id.new_generator_mappings property to true.
Setting the hibernate.id.new_generator_mappings property to true, is the preferred behavior. It is more efficient and closer to the JPA 2 specification. But for existing applications, care must be taken to ensure that newly created entities, use the same generator as was previously used with the application.
When JPA applications are deployed on JBoss Enterprise Application Platform 6, the hibernate.id.new_generator_mappings property defaults to true.
When Hibernate applications are deployed on JBoss Enterprise Application Platform 6, the hibernate.id.new_generator_mappings property defaults to false. If there is not existing entities created in the database yet, consider changing hibernate.id.new_generator_mappings to true. Applications that package the Hibernate jars will need to also consider setting hibernate.id.new_generator_mappings to true, if using Hibernate 3.5.x or newer.
For more information about these property settings, see Hibernate JPA Persistence Unit Properties.
Related Tasks
Update Your Hibernate 3 Application to Use Hibernate 4
Thank you for evaluating the new documentation format for JBoss Enterprise Application Platform. Let us know what you think by taking a short survey.
@sgilda

sgilda commented Apr 30, 2012

Copy link
Copy Markdown

I can't edit this. There's no "edit" button. Here's my revised version:

1.1. Preserve the Existing Behavior of the Hibernate Identity Auto Generated Value

Hibernate 3.5 introduced a core property named hibernate.id.new_generator_mappings that directs how identity or sequence fields are generated when using @GeneratedValue. In JBoss Enterprise Application Platform 6, the default value for this property is as follows:

*
  When you deploy a native Hibernate application, the default value is false.
*
  When you deploy a JPA application, the default value is true. 

Guidelines for New Applications
New applications that use the @GeneratedValue(AUTO) annotation should set the value for the hibernate.id.new_generator_mappings property to true. This is the intended and preferred behavior because it is more efficient and closer to the JPA 2 specification.

*
  For new JPA applications, the setting for this property should be true by default.
*
  For new native Hibernate applications, the setting for this property is false and should be changed to true. 

Guidelines for Existing JBoss Enterprise Application Platform 5 Applications
Existing applications that use the @GeneratedValue(AUTO) annotation must make sure that the same generator is used to create new entities when the application is migrated to JBoss Enterprise Application Platform 6, otherwise the change in behavior can result in indexing problems.

*
  For existing JPA applications, the setting for the hibernate.id.new_generator_mappings property is true and should be changed to false..
*
  For existing native Hibernate applications, the setting for the hibernate.id.new_generator_mappings should be false by default. 

The behaviors of @GeneratedValue(TABLE) and @GeneratedValue(SEQUENCE) annotations may also be affected when migrating to JBoss Enterprise Application Platform 6. For more information about these property settings, see Hibernate JPA Persistence Unit Properties.

@sgilda

sgilda commented Apr 30, 2012

Copy link
Copy Markdown

1.1. Preserve the Existing Behavior of the Hibernate Identity Auto Generated Value
Hibernate 3.5 introduced a core property named hibernate.id.new_generator_mappings that directs how identity or sequence columns are generated when using @GeneratedValue. In JBoss Enterprise Application Platform 6, the default value for this property is as follows:

*
  When you deploy a native Hibernate application, the default value is false.
*
  When you deploy a JPA application, the default value is true. 

Guidelines for New Applications
New applications that use the @GeneratedValue(AUTO) annotation should set the value for the hibernate.id.new_generator_mappings property to true. This is the intended and preferred behavior because it is more efficient and closer to the JPA 2 specification.

*
  For new JPA applications, the setting for this property should be true by default.
*
  For new native Hibernate applications, the default setting for this property is false and should be changed to true. 

Guidelines for Existing JBoss Enterprise Application Platform 5 Applications
Existing applications that use the @GeneratedValue(AUTO) annotation should make sure that the same generator is used to create unique index values for new entities when the application is migrated to JBoss Enterprise Application Platform 6.

*
  For existing JPA applications, the default setting for the hibernate.id.new_generator_mappings property is true and should be changed to false.
*
  For existing native Hibernate applications, the setting for the hibernate.id.new_generator_mappings should be false by default. 

The behaviors of @GeneratedValue(TABLE) and @GeneratedValue(SEQUENCE) annotations may also be affected when migrating to JBoss Enterprise Application Platform 6. For more information about these property settings, see Hibernate JPA Persistence Unit Properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment