From 6813d1f488f6b2bba82158740a40f5d0363b415a Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Wed, 20 Feb 2019 17:13:04 -0500 Subject: [PATCH] HHH-13281 - Avoid ClassCastException when unwrapping EntityManager to deprecated org.hibernate.ejb.HibernateEntityManager. --- .../HibernateEntityManagerImplementor.java | 2 +- .../test/jpa/EntityManagerUnwrapTest.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java index 0891f98bd3..2bd4e68d5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/spi/HibernateEntityManagerImplementor.java @@ -15,8 +15,8 @@ import javax.persistence.criteria.Selection; import org.hibernate.HibernateException; import org.hibernate.LockOptions; import org.hibernate.StaleStateException; +import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jpa.HibernateEntityManager; import org.hibernate.query.Query; import org.hibernate.query.criteria.internal.ValueHandlerFactory; import org.hibernate.type.Type; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java new file mode 100644 index 0000000000..9f54b78590 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java @@ -0,0 +1,50 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.jpa; + +import org.hibernate.Session; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + +/** + * @author Chris Cranford + */ +public class EntityManagerUnwrapTest extends BaseEntityManagerFunctionalTestCase { + @Test + @TestForIssue(jiraKey = "HHH-13281") + public void testUnwrapEjbHibernateEntityManagerInterface() { + org.hibernate.ejb.HibernateEntityManager em = getOrCreateEntityManager().unwrap( org.hibernate.ejb.HibernateEntityManager.class ); + } + + @Test + @TestForIssue(jiraKey = "HHH-13281") + public void testUnwrapJpaHibernateEntityManagerInterface() { + org.hibernate.jpa.HibernateEntityManager em = getOrCreateEntityManager().unwrap( org.hibernate.jpa.HibernateEntityManager.class ); + } + + @Test + @TestForIssue(jiraKey = "HHH-13281") + public void testUnwrapSessionImplementor() { + SessionImplementor session = getOrCreateEntityManager().unwrap( SessionImplementor.class ); + } + + @Test + @TestForIssue(jiraKey = "HHH-13281") + public void testUnwrapSession() { + Session session = getOrCreateEntityManager().unwrap( Session.class ); + } + + @Test + @TestForIssue(jiraKey = "HHH-13281") + public void testUnwrapSharedSessionContractImplementor() { + SharedSessionContractImplementor session = getOrCreateEntityManager().unwrap( SharedSessionContractImplementor.class ); + } +}