Skip to content

Commit 4f72f17

Browse files
gbadnersebersole
authored andcommitted
HHH-9937 : Hibernate#isPropertyInitialized always returns true for new enhancer (test case only)
1 parent 716e954 commit 4f72f17

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.bytecode.enhancement;
88

9+
import org.hibernate.test.bytecode.enhancement.lazy.LazyBasicFieldNotInitializedTestTask;
910
import org.hibernate.testing.FailureExpected;
1011
import org.hibernate.testing.TestForIssue;
1112
import org.hibernate.testing.junit4.BaseUnitTestCase;
@@ -72,4 +73,10 @@ public void testHHH3949() {
7273
EnhancerTestUtils.runEnhancerTestTask( HHH3949TestTask4.class );
7374
}
7475

76+
@Test
77+
@TestForIssue( jiraKey = "HHH-9937")
78+
@FailureExpected( jiraKey = "HHH-9937")
79+
public void testLazyBasicFieldNotInitialized() {
80+
EnhancerTestUtils.runEnhancerTestTask( LazyBasicFieldNotInitializedTestTask.class );
81+
}
7582
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.bytecode.enhancement.lazy;
8+
9+
10+
import javax.persistence.Basic;
11+
import javax.persistence.FetchType;
12+
import javax.persistence.GeneratedValue;
13+
import javax.persistence.Id;
14+
15+
import org.hibernate.Hibernate;
16+
import org.hibernate.Session;
17+
import org.hibernate.cfg.Configuration;
18+
import org.hibernate.cfg.Environment;
19+
20+
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
21+
import org.hibernate.test.bytecode.enhancement.EnhancerTestUtils;
22+
import org.junit.Assert;
23+
24+
/**
25+
* @author Gail Badner
26+
*/
27+
public class LazyBasicFieldNotInitializedTestTask extends AbstractEnhancerTestTask {
28+
29+
private Long entityId;
30+
31+
public Class<?>[] getAnnotatedClasses() {
32+
return new Class<?>[] {Entity.class};
33+
}
34+
35+
public void prepare() {
36+
Configuration cfg = new Configuration();
37+
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
38+
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
39+
super.prepare( cfg );
40+
41+
Session s = getFactory().openSession();
42+
s.beginTransaction();
43+
44+
Entity entity = new Entity();
45+
entity.setDescription( "desc" );
46+
s.persist( entity );
47+
entityId = entity.getId();
48+
49+
s.getTransaction().commit();
50+
s.clear();
51+
s.close();
52+
}
53+
54+
public void execute() {
55+
Session s = getFactory().openSession();
56+
s.beginTransaction();
57+
Entity entity = s.get( Entity.class, entityId );
58+
Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
59+
s.getTransaction().commit();
60+
s.close();
61+
}
62+
63+
protected void cleanup() {
64+
}
65+
66+
@javax.persistence.Entity
67+
public static class Entity {
68+
@Id
69+
@GeneratedValue
70+
private Long id;
71+
72+
@Basic(fetch = FetchType.LAZY)
73+
private String description;
74+
75+
public Long getId() {
76+
return id;
77+
}
78+
79+
public void setId(Long id) {
80+
this.id = id;
81+
}
82+
83+
public String getDescription() {
84+
return description;
85+
}
86+
87+
public void setDescription(String description) {
88+
this.description = description;
89+
}
90+
}
91+
92+
93+
}

0 commit comments

Comments
 (0)