HHH-15634 Fix naming of LazyBasicFieldAccessTest/LazyBasicPropertyAccessTest
For some reason they were reversed.
This commit is contained in:
parent
9bd269aa5d
commit
66daac53a2
|
@ -16,6 +16,8 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import jakarta.persistence.Access;
|
||||||
|
import jakarta.persistence.AccessType;
|
||||||
import jakarta.persistence.Basic;
|
import jakarta.persistence.Basic;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
|
@ -36,6 +38,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
|
public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
private LazyEntity entity;
|
private LazyEntity entity;
|
||||||
|
|
||||||
private Long entityId;
|
private Long entityId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,82 +56,69 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
LazyEntity entity = new LazyEntity();
|
LazyEntity entity = new LazyEntity();
|
||||||
entity.setDescription( "desc" );
|
entity.description = "desc";
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
entityId = entity.id;
|
entityId = entity.id;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void execute() {
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity = s.get( LazyEntity.class, entityId );
|
entity = s.get( LazyEntity.class, entityId );
|
||||||
|
|
||||||
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( entity );
|
checkDirtyTracking( entity );
|
||||||
|
|
||||||
assertEquals( "desc", entity.getDescription() );
|
assertEquals( "desc", entity.description );
|
||||||
assertTrue( isPropertyInitialized( entity, "description" ) );
|
assertTrue( isPropertyInitialized( entity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity.setDescription( "desc1" );
|
entity.description = "desc1";
|
||||||
s.update( entity );
|
s.update( entity );
|
||||||
|
|
||||||
//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
// Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( entity, "description" );
|
checkDirtyTracking( entity, "description" );
|
||||||
|
|
||||||
assertEquals( "desc1", entity.getDescription() );
|
assertEquals( "desc1", entity.description );
|
||||||
assertTrue( isPropertyInitialized( entity, "description" ) );
|
assertTrue( isPropertyInitialized( entity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity = s.get( LazyEntity.class, entityId );
|
entity = s.get( LazyEntity.class, entityId );
|
||||||
assertEquals( "desc1", entity.getDescription() );
|
assertEquals( "desc1", entity.description );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity.setDescription( "desc2" );
|
entity.description = "desc2";
|
||||||
LazyEntity mergedEntity = (LazyEntity) s.merge( entity );
|
LazyEntity mergedEntity = (LazyEntity) s.merge( entity );
|
||||||
|
|
||||||
// Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( mergedEntity, "description" );
|
checkDirtyTracking( mergedEntity, "description" );
|
||||||
|
|
||||||
assertEquals( "desc2", mergedEntity.getDescription() );
|
assertEquals( "desc2", mergedEntity.description );
|
||||||
assertTrue( isPropertyInitialized( mergedEntity, "description" ) );
|
assertTrue( isPropertyInitialized( mergedEntity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
LazyEntity entity = s.get( LazyEntity.class, entityId );
|
LazyEntity entity = s.get( LazyEntity.class, entityId );
|
||||||
assertEquals( "desc2", entity.getDescription() );
|
assertEquals( "desc2", entity.description );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- //
|
// --- //
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "LAZY_FIELD_ENTITY" )
|
@Access( AccessType.FIELD )
|
||||||
|
@Table( name = "LAZY_PROPERTY_ENTITY" )
|
||||||
private static class LazyEntity {
|
private static class LazyEntity {
|
||||||
Long id;
|
|
||||||
String description;
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
Long getId() {
|
Long id;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Basic( fetch = FetchType.LAZY )
|
@Basic( fetch = FetchType.LAZY )
|
||||||
String getDescription() {
|
String description;
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import jakarta.persistence.Access;
|
|
||||||
import jakarta.persistence.AccessType;
|
|
||||||
import jakarta.persistence.Basic;
|
import jakarta.persistence.Basic;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
|
@ -38,7 +36,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
|
public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
private LazyEntity entity;
|
private LazyEntity entity;
|
||||||
|
|
||||||
private Long entityId;
|
private Long entityId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,69 +53,82 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
|
||||||
public void prepare() {
|
public void prepare() {
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
LazyEntity entity = new LazyEntity();
|
LazyEntity entity = new LazyEntity();
|
||||||
entity.description = "desc";
|
entity.setDescription( "desc" );
|
||||||
s.persist( entity );
|
s.persist( entity );
|
||||||
entityId = entity.id;
|
entityId = entity.getId();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void execute() {
|
public void test() {
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity = s.get( LazyEntity.class, entityId );
|
entity = s.get( LazyEntity.class, entityId );
|
||||||
|
|
||||||
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( entity );
|
checkDirtyTracking( entity );
|
||||||
|
|
||||||
assertEquals( "desc", entity.description );
|
assertEquals( "desc", entity.getDescription() );
|
||||||
assertTrue( isPropertyInitialized( entity, "description" ) );
|
assertTrue( isPropertyInitialized( entity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity.description = "desc1";
|
entity.setDescription( "desc1" );
|
||||||
s.update( entity );
|
s.update( entity );
|
||||||
|
|
||||||
// Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( entity, "description" );
|
checkDirtyTracking( entity, "description" );
|
||||||
|
|
||||||
assertEquals( "desc1", entity.description );
|
assertEquals( "desc1", entity.getDescription() );
|
||||||
assertTrue( isPropertyInitialized( entity, "description" ) );
|
assertTrue( isPropertyInitialized( entity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity = s.get( LazyEntity.class, entityId );
|
entity = s.get( LazyEntity.class, entityId );
|
||||||
assertEquals( "desc1", entity.description );
|
assertEquals( "desc1", entity.getDescription() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
entity.description = "desc2";
|
entity.setDescription( "desc2" );
|
||||||
LazyEntity mergedEntity = (LazyEntity) s.merge( entity );
|
LazyEntity mergedEntity = (LazyEntity) s.merge( entity );
|
||||||
|
|
||||||
//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
|
// Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
|
||||||
checkDirtyTracking( mergedEntity, "description" );
|
checkDirtyTracking( mergedEntity, "description" );
|
||||||
|
|
||||||
assertEquals( "desc2", mergedEntity.description );
|
assertEquals( "desc2", mergedEntity.getDescription() );
|
||||||
assertTrue( isPropertyInitialized( mergedEntity, "description" ) );
|
assertTrue( isPropertyInitialized( mergedEntity, "description" ) );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
doInHibernate( this::sessionFactory, s -> {
|
doInHibernate( this::sessionFactory, s -> {
|
||||||
LazyEntity entity = s.get( LazyEntity.class, entityId );
|
LazyEntity entity = s.get( LazyEntity.class, entityId );
|
||||||
assertEquals( "desc2", entity.description );
|
assertEquals( "desc2", entity.getDescription() );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- //
|
// --- //
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Access( AccessType.FIELD )
|
@Table( name = "LAZY_FIELD_ENTITY" )
|
||||||
@Table( name = "LAZY_PROPERTY_ENTITY" )
|
|
||||||
private static class LazyEntity {
|
private static class LazyEntity {
|
||||||
|
Long id;
|
||||||
|
String description;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
Long id;
|
Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
@Basic( fetch = FetchType.LAZY )
|
@Basic( fetch = FetchType.LAZY )
|
||||||
String description;
|
String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue