HHH-11549 - Ad test for issue

This commit is contained in:
Andrea Boriero 2017-03-07 10:28:51 +00:00
parent 893e9e45c8
commit 0f20e51a5e
5 changed files with 149 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
@ -55,6 +57,14 @@ public class VersionTest extends BaseCoreFunctionalTestCase {
t.commit();
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-11549")
public void testMetamodelContainsHbmVersion() {
try (Session session = openSession()) {
session.getMetamodel().entity( Person.class ).getAttribute( "version" );
}
}
@Test
public void testCollectionVersion() {

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>.
*/
package org.hibernate.test.version.mappedsuperclass;
import javax.persistence.MappedSuperclass;
/**
* @author Andrea Boriero
*/
@MappedSuperclass
public class AbstractEntity {
private Long id;
private int version;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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>.
*/
package org.hibernate.test.version.mappedsuperclass;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-11549")
public class HbmMappingMappedSuperclassWithVersionTest extends BaseEntityManagerFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] {"org/hibernate/test/version/mappedsuperclass/TestEntity.hbm.xml"};
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {AbstractEntity.class};
}
@Test
public void testMetamodelContainsHbmVersion() {
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
final TestEntity entity = new TestEntity();
entity.setName( "Chris" );
entityManager.persist( entity );
} );
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<TestEntity> query = builder.createQuery( TestEntity.class );
final Root<TestEntity> root = query.from( TestEntity.class );
assertThat( root.get( "version" ), is( notNullValue() ) );
} );
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
~ 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>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!--
Demonstrates how to control the optimistic locking behavior
of a collection (do changes to the collection result in
a version increment on the owning instance)
-->
<hibernate-mapping
package="org.hibernate.test.version.mappedsuperclass">
<class name="TestEntity">
<id name="id">
<generator class="native"/>
</id>
<version name="version" column="`version`"/>
<property name="name"/>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,22 @@
/*
* 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>.
*/
package org.hibernate.test.version.mappedsuperclass;
/**
* @author Andrea Boriero
*/
public class TestEntity extends AbstractEntity {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}