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 + }; + } +}