[hibernate-dev] Make HibernatePersistenceProvider easier to extend

Sanne Grinovero sanne at hibernate.org
Wed Mar 19 09:54:15 EDT 2014

Hi Guillaume,
looks like a good idea to me, but my advice would be to make all the
changes and send a pull request: would make it easier to reason about
the implications.

You should either see it "just gets merged", os get some more concrete

Such an approach might make you occasionally code something which
doesn't get included, but it's rare to hit and actual deal breaker and
I'd argue it's never entirely a waste of time to play with
refactorings and iterate multiple times. We all learn from it.


On 19 March 2014 11:10, Guillaume Smet <guillaume.smet at hibernate.org> wrote:
> Hi,
> Any thoughts on this one?
> I have bandwidth this week if it's considered something we want.
> Thanks.
> On Thu, Jan 23, 2014 at 2:08 PM, Guillaume Smet
> <guillaume.smet at gmail.com> wrote:
>> Hi,
>> I'm starting our migration to ORM 4.3 to be able to provide some
>> (hopefully useful) feedback on ORM 4.3 and Search 4.5.
>> One thing we did in most of our apps was injecting Spring managed
>> interceptor into the session factory using a trick very similar to
>> what is explained there:
>> http://blog.krecan.net/2009/01/24/spring-managed-hibernate-interceptor-in-jpa/.
>> This (kinda ugly) trick doesn't work any more in 4.3 and I ended up
>> doing the following:
>> https://gist.github.com/gsmet/8578138
>> which works but is IMHO very fragile as I only changed one
>> initialization method and if I would have liked to change them all, I
>> would have to duplicate a lot of code.
>> Would it be possible to create a protected method which centralizes
>> the call to Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit,
>> integration, providedClassLoader ); call we could override easily?
>> See:
>> https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java#L129
>> https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java#L150
>> https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java#L157
>> This way I could simply override this method to return a different
>> EntityManagerFactoryBuilder aware of my interceptor for every way to
>> initialize an EntityManagerFactory.
>> And minor nitpicking, I think the wrap method should be protected as
>> it's used in a protected method we might want to tweak without having
>> to implement this method again. see
>> https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java#L137
>> I can open a Jira issue and do the work if you agree there is
>> something to fix and we come up with a plan (and a clever method
>> name).
>> Thanks for your feedback.
>> --
>> Guillaume
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev

More information about the hibernate-dev mailing list