HHH-13112 Add a test with an entity in the default package

This commit is contained in:
Yoann Rodière 2018-11-21 09:11:13 +01:00 committed by gbadner
parent e86a7a43d9
commit 2c60c8d2a0
2 changed files with 83 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}

View File

@ -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<AnnotationMappedNoPackageEntity> 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
};
}
}