Skip to content

Commit 0f20e51

Browse files
committed
HHH-11549 - Ad test for issue
1 parent 893e9e4 commit 0f20e51

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

hibernate-core/src/test/java/org/hibernate/test/version/VersionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.hibernate.Hibernate;
1212
import org.hibernate.Session;
1313
import org.hibernate.Transaction;
14+
15+
import org.hibernate.testing.TestForIssue;
1416
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1517

1618
import static org.junit.Assert.assertEquals;
@@ -55,6 +57,14 @@ public void testVersionShortCircuitFlush() {
5557
t.commit();
5658
s.close();
5759
}
60+
61+
@Test
62+
@TestForIssue( jiraKey = "HHH-11549")
63+
public void testMetamodelContainsHbmVersion() {
64+
try (Session session = openSession()) {
65+
session.getMetamodel().entity( Person.class ).getAttribute( "version" );
66+
}
67+
}
5868

5969
@Test
6070
public void testCollectionVersion() {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.version.mappedsuperclass;
8+
9+
import javax.persistence.MappedSuperclass;
10+
11+
/**
12+
* @author Andrea Boriero
13+
*/
14+
@MappedSuperclass
15+
public class AbstractEntity {
16+
private Long id;
17+
18+
private int version;
19+
20+
public Long getId() {
21+
return id;
22+
}
23+
24+
public void setId(Long id) {
25+
this.id = id;
26+
}
27+
28+
public int getVersion() {
29+
return version;
30+
}
31+
32+
public void setVersion(int version) {
33+
this.version = version;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.version.mappedsuperclass;
8+
9+
import javax.persistence.criteria.CriteriaBuilder;
10+
import javax.persistence.criteria.CriteriaQuery;
11+
import javax.persistence.criteria.Root;
12+
13+
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
14+
15+
import org.hibernate.testing.TestForIssue;
16+
import org.hibernate.testing.transaction.TransactionUtil;
17+
import org.junit.Test;
18+
19+
import static org.hamcrest.CoreMatchers.is;
20+
import static org.hamcrest.CoreMatchers.notNullValue;
21+
import static org.junit.Assert.assertThat;
22+
23+
/**
24+
* @author Andrea Boriero
25+
*/
26+
@TestForIssue(jiraKey = "HHH-11549")
27+
public class HbmMappingMappedSuperclassWithVersionTest extends BaseEntityManagerFunctionalTestCase {
28+
@Override
29+
public String[] getMappings() {
30+
return new String[] {"org/hibernate/test/version/mappedsuperclass/TestEntity.hbm.xml"};
31+
}
32+
33+
@Override
34+
protected Class<?>[] getAnnotatedClasses() {
35+
return new Class[] {AbstractEntity.class};
36+
}
37+
38+
@Test
39+
public void testMetamodelContainsHbmVersion() {
40+
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
41+
final TestEntity entity = new TestEntity();
42+
entity.setName( "Chris" );
43+
entityManager.persist( entity );
44+
} );
45+
46+
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
47+
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
48+
final CriteriaQuery<TestEntity> query = builder.createQuery( TestEntity.class );
49+
final Root<TestEntity> root = query.from( TestEntity.class );
50+
51+
assertThat( root.get( "version" ), is( notNullValue() ) );
52+
} );
53+
}
54+
55+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Hibernate, Relational Persistence for Idiomatic Java
4+
~
5+
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
-->
8+
<!DOCTYPE hibernate-mapping PUBLIC
9+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
10+
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
11+
12+
<!--
13+
Demonstrates how to control the optimistic locking behavior
14+
of a collection (do changes to the collection result in
15+
a version increment on the owning instance)
16+
-->
17+
<hibernate-mapping
18+
package="org.hibernate.test.version.mappedsuperclass">
19+
20+
<class name="TestEntity">
21+
<id name="id">
22+
<generator class="native"/>
23+
</id>
24+
<version name="version" column="`version`"/>
25+
<property name="name"/>
26+
</class>
27+
</hibernate-mapping>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.version.mappedsuperclass;
8+
9+
/**
10+
* @author Andrea Boriero
11+
*/
12+
public class TestEntity extends AbstractEntity {
13+
String name;
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
}

0 commit comments

Comments
 (0)