1 2 Previous Next 27 Replies Latest reply on Apr 4, 2012 11:27 AM by newway Go to original post
      • 15. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)


        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)

          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)

            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)

              Created AS7-2460 which was inspired by this thread.

              • 19. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)

                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)

                  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)

                    Here is that Hibernate RFE...

                    • 22. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)

                      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)



                        Thanks for the suggested solution! My question above is sorted



                        @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(..)




                        • 24. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)



                          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.




                          • 25. Re: AS7 has wrong behavior for @GeneratedValue(AUTO)

                            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)

                              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)

                                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

                                1 2 Previous Next