We're updating the issue view to help you get more done. 

Duplicate PersistenceProvider registration

Description

I've noticed a bug in the

javax.persistence.spi.PersistenceProviderResolverHolder.PersistenceProviderResolverPerClassLoader

Class which results in two instances of the

org.hibernate.jpa.HibernatePersistenceProvider

to be available at runtime (as well as the deprecated ejb instance, which is always move to first position).

I've highlighted the lines which cause the problem Persistence Proivder

During execution under Java 7, the implementation of hash set results in an iteration over the list of providers in the META-INF/services file which has the org.hibernate.ejb.HibernatePersistence first, which avoid the bug.

In Java 8 this order has changed and results in the org.hibernate.jpa.HibernatePersistenceProvider being the first item in the iterator.

The duplicate is added if the org.hibernate.jpa.HibernatePersistenceProvider is the first element in the iterator, as this then passes the condition to manage the org.hibernate.ejb.HibernatePersistence to be first in the list. This is where the extra is added, as all that is needed to complete correctly and force the ejb version to be first is line 148. Line 149 adds a copy of the binding previously at position 0 at the end of the list. Lines 147 & 149 should be removed to resolve the problem.

Environment

Java 8, Hibernate 4.3.6.Final, jpa-2.1-1.0.0

Status

Assignee

Unassigned

Reporter

Matt Todd

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major