[forge-dev] @GeneratedValue Strategy
Thomas Frühbeck
fruehbeck at aon.at
Sat May 5 06:15:00 EDT 2012
Just for the records, TWIMC :-)
I really was surprised to find this behavior of hibernate generating a
"hibernate_sequence" on MySQL, where the autoincrement is IMHO the most
simple and elegant way to create/use a technical primary key - which is
in the end the reason for the initially desribed behavior of the
incrementing id from Ryan.
(Similar to the discussion on "Serializeable not getting a default
serialVersionUID" the question is: should a tool like Forge provide a
functional core to build on or should it "evangelize" a certain -
debatable - implementation practice.)
In this case the reason for the discussed behavior is the new
AnnotationMapping introduced in Hibernate.
See: 5.1.2.2. Identifier generator in
http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/mapping.html
private static String generatorType(GenerationType generatorEnum,
Mappings mappings) {
boolean useNewGeneratorMappings =
mappings.useNewGeneratorMappings();
switch ( generatorEnum ) {
case IDENTITY:
return "identity";
case AUTO:
return useNewGeneratorMappings
?
org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName()
: "native";
The old mapping "native" would have been the mapping causing the use of
"auto_increment", if available.
So there would be two possibilities to react to the issue per default:
- place a property in persistence.xml:
<property name="hibernate.id.new_generator_mappings" value="false"/>
- set GenerationType.IDENTITY per default
thus excluding technically Databases not supporting autoincrement
Unfortunately both are not really attractive :-/
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20120505/99fd0617/attachment.html
More information about the forge-dev
mailing list