From 7799555bc78d3276d056b9d8d0e55b1e86e146e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 21 Nov 2018 09:11:13 +0100 Subject: [PATCH] HHH-13112 Add a test with an entity in the default package --- .../java/AnnotationMappedNoPackageEntity.java | 35 ++++++++++++++ .../src/test/java/NoPackageTest.java | 48 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 hibernate-core/src/test/java/AnnotationMappedNoPackageEntity.java create mode 100644 hibernate-core/src/test/java/NoPackageTest.java diff --git a/hibernate-core/src/test/java/AnnotationMappedNoPackageEntity.java b/hibernate-core/src/test/java/AnnotationMappedNoPackageEntity.java new file mode 100644 index 0000000000..78bb726afa --- /dev/null +++ b/hibernate-core/src/test/java/AnnotationMappedNoPackageEntity.java @@ -0,0 +1,35 @@ +/* + * 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 . + */ + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class AnnotationMappedNoPackageEntity { + @Id + private Integer id; + + @Basic + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hibernate-core/src/test/java/NoPackageTest.java b/hibernate-core/src/test/java/NoPackageTest.java new file mode 100644 index 0000000000..5c8e20aef3 --- /dev/null +++ b/hibernate-core/src/test/java/NoPackageTest.java @@ -0,0 +1,48 @@ +/* + * 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 http://www.gnu.org/licenses/lgpl-2.1.html + */ + +import org.hibernate.query.Query; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test using an entity which is in no package. + * We had problems with ByteBuddy in the past. + */ +@TestForIssue(jiraKey = "HHH-13112") +public class NoPackageTest extends BaseCoreFunctionalTestCase { + + @Test + public void testNoException() { + inTransaction( session -> { + AnnotationMappedNoPackageEntity box = new AnnotationMappedNoPackageEntity(); + box.setId( 42 ); + box.setName( "This feels dirty" ); + session.persist( box ); + } ); + + inTransaction( session -> { + Query query = session.createQuery( + "select e from " + AnnotationMappedNoPackageEntity.class.getSimpleName() + " e", + AnnotationMappedNoPackageEntity.class + ); + AnnotationMappedNoPackageEntity box = query.getSingleResult(); + assertEquals( (Integer) 42, box.getId() ); + } ); + } + + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + AnnotationMappedNoPackageEntity.class + }; + } +}