I have a unique Oracle sequence in my schema, used to draw primary keys for several tables. I mapped this scenario to JPA/Hibernate by declare a @SequenceGenerator on a package-info.java so that it's available for the whole persistence-unit, then my entities reference the generator by name using @GeneratedValue
I'm using an allocationSize=100 with the enhanced generators and pooled-lo optimizer.
It seems that Hibernate actually creates an instance of SequenceStyleGenerator for each entity, so that in the end when 2 different entities are inserted, 2 DB calls are made instead of one because there are 2 instances of the PooledLoOptimizer.
The same java code run with EclipseLink actually shares the generator : the DB is accessed only once.
Is there a way to share generator instances with Hibernate ? It seems that it was not the case back in 2007 (see this post https://forum.hibernate.org/viewtopic.php?f=9&t=969596&hilit=shared+sequence ), what about now with 4.2 ?
|