-
15. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
simas_ch Nov 1, 2011 6:21 PM (in response to sebersole)@Steve
IDENTITY works perfectly with MySQL auto_increment and Hibernate.
Hibernate executes the INSERT on EntityManager.persist() so the ID is available.
-
16. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
sebersole Nov 1, 2011 6:26 PM (in response to simas_ch)As the lead developer of Hibernate, yes I understand it works But I understand when it does and when it does not. Please read ALL of my reply, thanks.
-
17. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
smarlow Nov 1, 2011 11:30 PM (in response to smarlow)I'll create the jira for allowing hibernate.id.new_generator_mappings=false to be specified as a property in the persistence.xml.
-
18. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
smarlow Nov 1, 2011 11:56 PM (in response to smarlow)Created AS7-2460 which was inspired by this thread.
-
19. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
sebersole Nov 2, 2011 12:16 AM (in response to smarlow)Just to be clear... Personally I do not see AS7-2460 as the "solution" to this discussion. AS7-2460 is just about giving AS7 users the ability to override the "hibernate.id.new_generator_mappings" setting. But that just reverts Hibernate to its legacy behavior, which was changed for a reason. We needed to allow specifying "hibernate.id.new_generator_mappings" to allow for backwards compatibility for pre-existing applications.
For new applications, specifying true for hibernate.id.new_generator_mappings (the default in AS7) is definitely the recommended set up.
What Ove would be more interested in is a RFE against Hibernate itself to allow users to request that Hibernate create a sequence per entity in the case when no explicit sequence name is given. Basically a org.hibernate.id.enhanced.SequenceStyleGenerator corollary to the org.hibernate.id.enhanced.TableGenerator#CONFIG_PREFER_SEGMENT_PER_ENTITY setting. That RFE has not been created yet afaik.
-
20. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
sebersole Nov 2, 2011 12:19 AM (in response to oranheim)Ove, another thing you might want to ask yourself is why you care that there is a single sequence instead of one per entity. I have worked on huge systems in the past where this was the case and never had issues with running out of values.
-
21. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
sebersole Nov 2, 2011 12:49 AM (in response to sebersole)Here is that Hibernate RFE...
-
22. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
oranheim Nov 13, 2011 5:11 AM (in response to sebersole)Hi Steve,
I try to override the SequenceStyleGenerator and use it in my root entity. What I do not understand is how to reference or register the custom SequenceStyleGenerator? The @SequenceGenerator maps with default SequenceStyleGenerator, doesn't it?
My goal would then be to override method SequenceStyleGenerator#determineSequenceName and use the declaring class name as a sequenceName.
-
23. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
oranheim Nov 13, 2011 5:40 AM (in response to oranheim)Steve,
Thanks for the suggested solution! My question above is sorted
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PARTS_ID") @GenericGenerator(name="PARTS_ID", strategy="com.parts.commons.model.PartsSequenceStyleGenerator")
It all sorts out by resolving passed parameter 'entity_name' #determineSequenceName(..)
Thanks,
Ove
-
24. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
newway Apr 4, 2012 10:28 AM (in response to sebersole)Steve,
I'm kind off piggy backing on this thread, but after encountering an issue that was solved by setting hibernate.id.new_generator_mappings=false i was wondering if someone can direct me to the place that explains why in AS 7 the out off the box value is true, while Hibernate documentation says that the value is false for reasons of backsword computability.
I didn't explore the new behavior much, but I did need to migrate code from 4.2.3 and setting the value to false kept me with the behavior I expected.
Did is just a question for academic knowledge.
thanks,
Noa
-
25. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
sebersole Apr 4, 2012 10:38 AM (in response to newway)Libraries always need to allow for backwards compatibility (at least for some period of time). That is the only purpose of (a) having ' hibernate.id.new_generator_mappings' and (b) allowing ' hibernate.id.new_generator_mappings' to be false. Otherwise, these improvements in how identifier generation happen would cause problems with older applications that used Hibernate before those improvements were in place.
But, they are called improvements for a reason...
-
26. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
smarlow Apr 4, 2012 11:24 AM (in response to newway)I just added some notes here about the properties that AS automatically adds to the persistence unit.
-
27. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)
newway Apr 4, 2012 11:27 AM (in response to sebersole)Thanks, I have some time constraints so I can't look into it right now - but I will explore the issue more once I have the chance