-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-14571 Test that the identifier is always reported as initialized …
…by Hibernate.isPropertyInitialized when using enhanced proxies
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...rc/test/java/org/hibernate/test/bytecode/enhancement/lazy/IdInUninitializedProxyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.bytecode.enhancement.lazy; | ||
|
||
import javax.persistence.Basic; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.Hibernate; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.cfg.AvailableSettings; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; | ||
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; | ||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@TestForIssue(jiraKey = "HHH-14571") | ||
@RunWith(BytecodeEnhancerRunner.class) | ||
@EnhancementOptions(lazyLoading = true, extendedEnhancement = true) | ||
public class IdInUninitializedProxyTest extends BaseNonConfigCoreFunctionalTestCase { | ||
|
||
@Override | ||
protected Class[] getAnnotatedClasses() { | ||
return new Class[] { AnEntity.class }; | ||
} | ||
|
||
@Override | ||
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) { | ||
super.configureStandardServiceRegistryBuilder( ssrb ); | ||
ssrb.applySetting( AvailableSettings.ALLOW_ENHANCEMENT_AS_PROXY, true ); | ||
} | ||
|
||
@Test | ||
public void testIdIsAlwaysConsideredInitialized() { | ||
inTransaction( session -> { | ||
final AnEntity e = session.byId( AnEntity.class ).getReference( 1 ); | ||
assertFalse( Hibernate.isInitialized( e ) ); | ||
// This is the gist of the problem | ||
assertTrue( Hibernate.isPropertyInitialized( e, "id" ) ); | ||
assertFalse( Hibernate.isPropertyInitialized( e, "name" ) ); | ||
|
||
assertEquals( "George", e.name ); | ||
assertTrue( Hibernate.isInitialized( e ) ); | ||
assertTrue( Hibernate.isPropertyInitialized( e, "id" ) ); | ||
assertTrue( Hibernate.isPropertyInitialized( e, "name" ) ); | ||
} ); | ||
} | ||
|
||
@Before | ||
public void prepareTestData() { | ||
inTransaction( session -> { | ||
AnEntity anEntity = new AnEntity(); | ||
anEntity.id = 1; | ||
anEntity.name = "George"; | ||
session.persist( anEntity ); | ||
} ); | ||
} | ||
|
||
@Entity(name = "AnEntity") | ||
public static class AnEntity { | ||
@Id | ||
private int id; | ||
|
||
@Basic | ||
private String name; | ||
} | ||
|
||
} |