Convert bytecodeenhanced tests to use JUnit 5 extensions

This commit is contained in:
marko-bekhta 2024-04-05 16:34:11 +02:00 committed by Steve Ebersole
parent 85364a2c53
commit 19e495d8da
269 changed files with 9893 additions and 9621 deletions

View File

@ -6,82 +6,74 @@
*/ */
package org.hibernate.orm.test.annotations.collectionelement.recreate; package org.hibernate.orm.test.annotations.collectionelement.recreate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.annotations.collectionelement.recreate.BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest.MyEntity;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.After; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OrderColumn; import jakarta.persistence.OrderColumn;
import static org.assertj.core.api.Assertions.assertThat; @DomainModel(
import static org.junit.Assert.assertTrue; annotatedClasses = {
MyEntity.class,
@RunWith(BytecodeEnhancerRunner.class) }
)
@SessionFactory
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
@EnhancementOptions(lazyLoading = true) @EnhancementOptions(lazyLoading = true)
@TestForIssue(jiraKey = "HHH-14387") @JiraKey("HHH-14387")
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest {
extends BaseNonConfigCoreFunctionalTestCase {
@Override @BeforeEach
protected Class[] getAnnotatedClasses() { public void check(SessionFactoryScope scope) {
return new Class[] { scope.inSession(
MyEntity.class
};
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( true );
}
@Before
public void check() {
inSession(
session -> session ->
assertTrue( session.getSessionFactory().getSessionFactoryOptions() assertTrue( session.getSessionFactory().getSessionFactoryOptions()
.isCollectionsInDefaultFetchGroupEnabled() ) .isCollectionsInDefaultFetchGroupEnabled() )
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session ->
session.createQuery( "delete from myentity" ).executeUpdate() session.createQuery( "delete from myentity" ).executeUpdate()
); );
} }
@Test @Test
public void testRecreateCollection() { public void testRecreateCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -89,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testRecreateCollectionFind() { public void testRecreateCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -111,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testDeleteCollection() { public void testDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -132,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testDeleteCollectionFind() { public void testDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -153,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollection() { public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.get( MyEntity.class, 1 ) session.get( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );
@ -174,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() { public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.find( MyEntity.class, 1 ) session.find( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );

View File

@ -6,80 +6,73 @@
*/ */
package org.hibernate.orm.test.annotations.collectionelement.recreate; package org.hibernate.orm.test.annotations.collectionelement.recreate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.annotations.collectionelement.recreate.BytecodeEnhancementElementCollectionRecreateTest.MyEntity;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.After; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OrderColumn; import jakarta.persistence.OrderColumn;
import static org.assertj.core.api.Assertions.assertThat; @DomainModel(
import static org.junit.Assert.assertFalse; annotatedClasses = {
MyEntity.class,
@RunWith(BytecodeEnhancerRunner.class) }
)
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
@EnhancementOptions(lazyLoading = true) @EnhancementOptions(lazyLoading = true)
@TestForIssue(jiraKey = "HHH-14387") @JiraKey("HHH-14387")
public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonConfigCoreFunctionalTestCase { public class BytecodeEnhancementElementCollectionRecreateTest {
@Override @BeforeEach
protected Class[] getAnnotatedClasses() { public void check(SessionFactoryScope scope) {
return new Class[] { scope.inSession(
MyEntity.class
};
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( false );
}
@Before
public void check() {
inSession(
session -> session ->
assertFalse( session.getSessionFactory().getSessionFactoryOptions() assertFalse( session.getSessionFactory().getSessionFactoryOptions()
.isCollectionsInDefaultFetchGroupEnabled() ) .isCollectionsInDefaultFetchGroupEnabled() )
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session ->
session.createQuery( "delete from myentity" ).executeUpdate() session.createQuery( "delete from myentity" ).executeUpdate()
); );
} }
@Test @Test
public void testRecreateCollection() { public void testRecreateCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -87,21 +80,21 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testRecreateCollectionFind() { public void testRecreateCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -109,20 +102,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testDeleteCollection() { public void testDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -130,20 +123,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testDeleteCollectionFind() { public void testDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -151,19 +144,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollection() { public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.get( MyEntity.class, 1 ) session.get( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );
@ -172,19 +165,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() { public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.find( MyEntity.class, 1 ) session.find( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );

View File

@ -6,23 +6,6 @@
*/ */
package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy; package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
import java.lang.reflect.Method;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.extractor.Extractors.resultOf; import static org.assertj.core.extractor.Extractors.resultOf;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.ENTITY_ENTRY_FIELD_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.ENTITY_ENTRY_FIELD_NAME;
@ -44,10 +27,29 @@ import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_FIELD
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME;
import static org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableAndMappedSuperclassTest.CardGame;
@TestForIssue(jiraKey = "HHH-13759") import java.lang.reflect.Method;
@RunWith(BytecodeEnhancerRunner.class)
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
@BytecodeEnhanced(testEnhancedClasses = CardGame.class)
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
@JiraKey("HHH-13759")
public class DirtyCheckingWithEmbeddableAndMappedSuperclassTest { public class DirtyCheckingWithEmbeddableAndMappedSuperclassTest {
@Test @Test

View File

@ -34,18 +34,17 @@ import java.lang.reflect.Method;
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker; import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker; import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest { public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest {
@ -99,7 +98,7 @@ public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest
assertThat( entity ) assertThat( entity )
.extracting( TRACKER_FIELD_NAME ).isInstanceOf( SimpleFieldTracker.class ); .extracting( TRACKER_FIELD_NAME ).isInstanceOf( SimpleFieldTracker.class );
assertThat( entity.getEmbedded() ) assertThat( entity.getEmbedded() )
.extracting( TRACKER_COMPOSITE_FIELD_NAME ).isInstanceOf( CompositeOwnerTracker.class); .extracting( TRACKER_COMPOSITE_FIELD_NAME ).isInstanceOf( CompositeOwnerTracker.class );
assertThat( entity ).extracting( resultOf( TRACKER_HAS_CHANGED_NAME ) ).isEqualTo( true ); assertThat( entity ).extracting( resultOf( TRACKER_HAS_CHANGED_NAME ) ).isEqualTo( true );
assertThat( entity ).extracting( resultOf( TRACKER_GET_NAME ) ) assertThat( entity ).extracting( resultOf( TRACKER_GET_NAME ) )

View File

@ -20,11 +20,10 @@ import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_N
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
@ -33,7 +32,7 @@ import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
@JiraKey("HHH-17035") @JiraKey("HHH-17035")
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassWithDifferentGenericParameterNameTest { public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassWithDifferentGenericParameterNameTest {

View File

@ -11,11 +11,10 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
@ -23,7 +22,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest { public class DirtyCheckingWithEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest {

View File

@ -6,11 +6,10 @@
*/ */
package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy; package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
@ -23,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX;
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableExtedingAnotherEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest { public class DirtyCheckingWithEmbeddableExtedingAnotherEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest {

View File

@ -8,12 +8,13 @@ package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
import java.util.List; import java.util.List;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -23,29 +24,25 @@ import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableExtendingMappedSuperclassTest.*;
@RunWith(BytecodeEnhancerRunner.class)
@DomainModel(annotatedClasses = { MyEntity.class, })
@SessionFactory
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableExtendingMappedSuperclassTest extends public class DirtyCheckingWithEmbeddableExtendingMappedSuperclassTest {
BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
MyEntity.class
};
}
@JiraKey("HHH-17041") @JiraKey("HHH-17041")
@Test @Test
public void testQueryEmbeddableFields() { public void testQueryEmbeddableFields(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = new MyEntity(1, "one"); MyEntity myEntity = new MyEntity(1, "one");
session.persist( myEntity ); session.persist( myEntity );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list(); List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list();
assertThat( result.size() ).isEqualTo( 1 ); assertThat( result.size() ).isEqualTo( 1 );

View File

@ -9,44 +9,43 @@ package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy.DirtyCheckingWithEmbeddableNonVisibleGenericExtendsSerializableMappedSuperclassTest.*;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
MyEntity.class,
}
)
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddableNonVisibleGenericExtendsSerializableMappedSuperclassTest extends public class DirtyCheckingWithEmbeddableNonVisibleGenericExtendsSerializableMappedSuperclassTest {
BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
MyEntity.class
};
}
@JiraKey("HHH-17041") @JiraKey("HHH-17041")
@Test @Test
public void testQueryEmbeddableFields() { public void testQueryEmbeddableFields(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = new MyEntity(1, "one"); MyEntity myEntity = new MyEntity(1, "one");
session.persist( myEntity ); session.persist( myEntity );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list(); List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list();
assertThat( result.size() ).isEqualTo( 1 ); assertThat( result.size() ).isEqualTo( 1 );

View File

@ -16,11 +16,10 @@ import jakarta.persistence.Id;
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker; import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker; import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
@ -46,8 +45,8 @@ import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_N
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME;
@TestForIssue(jiraKey = "HHH-13764") @JiraKey("HHH-13764")
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddedOnGetterTest { public class DirtyCheckingWithEmbeddedOnGetterTest {

View File

@ -16,13 +16,12 @@ import jakarta.persistence.Id;
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker; import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker; import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.extractor.Extractors.resultOf; import static org.assertj.core.extractor.Extractors.resultOf;
@ -46,8 +45,8 @@ import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_N
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME;
@TestForIssue(jiraKey = "HHH-13764") @JiraKey("HHH-13764")
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithEmbeddedTest { public class DirtyCheckingWithEmbeddedTest {
@ -64,7 +63,8 @@ public class DirtyCheckingWithEmbeddedTest {
.hasDeclaredMethods( PERSISTENT_FIELD_READER_PREFIX + "name", PERSISTENT_FIELD_WRITER_PREFIX + "name" ) .hasDeclaredMethods( PERSISTENT_FIELD_READER_PREFIX + "name", PERSISTENT_FIELD_WRITER_PREFIX + "name" )
.hasDeclaredMethods( ENTITY_INSTANCE_GETTER_NAME, ENTITY_ENTRY_GETTER_NAME ) .hasDeclaredMethods( ENTITY_INSTANCE_GETTER_NAME, ENTITY_ENTRY_GETTER_NAME )
.hasDeclaredMethods( PREVIOUS_GETTER_NAME, PREVIOUS_SETTER_NAME, NEXT_GETTER_NAME, NEXT_SETTER_NAME ) .hasDeclaredMethods( PREVIOUS_GETTER_NAME, PREVIOUS_SETTER_NAME, NEXT_GETTER_NAME, NEXT_SETTER_NAME )
.hasDeclaredMethods( TRACKER_HAS_CHANGED_NAME, TRACKER_CLEAR_NAME, TRACKER_SUSPEND_NAME, TRACKER_GET_NAME ); .hasDeclaredMethods(
TRACKER_HAS_CHANGED_NAME, TRACKER_CLEAR_NAME, TRACKER_SUSPEND_NAME, TRACKER_GET_NAME );
} }
@Test @Test
@ -76,7 +76,8 @@ public class DirtyCheckingWithEmbeddedTest {
@Test @Test
public void shouldDeclareMethodsInEmbeddedClass() { public void shouldDeclareMethodsInEmbeddedClass() {
assertThat( Component.class ) assertThat( Component.class )
.hasDeclaredMethods( PERSISTENT_FIELD_READER_PREFIX + "component", PERSISTENT_FIELD_WRITER_PREFIX + "component" ) .hasDeclaredMethods(
PERSISTENT_FIELD_READER_PREFIX + "component", PERSISTENT_FIELD_WRITER_PREFIX + "component" )
.hasDeclaredMethods( TRACKER_COMPOSITE_SET_OWNER, TRACKER_COMPOSITE_CLEAR_OWNER ); .hasDeclaredMethods( TRACKER_COMPOSITE_SET_OWNER, TRACKER_COMPOSITE_CLEAR_OWNER );
} }

View File

@ -6,20 +6,6 @@
*/ */
package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy; package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
import java.lang.reflect.Method;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import org.assertj.core.extractor.Extractors;
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.extractor.Extractors.resultOf; import static org.assertj.core.extractor.Extractors.resultOf;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.ENTITY_ENTRY_FIELD_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.ENTITY_ENTRY_FIELD_NAME;
@ -39,8 +25,21 @@ import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_GET_N
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_HAS_CHANGED_NAME;
import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME; import static org.hibernate.bytecode.enhance.spi.EnhancerConstants.TRACKER_SUSPEND_NAME;
@TestForIssue(jiraKey = "HHH-13759") import java.lang.reflect.Method;
@RunWith(BytecodeEnhancerRunner.class)
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
@JiraKey("HHH-13759")
@BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyCheckingWithMappedsuperclassTest { public class DirtyCheckingWithMappedsuperclassTest {

View File

@ -1,16 +1,17 @@
package org.hibernate.orm.test.bytecode.enhancement.access; package org.hibernate.orm.test.bytecode.enhancement.access;
import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext; import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.After; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Assert; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Access; import jakarta.persistence.Access;
import jakarta.persistence.AccessType; import jakarta.persistence.AccessType;
@ -27,7 +28,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* Requires a custom enhancement context to disable dirty checking as bytecode enhancement is not expected to fully work with AccessType.PROPERTY * Requires a custom enhancement context to disable dirty checking as bytecode enhancement is not expected to fully work with AccessType.PROPERTY
@ -35,23 +37,24 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
* *
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10851" ) @JiraKey("HHH-10851" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
@CustomEnhancementContext( MixedAccessTest.NoDirtyCheckingContext.class ) annotatedClasses = {
public class MixedAccessTest extends BaseCoreFunctionalTestCase { MixedAccessTest.TestEntity.class, MixedAccessTest.TestOtherEntity.class,
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext(MixedAccessTest.NoDirtyCheckingContext.class)
public class MixedAccessTest {
private static final Pattern PARAM_PATTERN = Pattern.compile( "\\{\\\"(.*)\\\"\\:\\\"(.*)\\\"\\}" ); private static final Pattern PARAM_PATTERN = Pattern.compile( "\\{\\\"(.*)\\\"\\:\\\"(.*)\\\"\\}" );
private static final Function<Map.Entry, String> MAPPING_FUNCTION = e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\""; private static final Function<Map.Entry, String> MAPPING_FUNCTION = e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\"";
private static final String ID = "foo", PARAM_KEY = "paramName", PARAM_VAL = "paramValue", PARAMS_AS_STR = "{\"" + PARAM_KEY + "\":\"" + PARAM_VAL + "\"}"; private static final String ID = "foo", PARAM_KEY = "paramName", PARAM_VAL = "paramValue", PARAMS_AS_STR = "{\"" + PARAM_KEY + "\":\"" + PARAM_VAL + "\"}";
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{TestEntity.class, TestOtherEntity.class}; scope.inTransaction( s -> {
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
TestEntity testEntity = new TestEntity( ID ); TestEntity testEntity = new TestEntity( ID );
testEntity.setParamsAsString( PARAMS_AS_STR ); testEntity.setParamsAsString( PARAMS_AS_STR );
s.persist( testEntity ); s.persist( testEntity );
@ -63,13 +66,13 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
TestEntity testEntity = s.get( TestEntity.class, ID ); TestEntity testEntity = s.get( TestEntity.class, ID );
Assert.assertEquals( PARAMS_AS_STR, testEntity.getParamsAsString() ); assertEquals( PARAMS_AS_STR, testEntity.getParamsAsString() );
TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, ID ); TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, ID );
Assert.assertEquals( PARAMS_AS_STR, testOtherEntity.getParamsAsString() ); assertEquals( PARAMS_AS_STR, testOtherEntity.getParamsAsString() );
// Clean parameters // Clean parameters
testEntity.setParamsAsString( "{}" ); testEntity.setParamsAsString( "{}" );
@ -77,14 +80,14 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
} ); } );
} }
@After @AfterEach
public void cleanup() { public void cleanup(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
TestEntity testEntity = s.get( TestEntity.class, ID ); TestEntity testEntity = s.get( TestEntity.class, ID );
Assert.assertTrue( testEntity.getParams().isEmpty() ); assertTrue( testEntity.getParams().isEmpty() );
TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, ID ); TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, ID );
Assert.assertTrue( testOtherEntity.getParams().isEmpty() ); assertTrue( testOtherEntity.getParams().isEmpty() );
} ); } );
} }
@ -92,7 +95,7 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "TEST_ENTITY" ) @Table( name = "TEST_ENTITY" )
private static class TestEntity { static class TestEntity {
@Id @Id
String name; String name;
@ -137,7 +140,7 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "OTHER_ENTITY" ) @Table( name = "OTHER_ENTITY" )
@Access( AccessType.FIELD ) @Access( AccessType.FIELD )
private static class TestOtherEntity { static class TestOtherEntity {
@Id @Id
String name; String name;

View File

@ -1,14 +1,14 @@
package org.hibernate.orm.test.bytecode.enhancement.access; package org.hibernate.orm.test.bytecode.enhancement.access;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Access; import jakarta.persistence.Access;
import jakarta.persistence.AccessType; import jakarta.persistence.AccessType;
@ -17,44 +17,46 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
@DomainModel(
annotatedClasses = {
PropertyAccessTest.SomeEntity.class,
}
)
@SessionFactory
@JiraKey("HHH-16799") @JiraKey("HHH-16799")
@RunWith(BytecodeEnhancerRunner.class) @BytecodeEnhanced
public class PropertyAccessTest extends BaseCoreFunctionalTestCase { public class PropertyAccessTest {
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { SomeEntity.class };
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.persist( new SomeEntity( 1L, "field", "property" ) ); session.persist( new SomeEntity( 1L, "field", "property" ) );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
SomeEntity entity = session.get( SomeEntity.class, 1L ); SomeEntity entity = session.get( SomeEntity.class, 1L );
assertThat( entity.property ).isEqualTo( "from getter: property" ); assertThat( entity.property ).isEqualTo( "from getter: property" );
entity.setProperty( "updated" ); entity.setProperty( "updated" );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
SomeEntity entity = session.get( SomeEntity.class, 1L ); SomeEntity entity = session.get( SomeEntity.class, 1L );
assertThat( entity.property ).isEqualTo( "from getter: updated" ); assertThat( entity.property ).isEqualTo( "from getter: updated" );
} ); } );
} }
@After @AfterEach
public void cleanup() { public void cleanup(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.remove( session.get( SomeEntity.class, 1L ) ); session.remove( session.get( SomeEntity.class, 1L ) );
} ); } );
} }
@Entity @Entity
@Table(name = "SOME_ENTITY") @Table(name = "SOME_ENTITY")
private static class SomeEntity { static class SomeEntity {
@Id @Id
Long id; Long id;

View File

@ -6,12 +6,13 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.LazyGroup; import org.hibernate.annotations.LazyGroup;
import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOne;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -25,25 +26,24 @@ import static jakarta.persistence.CascadeType.ALL;
import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.FetchType.LAZY;
import static org.hibernate.annotations.FetchMode.SELECT; import static org.hibernate.annotations.FetchMode.SELECT;
import static org.hibernate.annotations.LazyToOneOption.NO_PROXY; import static org.hibernate.annotations.LazyToOneOption.NO_PROXY;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
BidirectionalOneToOneWithNonAggregateIdTest.Entity1.class,
BidirectionalOneToOneWithNonAggregateIdTest.Entity2.class
}
)
@SessionFactory
@BytecodeEnhanced
@JiraKey("HHH-17519") @JiraKey("HHH-17519")
public class BidirectionalOneToOneWithNonAggregateIdTest extends BaseCoreFunctionalTestCase { public class BidirectionalOneToOneWithNonAggregateIdTest {
static final int ENTITY_ID = 1; static final int ENTITY_ID = 1;
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class<?>[] { scope.inTransaction(
Entity1.class,
Entity2.class
};
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
Entity1 e1 = new Entity1( ENTITY_ID ); Entity1 e1 = new Entity1( ENTITY_ID );
Entity2 e2 = new Entity2(); Entity2 e2 = new Entity2();
@ -60,8 +60,8 @@ public class BidirectionalOneToOneWithNonAggregateIdTest extends BaseCoreFunctio
@Test @Test
public void testRemovingChild() { public void testRemovingChild(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Entity1 e1 = session.byId( Entity1.class ).load( ENTITY_ID ); Entity1 e1 = session.byId( Entity1.class ).load( ENTITY_ID );
Entity2 child = e1.getChild(); Entity2 child = e1.getChild();

View File

@ -6,11 +6,12 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import org.hibernate.testing.TestForIssue; import java.util.List;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType; import jakarta.persistence.DiscriminatorType;
@ -24,56 +25,55 @@ import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import java.util.List;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-11050" ) @JiraKey("HHH-11050")
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class InheritedAttributeAssociationTest { public class InheritedAttributeAssociationTest {
@Test @Test
public void test() { public void test() {
// The mapping is wrong but the point is that the enhancement phase does not need to fail. See JIRA for further detail // The mapping is wrong but the point is that the enhancement phase does not need to fail. See JIRA for further detail
// If enhancement of 'items' attribute fails, 'name' won't be enhanced // If enhancement of 'items' attribute fails, 'name' won't be enhanced
Author author = new Author(); Author author = new Author();
author.name = "Bernardo Soares"; author.name = "Bernardo Soares";
EnhancerTestUtils.checkDirtyTracking( author, "name" ); EnhancerTestUtils.checkDirtyTracking( author, "name" );
} }
// --- // // --- //
@Entity @Entity
private static class Author { private static class Author {
@Id @Id
@GeneratedValue @GeneratedValue
Long id; Long id;
@OneToMany( fetch = FetchType.LAZY, mappedBy = "author" ) @OneToMany(fetch = FetchType.LAZY, mappedBy = "author")
List<ChildItem> items; List<ChildItem> items;
// keep this field after 'items' // keep this field after 'items'
String name; String name;
} }
@MappedSuperclass @MappedSuperclass
@Inheritance( strategy = InheritanceType.SINGLE_TABLE ) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn( name = "type", discriminatorType = DiscriminatorType.STRING ) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
private static abstract class Item { private static abstract class Item {
@Id @Id
@GeneratedValue @GeneratedValue
Long id; Long id;
@ManyToOne( fetch = FetchType.LAZY ) @ManyToOne(fetch = FetchType.LAZY)
Author author; Author author;
} }
@Entity @Entity
@DiscriminatorValue( "child" ) @DiscriminatorValue("child")
private static class ChildItem extends Item { private static class ChildItem extends Item {
} }
} }

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -15,15 +17,14 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToMany;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class ManyToManyAssociationListTest { public class ManyToManyAssociationListTest {
@Test @Test
public void testBidirectionalExisting() { public void testBidirectionalExisting() {
@ -36,8 +37,8 @@ public class ManyToManyAssociationListTest {
user.setGroups( new ArrayList<>( Collections.singleton( group ) ) ); user.setGroups( new ArrayList<>( Collections.singleton( group ) ) );
user.setGroups( new ArrayList<>( Arrays.asList( group, anotherGroup ) ) ); user.setGroups( new ArrayList<>( Arrays.asList( group, anotherGroup ) ) );
Assert.assertEquals( 1, group.getUsers().size() ); assertEquals( 1, group.getUsers().size() );
Assert.assertEquals( 1, anotherGroup.getUsers().size() ); assertEquals( 1, anotherGroup.getUsers().size() );
} }
// -- // // -- //

View File

@ -6,10 +6,11 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.*;
import org.junit.Assert;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -22,7 +23,7 @@ import java.util.Set;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class ManyToManyAssociationTest { public class ManyToManyAssociationTest {
@Test @Test
@ -37,34 +38,34 @@ public class ManyToManyAssociationTest {
user.addGroup( anotherGroup ); user.addGroup( anotherGroup );
anotherUser.addGroup( group ); anotherUser.addGroup( group );
Assert.assertEquals( 2, group.getUsers().size() ); assertEquals( 2, group.getUsers().size() );
Assert.assertEquals( 1, anotherGroup.getUsers().size() ); assertEquals( 1, anotherGroup.getUsers().size() );
group.resetUsers(); group.resetUsers();
Assert.assertEquals( 1, user.getGroups().size() ); assertEquals( 1, user.getGroups().size() );
Assert.assertEquals( 0, anotherUser.getGroups().size() ); assertEquals( 0, anotherUser.getGroups().size() );
// Test remove // Test remove
user.addGroup( group ); user.addGroup( group );
anotherUser.addGroup( group ); anotherUser.addGroup( group );
Assert.assertEquals( 2, group.getUsers().size() ); assertEquals( 2, group.getUsers().size() );
Assert.assertEquals( 1, anotherGroup.getUsers().size() ); assertEquals( 1, anotherGroup.getUsers().size() );
Set<Group> groups = new HashSet<>( user.getGroups() ); Set<Group> groups = new HashSet<>( user.getGroups() );
groups.remove( group ); groups.remove( group );
user.setGroups( groups ); user.setGroups( groups );
Assert.assertEquals( 1, group.getUsers().size() ); assertEquals( 1, group.getUsers().size() );
Assert.assertEquals( 1, anotherGroup.getUsers().size() ); assertEquals( 1, anotherGroup.getUsers().size() );
groups.remove( anotherGroup ); groups.remove( anotherGroup );
user.setGroups( groups ); user.setGroups( groups );
Assert.assertEquals( 1, group.getUsers().size() ); assertEquals( 1, group.getUsers().size() );
// This happens (and is expected) because there was no snapshot taken before remove // This happens (and is expected) because there was no snapshot taken before remove
Assert.assertEquals( 1, anotherGroup.getUsers().size() ); assertEquals( 1, anotherGroup.getUsers().size() );
} }
// -- // // -- //

View File

@ -6,10 +6,13 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertSame;
import org.junit.runner.RunWith; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -24,43 +27,43 @@ import java.util.List;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class OneToManyAssociationTest { public class OneToManyAssociationTest {
@Test @Test
public void test() { public void test() {
Customer customer = new Customer(); Customer customer = new Customer();
Assert.assertTrue( customer.getInventories().isEmpty() ); assertTrue( customer.getInventories().isEmpty() );
CustomerInventory customerInventory = new CustomerInventory(); CustomerInventory customerInventory = new CustomerInventory();
customerInventory.setCustomer( customer ); customerInventory.setCustomer( customer );
Assert.assertEquals( 1, customer.getInventories().size() ); assertEquals( 1, customer.getInventories().size() );
Assert.assertTrue( customer.getInventories().contains( customerInventory ) ); assertTrue( customer.getInventories().contains( customerInventory ) );
Customer anotherCustomer = new Customer(); Customer anotherCustomer = new Customer();
Assert.assertTrue( anotherCustomer.getInventories().isEmpty() ); assertTrue( anotherCustomer.getInventories().isEmpty() );
customerInventory.setCustomer( anotherCustomer ); customerInventory.setCustomer( anotherCustomer );
Assert.assertTrue( customer.getInventories().isEmpty() ); assertTrue( customer.getInventories().isEmpty() );
Assert.assertEquals( 1, anotherCustomer.getInventories().size() ); assertEquals( 1, anotherCustomer.getInventories().size() );
Assert.assertSame( customerInventory, anotherCustomer.getInventories().get( 0 ) ); assertSame( customerInventory, anotherCustomer.getInventories().get( 0 ) );
customer.addInventory( customerInventory ); customer.addInventory( customerInventory );
Assert.assertSame( customer, customerInventory.getCustomer() ); assertSame( customer, customerInventory.getCustomer() );
Assert.assertTrue( anotherCustomer.getInventories().isEmpty() ); assertTrue( anotherCustomer.getInventories().isEmpty() );
Assert.assertEquals( 1, customer.getInventories().size() ); assertEquals( 1, customer.getInventories().size() );
customer.addInventory( new CustomerInventory() ); customer.addInventory( new CustomerInventory() );
Assert.assertEquals( 2, customer.getInventories().size() ); assertEquals( 2, customer.getInventories().size() );
// Test remove // Test remove
customer.removeInventory( customerInventory ); customer.removeInventory( customerInventory );
Assert.assertEquals( 1, customer.getInventories().size() ); assertEquals( 1, customer.getInventories().size() );
// This happens (and is expected) because there was no snapshot taken before remove // This happens (and is expected) because there was no snapshot taken before remove
Assert.assertNotNull( customerInventory.getCustomer() ); assertNotNull( customerInventory.getCustomer() );
} }
// --- // // --- //

View File

@ -10,14 +10,15 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.After; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@ -34,21 +35,21 @@ import static org.junit.Assert.assertTrue;
* @author Marco Belladelli * @author Marco Belladelli
* @author Tomas Cerskus * @author Tomas Cerskus
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
@TestForIssue(jiraKey = "HHH-16136") annotatedClasses = {
public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCase { OneToManyLazyAndEagerTest.User.class,
@Override OneToManyLazyAndEagerTest.Order.class,
protected Class<?>[] getAnnotatedClasses() { OneToManyLazyAndEagerTest.OrderItem.class
return new Class<?>[] { }
User.class, )
Order.class, @SessionFactory
OrderItem.class @BytecodeEnhanced
}; @JiraKey("HHH-16136")
} public class OneToManyLazyAndEagerTest {
@Before @BeforeEach
public void prepare() { public void prepare(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
final User user = new User( "User 1", "Marco" ); final User user = new User( "User 1", "Marco" );
final User targetUser = new User( "User 2", "Andrea" ); final User targetUser = new User( "User 2", "Andrea" );
final Order order = new Order( "Order 1", user, targetUser ); final Order order = new Order( "Order 1", user, targetUser );
@ -61,9 +62,9 @@ public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCa
} ); } );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.createQuery( "delete from OrderItem" ).executeUpdate(); em.createQuery( "delete from OrderItem" ).executeUpdate();
em.createQuery( "delete from Order" ).executeUpdate(); em.createQuery( "delete from Order" ).executeUpdate();
em.createQuery( "delete from User" ).executeUpdate(); em.createQuery( "delete from User" ).executeUpdate();
@ -71,8 +72,8 @@ public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCa
} }
@Test @Test
public void testQuery() { public void testQuery(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
final Order order = em.createQuery( "select o from Order o", Order.class ) final Order order = em.createQuery( "select o from Order o", Order.class )
.getResultList() .getResultList()
.get( 0 ); .get( 0 );

View File

@ -6,42 +6,46 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import jakarta.persistence.*; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.After; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
/** /**
* @author Marco Belladelli * @author Marco Belladelli
* @author Tomas Cerskus * @author Tomas Cerskus
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
@TestForIssue(jiraKey = "HHH-16477") annotatedClasses = {
public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestCase { OneToManyLazyAndEagerTest2.User.class,
@Override OneToManyLazyAndEagerTest2.Coupon.class,
protected Class<?>[] getAnnotatedClasses() { OneToManyLazyAndEagerTest2.Order.class
return new Class<?>[] { }
User.class, )
Coupon.class, @SessionFactory
Order.class @BytecodeEnhanced
}; @JiraKey("HHH-16477")
} public class OneToManyLazyAndEagerTest2 {
@Before @BeforeEach
public void prepare() { public void prepare(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
final User user = new User( "User 1", "Marco" ); final User user = new User( "User 1", "Marco" );
final User targetUser = new User( "User 2", "Andrea" ); final User targetUser = new User( "User 2", "Andrea" );
final Coupon coupon = new Coupon( "Coupon 1", targetUser ); final Coupon coupon = new Coupon( "Coupon 1", targetUser );
@ -53,9 +57,9 @@ public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestC
} ); } );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.createQuery( "delete from Order" ).executeUpdate(); em.createQuery( "delete from Order" ).executeUpdate();
em.createQuery( "delete from Coupon" ).executeUpdate(); em.createQuery( "delete from Coupon" ).executeUpdate();
em.createQuery( "delete from User" ).executeUpdate(); em.createQuery( "delete from User" ).executeUpdate();
@ -63,22 +67,22 @@ public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestC
} }
@Test @Test
public void testQuery() { public void testQuery(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
final Order order = em.createQuery( "select o from Order o", Order.class ) final Order order = em.createQuery( "select o from Order o", Order.class )
.getResultList() .getResultList()
.get( 0 ); .get( 0 );
final User user = order.getUser(); final User user = order.getUser();
assertTrue( "Proxy should be initialized", Hibernate.isInitialized( user ) ); assertTrue( Hibernate.isInitialized( user ), "Proxy should be initialized" );
assertEquals( "Marco", user.getName() ); assertEquals( "Marco", user.getName() );
final User targetUser = order.getTargetUser(); final User targetUser = order.getTargetUser();
assertTrue( "Proxy should be initialized", Hibernate.isInitialized( targetUser ) ); assertTrue( Hibernate.isInitialized( targetUser ), "Proxy should be initialized" );
assertEquals( "Andrea", targetUser.getName() ); assertEquals( "Andrea", targetUser.getName() );
final Coupon coupon = order.getCoupon(); final Coupon coupon = order.getCoupon();
assertTrue( "Proxy should be initialized", Hibernate.isInitialized( coupon ) ); assertTrue( Hibernate.isInitialized( coupon ), "Proxy should be initialized" );
assertThat( coupon.getTargetUser() ).isSameAs( targetUser ); assertThat( coupon.getTargetUser() ).isSameAs( targetUser );

View File

@ -2,14 +2,16 @@ package org.hibernate.orm.test.bytecode.enhancement.association;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -18,30 +20,30 @@ import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
@JiraKey("HHH-17173") @JiraKey("HHH-17173")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class OneToOnEnhancedEntityLoadedAsReferenceTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
OneToOnEnhancedEntityLoadedAsReferenceTest.ContainingEntity.class, OneToOnEnhancedEntityLoadedAsReferenceTest.ContainedEntity.class
}
)
@ServiceRegistry(
settings = {
@Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "10"),
@Setting(name = AvailableSettings.MAX_FETCH_DEPTH, value = "0")
}
)
@SessionFactory
@BytecodeEnhanced
public class OneToOnEnhancedEntityLoadedAsReferenceTest {
private long entityId; private long entityId;
private long entityId2; private long entityId2;
private long containedEntityId; private long containedEntityId;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[] { ContainingEntity.class, ContainedEntity.class }; scope.inTransaction( em -> {
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, 10 );
configuration.setProperty( AvailableSettings.MAX_FETCH_DEPTH, 0 );
}
@Before
public void prepare() {
doInJPA( this::sessionFactory, em -> {
ContainingEntity entity = new ContainingEntity(); ContainingEntity entity = new ContainingEntity();
ContainedEntity containedEntity = new ContainedEntity(); ContainedEntity containedEntity = new ContainedEntity();
containedEntity.setValue( "value" ); containedEntity.setValue( "value" );
@ -60,8 +62,8 @@ public class OneToOnEnhancedEntityLoadedAsReferenceTest extends BaseCoreFunction
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
ContainingEntity entity2 = em.getReference( ContainingEntity.class, entityId2 ); ContainingEntity entity2 = em.getReference( ContainingEntity.class, entityId2 );
ContainingEntity entity = em.getReference( ContainingEntity.class, entityId ); ContainingEntity entity = em.getReference( ContainingEntity.class, entityId );
ContainedEntity containedEntity = em.getReference( ContainedEntity.class, containedEntityId ); ContainedEntity containedEntity = em.getReference( ContainedEntity.class, containedEntityId );

View File

@ -6,22 +6,23 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.association; package org.hibernate.orm.test.bytecode.enhancement.association;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class OneToOneAssociationTest { public class OneToOneAssociationTest {
@Test @Test
@ -32,7 +33,7 @@ public class OneToOneAssociationTest {
Customer customer = new Customer(); Customer customer = new Customer();
customer.setUser( user ); customer.setUser( user );
Assert.assertEquals( customer, user.getCustomer() ); assertEquals( customer, user.getCustomer() );
// check dirty tracking is set automatically with bi-directional association management // check dirty tracking is set automatically with bi-directional association management
EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" ); EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" );
@ -42,12 +43,12 @@ public class OneToOneAssociationTest {
customer.setUser( anotherUser ); customer.setUser( anotherUser );
Assert.assertNull( user.getCustomer() ); assertNull( user.getCustomer() );
Assert.assertEquals( customer, anotherUser.getCustomer() ); assertEquals( customer, anotherUser.getCustomer() );
user.setCustomer( new Customer() ); user.setCustomer( new Customer() );
Assert.assertEquals( user, user.getCustomer().getUser() ); assertEquals( user, user.getCustomer().getUser() );
} }
@Test @Test
@ -58,15 +59,15 @@ public class OneToOneAssociationTest {
Customer customer = new Customer(); Customer customer = new Customer();
customer.setUser( user ); customer.setUser( user );
Assert.assertEquals( customer, user.getCustomer() ); assertEquals( customer, user.getCustomer() );
// check dirty tracking is set automatically with bi-directional association management // check dirty tracking is set automatically with bi-directional association management
EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" ); EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" );
user.setCustomer( null ); user.setCustomer( null );
Assert.assertNull( user.getCustomer() ); assertNull( user.getCustomer() );
Assert.assertNull( customer.getUser() ); assertNull( customer.getUser() );
} }
// --- // // --- //

View File

@ -1,40 +1,39 @@
package org.hibernate.orm.test.bytecode.enhancement.bag; package org.hibernate.orm.test.bytecode.enhancement.bag;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Set; import java.util.Set;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @DomainModel(
import static org.junit.Assert.assertTrue; annotatedClasses = {
BagAndSetFetchTest.EntityA.class,
BagAndSetFetchTest.EntityB.class,
@RunWith(BytecodeEnhancerRunner.class) BagAndSetFetchTest.EntityC.class,
public class BagAndSetFetchTest extends BaseCoreFunctionalTestCase { BagAndSetFetchTest.EntityD.class,
}
@Override )
protected Class<?>[] getAnnotatedClasses() { @SessionFactory
return new Class[] { @BytecodeEnhanced
EntityA.class, public class BagAndSetFetchTest {
EntityB.class,
EntityC.class,
EntityD.class,
};
}
@Test @Test
public void testIt() { public void testIt(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
EntityB b = new EntityB( 1l, "b" ); EntityB b = new EntityB( 1l, "b" );
@ -85,7 +84,7 @@ public class BagAndSetFetchTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
EntityA entityA = session.find( EntityA.class, 1l ); EntityA entityA = session.find( EntityA.class, 1l );
Collection<EntityB> attributes = entityA.attributes; Collection<EntityB> attributes = entityA.attributes;

View File

@ -1,38 +1,39 @@
package org.hibernate.orm.test.bytecode.enhancement.bag; package org.hibernate.orm.test.bytecode.enhancement.bag;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class EagerBagsTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
EagerBagsTest.EntityA.class,
@Override EagerBagsTest.EntityB.class,
protected Class<?>[] getAnnotatedClasses() { EagerBagsTest.EntityC.class,
return new Class[] { EagerBagsTest.EntityD.class,
EntityA.class, }
EntityB.class, )
EntityC.class, @SessionFactory
EntityD.class, @BytecodeEnhanced
}; public class EagerBagsTest {
}
@Test @Test
public void testIt() { public void testIt(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
EntityB b = new EntityB( 1l, "b" ); EntityB b = new EntityB( 1l, "b" );
@ -70,7 +71,7 @@ public class EagerBagsTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
EntityA entityA = session.find( EntityA.class, 1l ); EntityA entityA = session.find( EntityA.class, 1l );
Collection<EntityB> attributes = entityA.attributes; Collection<EntityB> attributes = entityA.attributes;

View File

@ -10,14 +10,11 @@ import org.hibernate.Version;
import org.hibernate.bytecode.enhance.spi.EnhancementInfo; import org.hibernate.bytecode.enhance.spi.EnhancementInfo;
import org.hibernate.engine.spi.ManagedEntity; import org.hibernate.engine.spi.ManagedEntity;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.orm.test.legacy.Simple;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Assert; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.Jira;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -26,18 +23,18 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class BasicEnhancementTest { public class BasicEnhancementTest {
@Test @Test
@ -62,10 +59,10 @@ public class BasicEnhancementTest {
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13439") @Jira("HHH-13439")
public void enhancementInfoTest() { public void enhancementInfoTest() {
EnhancementInfo info = SimpleEntity.class.getAnnotation( EnhancementInfo.class ); EnhancementInfo info = SimpleEntity.class.getAnnotation( EnhancementInfo.class );
assertNotNull( "EnhancementInfo was not applied", info ); assertNotNull( info, "EnhancementInfo was not applied" );
assertEquals( Version.getVersionString(), info.version() ); assertEquals( Version.getVersionString(), info.version() );
} }
@ -114,7 +111,7 @@ public class BasicEnhancementTest {
( (PersistentAttributeInterceptable) entity ).$$_hibernate_setInterceptor( null ); ( (PersistentAttributeInterceptable) entity ).$$_hibernate_setInterceptor( null );
entity.id = 1234567890L; entity.id = 1234567890L;
Assert.assertEquals( 1234567890L, (long) entity.getId() ); assertEquals( 1234567890L, (long) entity.getId() );
entity.name = "Entity Name"; entity.name = "Entity Name";
assertSame( "Entity Name", entity.name ); assertSame( "Entity Name", entity.name );

View File

@ -8,42 +8,44 @@ package org.hibernate.orm.test.bytecode.enhancement.basic;
import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.ManagedEntity; import org.hibernate.engine.spi.ManagedEntity;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.persistence.Transient; import jakarta.persistence.Transient;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertSame;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class BasicSessionTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
BasicSessionTest.MyEntity.class,
@Override }
protected Class<?>[] getAnnotatedClasses() { )
return new Class[]{ MyEntity.class}; @SessionFactory
} @BytecodeEnhanced
public class BasicSessionTest {
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.save( new MyEntity( 1L ) ); s.save( new MyEntity( 1L ) );
s.save( new MyEntity( 2L ) ); s.save( new MyEntity( 2L ) );
} ); } );
MyEntity[] entities = new MyEntity[2]; MyEntity[] entities = new MyEntity[2];
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
entities[0] = s.get( MyEntity.class, 1L ); entities[0] = s.get( MyEntity.class, 1L );
entities[1] = s.get( MyEntity.class, 2L ); entities[1] = s.get( MyEntity.class, 2L );
@ -70,7 +72,7 @@ public class BasicSessionTest extends BaseCoreFunctionalTestCase {
@Entity( name = "MyEntity" ) @Entity( name = "MyEntity" )
@Table( name = "MY_ENTITY" ) @Table( name = "MY_ENTITY" )
private static class MyEntity implements ManagedEntity { static class MyEntity implements ManagedEntity {
@Id @Id
Long id; Long id;

View File

@ -6,11 +6,12 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.basic; package org.hibernate.orm.test.bytecode.enhancement.basic;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.EmbeddedId; import jakarta.persistence.EmbeddedId;
@ -21,44 +22,45 @@ import jakarta.persistence.MapsId;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.SessionFactory;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-9529" ) @JiraKey( "HHH-9529" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class CrossEnhancementTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
CrossEnhancementTest.Parent.class, CrossEnhancementTest.Child.class, CrossEnhancementTest.ChildKey.class
@Override }
public Class<?>[] getAnnotatedClasses() { )
return new Class<?>[]{Parent.class, Child.class, ChildKey.class}; @SessionFactory
} @BytecodeEnhanced
public class CrossEnhancementTest {
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
sessionFactory().close(); // sessionFactory().close();
buildSessionFactory(); // buildSessionFactory();
} scope.getSessionFactory().close();
// TODO: I do not get this test ^ and not sure how to update it ...
}
// --- // // --- //
@Entity @Entity
@Table( name = "PARENT" ) @Table( name = "PARENT" )
private static class Parent { static class Parent {
@Id @Id
String id; String id;
} }
@Embeddable @Embeddable
private static class ChildKey implements Serializable { static class ChildKey implements Serializable {
String parent; String parent;
String type; String type;
} }
@Entity @Entity
@Table( name = "CHILD" ) @Table( name = "CHILD" )
private static class Child { static class Child {
@EmbeddedId @EmbeddedId
ChildKey id; ChildKey id;

View File

@ -6,26 +6,25 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.basic; package org.hibernate.orm.test.bytecode.enhancement.basic;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.getFieldByReflection; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.getFieldByReflection;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class ExtendedAssociationManagementTest { public class ExtendedAssociationManagementTest {
@Test @Test
@ -46,7 +45,7 @@ public class ExtendedAssociationManagementTest {
customer.user = anotherUser; customer.user = anotherUser;
Assert.assertNull( user.customer ); assertNull( user.customer );
assertEquals( customer, getFieldByReflection( anotherUser, "customer" ) ); assertEquals( customer, getFieldByReflection( anotherUser, "customer" ) );
user.customer = new Customer(); user.customer = new Customer();

View File

@ -4,11 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -21,19 +22,18 @@ import jakarta.persistence.Id;
* static accessors, accessors defined in a subclass, * static accessors, accessors defined in a subclass,
* or accessors defined in an inner class. * or accessors defined in an inner class.
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
ExtendedEnhancementNonStandardAccessTest.MyAbstractEntity.class, ExtendedEnhancementNonStandardAccessTest.MyAbstractConfusingEntity.class, ExtendedEnhancementNonStandardAccessTest.MyConcreteEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions(lazyLoading = true, extendedEnhancement = true) @EnhancementOptions(lazyLoading = true, extendedEnhancement = true)
public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctionalTestCase { public class ExtendedEnhancementNonStandardAccessTest {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
MyAbstractEntity.class, MyAbstractConfusingEntity.class, MyConcreteEntity.class
};
}
@Test @Test
public void nonStandardInstanceGetterSetterPublicField() { public void nonStandardInstanceGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -44,11 +44,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForPublicField(); return entity.nonStandardGetterForPublicField();
} }
} ); }, scope );
} }
@Test @Test
public void nonStandardInstanceGetterSetterProtectedField() { public void nonStandardInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -59,11 +59,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForProtectedField(); return entity.nonStandardGetterForProtectedField();
} }
} ); }, scope );
} }
@Test @Test
public void nonStandardInstanceGetterSetterPackagePrivateField() { public void nonStandardInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -74,11 +74,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForPackagePrivateField(); return entity.nonStandardGetterForPackagePrivateField();
} }
} ); }, scope );
} }
@Test @Test
public void nonStandardInstanceGetterSetterPrivateField() { public void nonStandardInstanceGetterSetterPrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -89,11 +89,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForPrivateField(); return entity.nonStandardGetterForPrivateField();
} }
} ); }, scope );
} }
@Test @Test
public void staticGetterSetterPublicField() { public void staticGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -104,11 +104,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.staticGetPublicField( entity ); return MyConcreteEntity.staticGetPublicField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void staticGetterSetterProtectedField() { public void staticGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -119,11 +119,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.staticGetProtectedField( entity ); return MyConcreteEntity.staticGetProtectedField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void staticGetterSetterPackagePrivateField() { public void staticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -134,11 +134,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.staticGetPackagePrivateField( entity ); return MyConcreteEntity.staticGetPackagePrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void staticGetterSetterPrivateField() { public void staticGetterSetterPrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -149,11 +149,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.staticGetPrivateField( entity ); return MyConcreteEntity.staticGetPrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassStaticGetterSetterPublicField() { public void innerClassStaticGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -164,11 +164,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.InnerClassAccessors.staticGetPublicField( entity ); return MyConcreteEntity.InnerClassAccessors.staticGetPublicField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassStaticGetterSetterProtectedField() { public void innerClassStaticGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -179,11 +179,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.InnerClassAccessors.staticGetProtectedField( entity ); return MyConcreteEntity.InnerClassAccessors.staticGetProtectedField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassStaticGetterSetterPackagePrivateField() { public void innerClassStaticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -194,11 +194,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.InnerClassAccessors.staticGetPackagePrivateField( entity ); return MyConcreteEntity.InnerClassAccessors.staticGetPackagePrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassStaticGetterSetterPrivateField() { public void innerClassStaticGetterSetterPrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -209,11 +209,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return MyConcreteEntity.InnerClassAccessors.staticGetPrivateField( entity ); return MyConcreteEntity.InnerClassAccessors.staticGetPrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassInstanceGetterSetterPublicField() { public void innerClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -224,11 +224,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new MyConcreteEntity.InnerClassAccessors().instanceGetPublicField( entity ); return new MyConcreteEntity.InnerClassAccessors().instanceGetPublicField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassInstanceGetterSetterProtectedField() { public void innerClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -239,11 +239,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new MyConcreteEntity.InnerClassAccessors().instanceGetProtectedField( entity ); return new MyConcreteEntity.InnerClassAccessors().instanceGetProtectedField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassInstanceGetterSetterPackagePrivateField() { public void innerClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -254,11 +254,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new MyConcreteEntity.InnerClassAccessors().instanceGetPackagePrivateField( entity ); return new MyConcreteEntity.InnerClassAccessors().instanceGetPackagePrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void innerClassInstanceGetterSetterPrivateField() { public void innerClassInstanceGetterSetterPrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -269,11 +269,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new MyConcreteEntity.InnerClassAccessors().instanceGetPrivateField( entity ); return new MyConcreteEntity.InnerClassAccessors().instanceGetPrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassStaticGetterSetterPublicField() { public void externalClassStaticGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -284,11 +284,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return ExternalClassAccessors.staticGetPublicField( entity ); return ExternalClassAccessors.staticGetPublicField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassStaticGetterSetterProtectedField() { public void externalClassStaticGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -299,11 +299,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return ExternalClassAccessors.staticGetProtectedField( entity ); return ExternalClassAccessors.staticGetProtectedField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassStaticGetterSetterPackagePrivateField() { public void externalClassStaticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -314,11 +314,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return ExternalClassAccessors.staticGetPackagePrivateField( entity ); return ExternalClassAccessors.staticGetPackagePrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassInstanceGetterSetterPublicField() { public void externalClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -329,11 +329,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new ExternalClassAccessors().instanceGetPublicField( entity ); return new ExternalClassAccessors().instanceGetPublicField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassInstanceGetterSetterProtectedField() { public void externalClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -344,11 +344,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new ExternalClassAccessors().instanceGetProtectedField( entity ); return new ExternalClassAccessors().instanceGetProtectedField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void externalClassInstanceGetterSetterPackagePrivateField() { public void externalClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -359,11 +359,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return new ExternalClassAccessors().instanceGetPackagePrivateField( entity ); return new ExternalClassAccessors().instanceGetPackagePrivateField( entity );
} }
} ); }, scope );
} }
@Test @Test
public void subClassInstanceGetterSetterPublicField() { public void subClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -374,11 +374,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.getAbstractEntityPublicField(); return entity.getAbstractEntityPublicField();
} }
} ); }, scope );
} }
@Test @Test
public void subClassInstanceGetterSetterProtectedField() { public void subClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -389,11 +389,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.getAbstractEntityProtectedField(); return entity.getAbstractEntityProtectedField();
} }
} ); }, scope );
} }
@Test @Test
public void subClassInstanceGetterSetterPackagePrivateField() { public void subClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -404,11 +404,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.getAbstractEntityPackagePrivateField(); return entity.getAbstractEntityPackagePrivateField();
} }
} ); }, scope );
} }
@Test @Test
public void subClassNonStandardInstanceGetterSetterPublicField() { public void subClassNonStandardInstanceGetterSetterPublicField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -419,11 +419,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForAbstractEntityPublicField(); return entity.nonStandardGetterForAbstractEntityPublicField();
} }
} ); }, scope );
} }
@Test @Test
public void subClassNonStandardInstanceGetterSetterProtectedField() { public void subClassNonStandardInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -434,11 +434,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForAbstractEntityProtectedField(); return entity.nonStandardGetterForAbstractEntityProtectedField();
} }
} ); }, scope );
} }
@Test @Test
public void subClassNonStandardInstanceGetterSetterPackagePrivateField() { public void subClassNonStandardInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
doTestFieldAccess( new AccessDelegate() { doTestFieldAccess( new AccessDelegate() {
@Override @Override
public void setValue(MyConcreteEntity entity, Long value) { public void setValue(MyConcreteEntity entity, Long value) {
@ -449,33 +449,33 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
public Long getValue(MyConcreteEntity entity) { public Long getValue(MyConcreteEntity entity) {
return entity.nonStandardGetterForAbstractEntityPackagePrivateField(); return entity.nonStandardGetterForAbstractEntityPackagePrivateField();
} }
} ); }, scope );
} }
// Ideally we'd make this a @ParameterizedTest and pass the access delegate as parameter, // Ideally we'd make this a @ParameterizedTest and pass the access delegate as parameter,
// but we cannot do that due to JUnit using a different classloader than the test. // but we cannot do that due to JUnit using a different classloader than the test.
private void doTestFieldAccess(AccessDelegate delegate) { private void doTestFieldAccess(AccessDelegate delegate, SessionFactoryScope scope) {
Long id = fromTransaction( em -> { Long id = scope.fromTransaction( em -> {
var entity = new MyConcreteEntity(); var entity = new MyConcreteEntity();
em.persist( entity ); em.persist( entity );
return entity.id; return entity.id;
} ); } );
inTransaction( em -> { scope.inTransaction( em -> {
var entity = em.find( MyConcreteEntity.class, id ); var entity = em.find( MyConcreteEntity.class, id );
assertThat( delegate.getValue( entity ) ) assertThat( delegate.getValue( entity ) )
.as( "Loaded value before update" ) .as( "Loaded value before update" )
.isNull(); .isNull();
} ); } );
inTransaction( em -> { scope.inTransaction( em -> {
var entity = em.getReference( MyConcreteEntity.class, id ); var entity = em.getReference( MyConcreteEntity.class, id );
// Since field access is replaced with accessor calls, // Since field access is replaced with accessor calls,
// we expect this change to be detected by dirty tracking and persisted. // we expect this change to be detected by dirty tracking and persisted.
delegate.setValue( entity, 42L ); delegate.setValue( entity, 42L );
} ); } );
inTransaction( em -> { scope.inTransaction( em -> {
var entity = em.find( MyConcreteEntity.class, id ); var entity = em.find( MyConcreteEntity.class, id );
// We're working on an initialized entity. // We're working on an initialized entity.
assertThat( entity ) assertThat( entity )
@ -487,7 +487,7 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
.isEqualTo( 42L ); .isEqualTo( 42L );
} ); } );
inTransaction( em -> { scope.inTransaction( em -> {
var entity = em.getReference( MyConcreteEntity.class, id ); var entity = em.getReference( MyConcreteEntity.class, id );
// We're working on an uninitialized entity. // We're working on an uninitialized entity.
assertThat( entity ) assertThat( entity )

View File

@ -18,24 +18,25 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import org.hibernate.annotations.Immutable; import org.hibernate.annotations.Immutable;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.junit.jupiter.api.Test;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
FinalFieldEnhancementTest.EntityWithFinalField.class,
@Override FinalFieldEnhancementTest.EntityWithEmbeddedIdWithFinalField.class, FinalFieldEnhancementTest.EntityWithEmbeddedIdWithFinalField.EmbeddableId.class,
protected Class<?>[] getAnnotatedClasses() { FinalFieldEnhancementTest.EntityWithEmbeddedNonIdWithFinalField.class, FinalFieldEnhancementTest.EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId.class
return new Class[] { }
EntityWithFinalField.class, )
EntityWithEmbeddedIdWithFinalField.class, EntityWithEmbeddedIdWithFinalField.EmbeddableId.class, @SessionFactory
EntityWithEmbeddedNonIdWithFinalField.class, EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId.class @BytecodeEnhanced
}; public class FinalFieldEnhancementTest {
}
@Test @Test
public void entityWithFinalField_constructor() { public void entityWithFinalField_constructor() {
@ -45,14 +46,14 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
// Just test that the embedded non-ID works correctly over a persist/retrieve cycle // Just test that the embedded non-ID works correctly over a persist/retrieve cycle
@Test @Test
public void entityWithFinalField_smokeTest() { public void entityWithFinalField_smokeTest(SessionFactoryScope scope) {
EntityWithFinalField persistedEntity = new EntityWithFinalField( "foo" ); EntityWithFinalField persistedEntity = new EntityWithFinalField( "foo" );
persistedEntity.setName( "Some name" ); persistedEntity.setName( "Some name" );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( persistedEntity ); s.persist( persistedEntity );
} ); } );
inTransaction( s -> { scope.inTransaction( s -> {
EntityWithFinalField entity = s.find( EntityWithFinalField.class, persistedEntity.getId() ); EntityWithFinalField entity = s.find( EntityWithFinalField.class, persistedEntity.getId() );
assertThat( entity ).extracting( EntityWithFinalField::getImmutableProperty ) assertThat( entity ).extracting( EntityWithFinalField::getImmutableProperty )
.isEqualTo( persistedEntity.getImmutableProperty() ); .isEqualTo( persistedEntity.getImmutableProperty() );
@ -61,22 +62,22 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
// Just test that the embedded ID works correctly over a persist/retrieve cycle // Just test that the embedded ID works correctly over a persist/retrieve cycle
@Test @Test
public void embeddableIdWithFinalField_smokeTest() { public void embeddableIdWithFinalField_smokeTest(SessionFactoryScope scope) {
EntityWithEmbeddedIdWithFinalField persistedEntity = new EntityWithEmbeddedIdWithFinalField(); EntityWithEmbeddedIdWithFinalField persistedEntity = new EntityWithEmbeddedIdWithFinalField();
persistedEntity.setName( "Some name" ); persistedEntity.setName( "Some name" );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( persistedEntity ); s.persist( persistedEntity );
} ); } );
// Read with the same ID instance // Read with the same ID instance
inTransaction( s -> { scope.inTransaction( s -> {
EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, persistedEntity.getId() ); EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, persistedEntity.getId() );
assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id ) assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id )
.isEqualTo( persistedEntity.getId().id ); .isEqualTo( persistedEntity.getId().id );
} ); } );
// Read with a new ID instance // Read with a new ID instance
inTransaction( s -> { scope.inTransaction( s -> {
EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, EntityWithEmbeddedIdWithFinalField.EmbeddableId.of( persistedEntity.getId().id ) ); EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, EntityWithEmbeddedIdWithFinalField.EmbeddableId.of( persistedEntity.getId().id ) );
assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id ) assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id )
.isEqualTo( persistedEntity.getId().id ); .isEqualTo( persistedEntity.getId().id );
@ -87,7 +88,7 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
// we know Hibernate ORM *has to* instantiate the EmbeddableIdType itself: // we know Hibernate ORM *has to* instantiate the EmbeddableIdType itself:
// it cannot reuse the ID we passed. // it cannot reuse the ID we passed.
// And since the EmbeddableIdType has a final field, instantiation will not be able to use a no-arg constructor... // And since the EmbeddableIdType has a final field, instantiation will not be able to use a no-arg constructor...
inTransaction( s -> { scope.inTransaction( s -> {
EntityWithEmbeddedIdWithFinalField entity = EntityWithEmbeddedIdWithFinalField entity =
s.createQuery( "from embidwithfinal e where e.name = :name", EntityWithEmbeddedIdWithFinalField.class ) s.createQuery( "from embidwithfinal e where e.name = :name", EntityWithEmbeddedIdWithFinalField.class )
.setParameter( "name", persistedEntity.getName() ) .setParameter( "name", persistedEntity.getName() )
@ -106,15 +107,15 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
// Just test that the embedded non-ID works correctly over a persist/retrieve cycle // Just test that the embedded non-ID works correctly over a persist/retrieve cycle
@Test @Test
public void embeddableNonIdWithFinalField_smokeTest() { public void embeddableNonIdWithFinalField_smokeTest(SessionFactoryScope scope) {
EntityWithEmbeddedNonIdWithFinalField persistedEntity = new EntityWithEmbeddedNonIdWithFinalField(); EntityWithEmbeddedNonIdWithFinalField persistedEntity = new EntityWithEmbeddedNonIdWithFinalField();
persistedEntity.setName( "Some name" ); persistedEntity.setName( "Some name" );
persistedEntity.setEmbedded( new EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId( "foo" ) ); persistedEntity.setEmbedded( new EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId( "foo" ) );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( persistedEntity ); s.persist( persistedEntity );
} ); } );
inTransaction( s -> { scope.inTransaction( s -> {
EntityWithEmbeddedNonIdWithFinalField entity = s.find( EntityWithEmbeddedNonIdWithFinalField.class, persistedEntity.getId() ); EntityWithEmbeddedNonIdWithFinalField entity = s.find( EntityWithEmbeddedNonIdWithFinalField.class, persistedEntity.getId() );
assertThat( entity ).extracting( EntityWithEmbeddedNonIdWithFinalField::getEmbedded ) assertThat( entity ).extracting( EntityWithEmbeddedNonIdWithFinalField::getEmbedded )
.extracting( EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId::getImmutableProperty ) .extracting( EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId::getImmutableProperty )

View File

@ -6,7 +6,8 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.basic; package org.hibernate.orm.test.bytecode.enhancement.basic;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.persistence.Access; import jakarta.persistence.Access;
import jakarta.persistence.AccessType; import jakarta.persistence.AccessType;
@ -17,16 +18,16 @@ import jakarta.persistence.MappedSuperclass;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(BytecodeEnhancerRunner.class) import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
@BytecodeEnhanced
public class GenericReturnValueMappedSuperclassEnhancementTest { public class GenericReturnValueMappedSuperclassEnhancementTest {
@Test @Test
@TestForIssue(jiraKey = "HHH-12579") @JiraKey("HHH-12579")
public void enhanceClassWithGenericReturnValueOnMappedSuperclass() { public void enhanceClassWithGenericReturnValueOnMappedSuperclass() {
SimpleEntity implementation = new SimpleEntity(); SimpleEntity implementation = new SimpleEntity();

View File

@ -4,13 +4,12 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext; import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -18,16 +17,16 @@ import jakarta.persistence.Version;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.clearDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.clearDirtyTracking;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
* @author Craig Andrews * @author Craig Andrews
*/ */
@TestForIssue( jiraKey = "HHH-11284" ) @JiraKey( "HHH-11284" )
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
@CustomEnhancementContext( {EnhancerTestContext.class, InheritedTest.EagerEnhancementContext.class} ) @CustomEnhancementContext( {EnhancerTestContext.class, InheritedTest.EagerEnhancementContext.class} )
public class InheritedTest { public class InheritedTest {
@ -62,7 +61,7 @@ public class InheritedTest {
// Adapted from BasicEnhancementTest#basicExtendedEnhancementTest // Adapted from BasicEnhancementTest#basicExtendedEnhancementTest
@Test @Test
@TestForIssue(jiraKey = "HHH-14006") @JiraKey("HHH-14006")
public void extendedEnhancementTest() { public void extendedEnhancementTest() {
// This test only works if lazy loading bytecode enhancement is enabled, // This test only works if lazy loading bytecode enhancement is enabled,
// otherwise extended bytecode enhancement does not do anything we can check. // otherwise extended bytecode enhancement does not do anything we can check.

View File

@ -4,13 +4,12 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext; import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -19,15 +18,15 @@ import jakarta.persistence.Version;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.clearDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.clearDirtyTracking;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10646" ) @JiraKey( "HHH-10646" )
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
@CustomEnhancementContext( {EnhancerTestContext.class, MappedSuperclassTest.EagerEnhancementContext.class} ) @CustomEnhancementContext( {EnhancerTestContext.class, MappedSuperclassTest.EagerEnhancementContext.class} )
public class MappedSuperclassTest { public class MappedSuperclassTest {
@ -49,7 +48,7 @@ public class MappedSuperclassTest {
// Adapted from BasicEnhancementTest#basicExtendedEnhancementTest // Adapted from BasicEnhancementTest#basicExtendedEnhancementTest
@Test @Test
@TestForIssue(jiraKey = "HHH-14006") @JiraKey("HHH-14006")
public void extendedEnhancementTest() { public void extendedEnhancementTest() {
// This test only works if lazy loading bytecode enhancement is enabled, // This test only works if lazy loading bytecode enhancement is enabled,
// otherwise extended bytecode enhancement does not do anything we can check. // otherwise extended bytecode enhancement does not do anything we can check.

View File

@ -1,14 +1,13 @@
package org.hibernate.orm.test.bytecode.enhancement.basic; package org.hibernate.orm.test.bytecode.enhancement.basic;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -21,31 +20,28 @@ import jakarta.persistence.Table;
* when the entity has the same field defined twice: once in a mappedsuperclass (should be ignored) * when the entity has the same field defined twice: once in a mappedsuperclass (should be ignored)
* and once in the concrete entity class. * and once in the concrete entity class.
*/ */
@TestForIssue(jiraKey = "HHH-15505") @JiraKey("HHH-15505")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class OverriddenFieldTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
OverriddenFieldTest.AbstractEntity.class, OverriddenFieldTest.Fruit.class
@Override }
public Class<?>[] getAnnotatedClasses() { )
return new Class<?>[] { AbstractEntity.class, Fruit.class }; @SessionFactory
} @BytecodeEnhanced
public class OverriddenFieldTest {
@Before
public void prepare() {
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Fruit testEntity = new Fruit(); Fruit testEntity = new Fruit();
testEntity.setId( 1 ); testEntity.setId( 1 );
testEntity.setName( "John" ); testEntity.setName( "John" );
s.persist( testEntity ); s.persist( testEntity );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Fruit testEntity = s.get( Fruit.class, 1 ); Fruit testEntity = s.get( Fruit.class, 1 );
Assert.assertEquals( "John", testEntity.getName() ); assertEquals( "John", testEntity.getName() );
} ); } );
} }

View File

@ -7,17 +7,18 @@ import org.hibernate.Hibernate;
import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -33,21 +34,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@JiraKey("HHH-16890") @JiraKey("HHH-16890")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
BatchEntityOneToManyTest.Order.class, BatchEntityOneToManyTest.Product.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class BatchEntityOneToManyTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setupData(SessionFactoryScope scope) {
return new Class[] { Order.class, Product.class };
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setupData() {
Product cheese1 = new Product( 1l, "Cheese 1" ); Product cheese1 = new Product( 1l, "Cheese 1" );
Product cheese2 = new Product( 2l, "Cheese 2" ); Product cheese2 = new Product( 2l, "Cheese 2" );
Product cheese3 = new Product( 3l, "Cheese 3" ); Product cheese3 = new Product( 3l, "Cheese 3" );
@ -57,7 +59,7 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
order.addProduct( cheese1 ); order.addProduct( cheese1 );
order.addProduct( cheese2 ); order.addProduct( cheese2 );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( cheese1 ); s.persist( cheese1 );
s.persist( cheese2 ); s.persist( cheese2 );
s.persist( cheese3 ); s.persist( cheese3 );
@ -65,9 +67,9 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
} ); } );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
session.createMutationQuery( "delete from Order" ).executeUpdate(); session.createMutationQuery( "delete from Order" ).executeUpdate();
session.createMutationQuery( "delete from Product" ).executeUpdate(); session.createMutationQuery( "delete from Product" ).executeUpdate();
@ -76,8 +78,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testGetOrder() { public void testGetOrder(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Order o = s.get( Order.class, 1 ); Order o = s.get( Order.class, 1 );
@ -89,8 +91,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testGetProduct() { public void testGetProduct(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product = s.getReference( Product.class, 3l ); Product product = s.getReference( Product.class, 3l );
@ -102,8 +104,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testCriteriaQuery() { public void testCriteriaQuery(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();

View File

@ -9,15 +9,17 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -33,21 +35,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@JiraKey("HHH-16890") @JiraKey("HHH-16890")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
BatchEntityOneToManyWithDisabledProxyTest.Order.class, BatchEntityOneToManyWithDisabledProxyTest.Product.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class BatchEntityOneToManyWithDisabledProxyTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setupData(SessionFactoryScope scope) {
return new Class[] { Order.class, Product.class };
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setupData() {
Product cheese1 = new Product( 1l, "Cheese 1" ); Product cheese1 = new Product( 1l, "Cheese 1" );
Product cheese2 = new Product( 2l, "Cheese 2" ); Product cheese2 = new Product( 2l, "Cheese 2" );
Product cheese3 = new Product( 3l, "Cheese 3" ); Product cheese3 = new Product( 3l, "Cheese 3" );
@ -57,7 +60,7 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
order.addProduct( cheese1 ); order.addProduct( cheese1 );
order.addProduct( cheese2 ); order.addProduct( cheese2 );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( cheese1 ); s.persist( cheese1 );
s.persist( cheese2 ); s.persist( cheese2 );
s.persist( cheese3 ); s.persist( cheese3 );
@ -65,9 +68,9 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
} ); } );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
session.createMutationQuery( "delete from Order" ).executeUpdate(); session.createMutationQuery( "delete from Order" ).executeUpdate();
session.createMutationQuery( "delete from Product" ).executeUpdate(); session.createMutationQuery( "delete from Product" ).executeUpdate();
@ -76,8 +79,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
} }
@Test @Test
public void testGetOrder() { public void testGetOrder(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Order o = s.get( Order.class, 1 ); Order o = s.get( Order.class, 1 );
@ -89,8 +92,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
@Test @Test
public void testGetProduct() { public void testGetProduct(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product = s.getReference( Product.class, 3l ); Product product = s.getReference( Product.class, 3l );
@ -102,8 +105,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
} }
@Test @Test
public void testCriteriaQuery() { public void testCriteriaQuery(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();

View File

@ -7,15 +7,17 @@ import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -33,24 +35,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@JiraKey("HHH-16890") @JiraKey("HHH-16890")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
BatchEntityWithSelectFetchTest.Order.class,
BatchEntityWithSelectFetchTest.Product.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class BatchEntityWithSelectFetchTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setupData(SessionFactoryScope scope) {
return new Class[] {
Order.class,
Product.class
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setupData() {
Product cheese1 = new Product( 1l, "Cheese 1" ); Product cheese1 = new Product( 1l, "Cheese 1" );
Product cheese2 = new Product( 2l, "Cheese 2" ); Product cheese2 = new Product( 2l, "Cheese 2" );
Product cheese3 = new Product( 3l, "Cheese 3" ); Product cheese3 = new Product( 3l, "Cheese 3" );
@ -61,7 +62,7 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
order.setProduct( cheese2 ); order.setProduct( cheese2 );
order2.setProduct( cheese1 ); order2.setProduct( cheese1 );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( cheese1 ); s.persist( cheese1 );
s.persist( cheese2 ); s.persist( cheese2 );
s.persist( cheese3 ); s.persist( cheese3 );
@ -70,9 +71,9 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
} ); } );
} }
@After @AfterEach
public void tearDown(){ public void tearDown(SessionFactoryScope scope){
inTransaction( scope.inTransaction(
session -> { session -> {
session.createMutationQuery( "delete from Order" ).executeUpdate(); session.createMutationQuery( "delete from Order" ).executeUpdate();
session.createMutationQuery( "delete from Product" ).executeUpdate(); session.createMutationQuery( "delete from Product" ).executeUpdate();
@ -81,8 +82,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testGetOrder() { public void testGetOrder(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product1 = s.getReference( Product.class, 1l ); Product product1 = s.getReference( Product.class, 1l );
@ -96,8 +97,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testGetOrder2() { public void testGetOrder2(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product = s.getReference( Product.class, 2l ); Product product = s.getReference( Product.class, 2l );
@ -110,8 +111,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testGetProduct() { public void testGetProduct(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product3 = s.getReference( Product.class, 3l ); Product product3 = s.getReference( Product.class, 3l );
@ -125,8 +126,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testCriteriaQuery() { public void testCriteriaQuery(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product1 = s.getReference( Product.class, 1l ); Product product1 = s.getReference( Product.class, 1l );

View File

@ -8,15 +8,17 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -34,24 +36,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@JiraKey("HHH-16890") @JiraKey("HHH-16890")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
BatchEntityWithSelectFetchWithDisableProxyTest.Order.class,
BatchEntityWithSelectFetchWithDisableProxyTest.Product.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class BatchEntityWithSelectFetchWithDisableProxyTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setupData(SessionFactoryScope scope) {
return new Class[] {
Order.class,
Product.class
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setupData() {
Product cheese1 = new Product( 1l, "Cheese 1" ); Product cheese1 = new Product( 1l, "Cheese 1" );
Product cheese2 = new Product( 2l, "Cheese 2" ); Product cheese2 = new Product( 2l, "Cheese 2" );
Product cheese3 = new Product( 3l, "Cheese 3" ); Product cheese3 = new Product( 3l, "Cheese 3" );
@ -62,7 +63,7 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
order.setProduct( cheese2 ); order.setProduct( cheese2 );
order2.setProduct( cheese1 ); order2.setProduct( cheese1 );
inTransaction( s -> { scope.inTransaction( s -> {
s.persist( cheese1 ); s.persist( cheese1 );
s.persist( cheese2 ); s.persist( cheese2 );
s.persist( cheese3 ); s.persist( cheese3 );
@ -71,9 +72,9 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
} ); } );
} }
@After @AfterEach
public void tearDown(){ public void tearDown(SessionFactoryScope scope){
inTransaction( scope.inTransaction(
session -> { session -> {
session.createMutationQuery( "delete from Order" ).executeUpdate(); session.createMutationQuery( "delete from Order" ).executeUpdate();
session.createMutationQuery( "delete from Product" ).executeUpdate(); session.createMutationQuery( "delete from Product" ).executeUpdate();
@ -82,8 +83,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
} }
@Test @Test
public void testGetOrder() { public void testGetOrder(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product1 = s.getReference( Product.class, 1l ); Product product1 = s.getReference( Product.class, 1l );
@ -97,8 +98,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
} }
@Test @Test
public void testGetOrder2() { public void testGetOrder2(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product = s.getReference( Product.class, 2l ); Product product = s.getReference( Product.class, 2l );
@ -111,8 +112,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
} }
@Test @Test
public void testGetProduct() { public void testGetProduct(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product3 = s.getReference( Product.class, 3l ); Product product3 = s.getReference( Product.class, 3l );
@ -126,8 +127,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
} }
@Test @Test
public void testCriteriaQuery() { public void testCriteriaQuery(SessionFactoryScope scope) {
inSession( s -> { scope.inSession( s -> {
s.getSessionFactory().getCache().evictAllRegions(); s.getSessionFactory().getCache().evictAllRegions();
Product product1 = s.getReference( Product.class, 1l ); Product product1 = s.getReference( Product.class, 1l );

View File

@ -7,14 +7,16 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
@ -33,31 +35,30 @@ import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class)
@JiraKey("HHH-16473") @JiraKey("HHH-16473")
public class AbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
AbstractManyToOneNoProxyTest.Actor.class,
AbstractManyToOneNoProxyTest.User.class,
AbstractManyToOneNoProxyTest.UserGroup.class,
AbstractManyToOneNoProxyTest.ActorGroup.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class AbstractManyToOneNoProxyTest {
private static final String ENTITY_A_NAME = "Alice"; private static final String ENTITY_A_NAME = "Alice";
private static final String ENTITY_B_NAME = "Bob"; private static final String ENTITY_B_NAME = "Bob";
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
Actor.class,
User.class,
UserGroup.class,
ActorGroup.class
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
User user1 = new User(); User user1 = new User();
@ -87,7 +88,7 @@ public class AbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
session.getSessionFactory().getCache().evictAllRegions(); session.getSessionFactory().getCache().evictAllRegions();
} }
@ -95,8 +96,8 @@ public class AbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testSelect() { public void testSelect(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
User user = session.getReference( User.class, 1 ); User user = session.getReference( User.class, 1 );

View File

@ -7,14 +7,16 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
@ -33,31 +35,31 @@ import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class)
@JiraKey("HHH-16473") @JiraKey("HHH-16473")
public class ManyToOneNoProxyTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
ManyToOneNoProxyTest.Actor.class,
ManyToOneNoProxyTest.User.class,
ManyToOneNoProxyTest.UserGroup.class,
ManyToOneNoProxyTest.ActorGroup.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class ManyToOneNoProxyTest {
private static final String ENTITY_A_NAME = "Alice"; private static final String ENTITY_A_NAME = "Alice";
private static final String ENTITY_B_NAME = "Bob"; private static final String ENTITY_B_NAME = "Bob";
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Actor.class,
User.class,
UserGroup.class,
ActorGroup.class
};
}
@Override @BeforeEach
protected void configure(Configuration configuration) { public void setUp(SessionFactoryScope scope) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true ); scope.inTransaction(
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
User user1 = new User(); User user1 = new User();
@ -87,7 +89,7 @@ public class ManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
session.getSessionFactory().getCache().evictAllRegions(); session.getSessionFactory().getCache().evictAllRegions();
} }
@ -95,8 +97,8 @@ public class ManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testSelect() { public void testSelect(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
User user = session.getReference( User.class, 1 ); User user = session.getReference( User.class, 1 );

View File

@ -6,14 +6,16 @@ import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -26,28 +28,27 @@ import jakarta.persistence.NamedQuery;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @JiraKey("HHH-16193")
@TestForIssue( jiraKey = "HHH-16193") @DomainModel(
public class ManyToOneTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
ManyToOneTest.EntityA.class,
ManyToOneTest.EntityB.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class ManyToOneTest {
private static final String ENTITY_B_NAME = "B1"; private static final String ENTITY_B_NAME = "B1";
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
EntityA.class,
EntityB.class
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
EntityB b1 = new EntityB( ENTITY_B_NAME ); EntityB b1 = new EntityB( ENTITY_B_NAME );
session.persist( b1 ); session.persist( b1 );
@ -58,8 +59,8 @@ public class ManyToOneTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testSelect() { public void testSelect(SessionFactoryScope scope) {
List<EntityA> entities = fromTransaction( List<EntityA> entities = scope.fromTransaction(
session -> session ->
session.createNamedQuery( "PersonType.selectAll", EntityA.class ) session.createNamedQuery( "PersonType.selectAll", EntityA.class )
.getResultList() .getResultList()

View File

@ -9,14 +9,16 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cacheable; import jakarta.persistence.Cacheable;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
@ -34,31 +36,30 @@ import jakarta.persistence.OneToMany;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class)
@JiraKey("HHH-16744") @JiraKey("HHH-16744")
public class ManyToOneTestReusedColumn extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
ManyToOneTestReusedColumn.Fridge.class,
ManyToOneTestReusedColumn.Container.class,
ManyToOneTestReusedColumn.CheeseContainer.class,
ManyToOneTestReusedColumn.FruitContainer.class,
ManyToOneTestReusedColumn.Food.class,
ManyToOneTestReusedColumn.Fruit.class,
ManyToOneTestReusedColumn.Cheese.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class ManyToOneTestReusedColumn {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
Fridge.class,
Container.class,
CheeseContainer.class,
FruitContainer.class,
Food.class,
Fruit.class,
Cheese.class
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
Fridge fridge = new Fridge(); Fridge fridge = new Fridge();
FruitContainer fruitContainer = new FruitContainer(); FruitContainer fruitContainer = new FruitContainer();
@ -91,8 +92,8 @@ public class ManyToOneTestReusedColumn extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testSelect() { public void testSelect(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Fridge fridge = session.getReference( Fridge.class, 1 ); Fridge fridge = session.getReference( Fridge.class, 1 );

View File

@ -9,12 +9,13 @@ package org.hibernate.orm.test.bytecode.enhancement.callbacks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners; import jakarta.persistence.EntityListeners;
@ -27,17 +28,18 @@ import jakarta.persistence.PostLoad;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@JiraKey("HHH-17019") @JiraKey("HHH-17019")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
PostLoadLazyListenerTest.Person.class, PostLoadLazyListenerTest.Tag.class
}
)
@SessionFactory
@BytecodeEnhanced
public class PostLoadLazyListenerTest {
@Override @AfterEach
protected Class<?>[] getAnnotatedClasses() { public void tearDown(SessionFactoryScope scope) {
return new Class[] { Person.class, Tag.class }; scope.inTransaction( session -> {
}
@After
public void tearDown() {
inTransaction( session -> {
session.createQuery( "delete from Tag" ).executeUpdate(); session.createQuery( "delete from Tag" ).executeUpdate();
session.createQuery( "delete from Person" ).executeUpdate(); session.createQuery( "delete from Person" ).executeUpdate();
} }
@ -45,8 +47,8 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void smoke() { public void smoke(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = new Person( 1, "name" ); Person person = new Person( 1, "name" );
Tag tag = new Tag( 100, person ); Tag tag = new Tag( 100, person );
@ -57,7 +59,7 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Tag tag = session.find( Tag.class, 100 ); Tag tag = session.find( Tag.class, 100 );
assertThat( tag ) assertThat( tag )

View File

@ -6,9 +6,11 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.callbacks; package org.hibernate.orm.test.bytecode.enhancement.callbacks;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Map;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -20,42 +22,44 @@ import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate; import jakarta.persistence.PreUpdate;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@JiraKey("HHH-12718") @JiraKey("HHH-12718")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase { annotatedClasses = {
PreUpdateBytecodeEnhancementTest.Person.class
@Override }
protected Class<?>[] getAnnotatedClasses() { )
return new Class<?>[] { Person.class }; @ServiceRegistry(
} settings = {
// TODO: how to convert this, or even is it needed?
@Override // options.put( AvailableSettings.CLASSLOADERS, getClass().getClassLoader() );
protected void addConfigOptions(Map options) { @Setting( name = AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, value = "true" ),
options.put( AvailableSettings.CLASSLOADERS, getClass().getClassLoader() ); @Setting( name = AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING, value = "true" ),
options.put( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, "true" ); }
options.put( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING, "true" ); )
} @SessionFactory
@BytecodeEnhanced
public class PreUpdateBytecodeEnhancementTest {
@Test @Test
public void testPreUpdateModifications() { public void testPreUpdateModifications(SessionFactoryScope scope) {
Person person = new Person(); Person person = new Person();
doInJPA( this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
entityManager.persist( person ); entityManager.persist( person );
} ); } );
doInJPA( this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Person p = entityManager.find( Person.class, person.id ); Person p = entityManager.find( Person.class, person.id );
assertNotNull( p ); assertNotNull( p );
assertNotNull( p.createdAt ); assertNotNull( p.createdAt );
@ -64,14 +68,14 @@ public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctiona
p.setName( "Changed Name" ); p.setName( "Changed Name" );
} ); } );
doInJPA( this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Person p = entityManager.find( Person.class, person.id ); Person p = entityManager.find( Person.class, person.id );
assertNotNull( p.lastUpdatedAt ); assertNotNull( p.lastUpdatedAt );
} ); } );
} }
@Entity(name = "Person") @Entity(name = "Person")
private static class Person { static class Person {
@Id @Id
@GeneratedValue @GeneratedValue
private int id; private int id;

View File

@ -6,12 +6,18 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import org.hibernate.testing.TestForIssue; import static org.junit.jupiter.api.Assertions.assertFalse;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.Before; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
@ -25,35 +31,30 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10252" ) @JiraKey( "HHH-10252" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
CascadeDeleteCollectionTest.Parent.class, CascadeDeleteCollectionTest.Child.class
}
)
@SessionFactory
@BytecodeEnhanced
public class CascadeDeleteCollectionTest {
private Parent originalParent; private Parent originalParent;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{Parent.class, Child.class};
}
@Before @BeforeEach
public void prepare() { public void prepare(SessionFactoryScope scope) {
// Create a Parent with one Child // Create a Parent with one Child
originalParent = doInHibernate( this::sessionFactory, s -> { originalParent = scope.fromTransaction( s -> {
Parent p = new Parent(); Parent p = new Parent();
p.setName( "PARENT" ); p.setName( "PARENT" );
p.setLazy( "LAZY" ); p.setLazy( "LAZY" );
@ -65,13 +66,13 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testManagedWithUninitializedAssociation() { public void testManagedWithUninitializedAssociation(SessionFactoryScope scope) {
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" ) Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
.setParameter( "name", "PARENT" ) .setParameter( "name", "PARENT" )
.uniqueResult(); .uniqueResult();
checkInterceptor( loadedParent, false ); checkInterceptor( scope, loadedParent, false );
assertFalse( Hibernate.isInitialized( loadedParent.getChildren() ) ); assertFalse( Hibernate.isInitialized( loadedParent.getChildren() ) );
s.delete( loadedParent ); s.delete( loadedParent );
} ); } );
@ -79,14 +80,14 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testManagedWithInitializedAssociation() { public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" ) Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
.setParameter( "name", "PARENT" ) .setParameter( "name", "PARENT" )
.uniqueResult(); .uniqueResult();
checkInterceptor( loadedParent, false ); checkInterceptor( scope, loadedParent, false );
loadedParent.getChildren().size(); loadedParent.getChildren().size();
assertTrue( Hibernate.isInitialized( loadedParent.getChildren() ) ); assertTrue( Hibernate.isInitialized( loadedParent.getChildren() ) );
s.delete( loadedParent ); s.delete( loadedParent );
@ -95,27 +96,27 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedWithUninitializedAssociation() { public void testDetachedWithUninitializedAssociation(SessionFactoryScope scope) {
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> { final Parent detachedParent = scope.fromTransaction( s -> {
return s.get( Parent.class, originalParent.getId() ); return s.get( Parent.class, originalParent.getId() );
} ); } );
assertFalse( Hibernate.isInitialized( detachedParent.getChildren() ) ); assertFalse( Hibernate.isInitialized( detachedParent.getChildren() ) );
checkInterceptor( detachedParent, false ); checkInterceptor( scope, detachedParent, false );
// Delete the detached Parent with uninitialized children // Delete the detached Parent with uninitialized children
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( detachedParent ); s.delete( detachedParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedWithInitializedAssociation() { public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> { final Parent detachedParent = scope.fromTransaction( s -> {
Parent parent = s.get( Parent.class, originalParent.getId() ); Parent parent = s.get( Parent.class, originalParent.getId() );
// initialize collection before detaching // initialize collection before detaching
parent.getChildren().size(); parent.getChildren().size();
@ -124,33 +125,33 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
assertTrue( Hibernate.isInitialized( detachedParent.getChildren() ) ); assertTrue( Hibernate.isInitialized( detachedParent.getChildren() ) );
checkInterceptor( detachedParent, false ); checkInterceptor( scope, detachedParent, false );
// Delete the detached Parent with initialized children // Delete the detached Parent with initialized children
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( detachedParent ); s.delete( detachedParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedOriginal() { public void testDetachedOriginal(SessionFactoryScope scope) {
// originalParent#children should be initialized // originalParent#children should be initialized
assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) ); assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) );
checkInterceptor( originalParent, true ); checkInterceptor( scope, originalParent, true );
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( originalParent ); s.delete( originalParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
private void checkInterceptor(Parent parent, boolean isNullExpected) { private void checkInterceptor(SessionFactoryScope scope, Parent parent, boolean isNullExpected) {
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory().getRuntimeMetamodels() final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( Parent.class ) .getEntityDescriptor( Parent.class )
.getBytecodeEnhancementMetadata(); .getBytecodeEnhancementMetadata();
@ -223,7 +224,7 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "CHILD" ) @Table( name = "CHILD" )
private static class Child { static class Child {
@Id @Id
@GeneratedValue( strategy = GenerationType.AUTO ) @GeneratedValue( strategy = GenerationType.AUTO )

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -17,18 +16,15 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.boot.internal.SessionFactoryBuilderImpl;
import org.hibernate.boot.internal.SessionFactoryOptionsBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.SessionFactoryBuilderService;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
@ -50,37 +46,25 @@ import jakarta.persistence.Table;
* *
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10252" ) @JiraKey( "HHH-10252" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest.Parent.class, CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest.Child.class
}
)
@SessionFactory(
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
applyCollectionsInDefaultFetchGroup = false
)
@BytecodeEnhanced
public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest {
private Parent originalParent; private Parent originalParent;
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class[]{Parent.class, Child.class};
}
@Override
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addService(
SessionFactoryBuilderService.class,
(SessionFactoryBuilderService) (metadata, bootstrapContext) -> {
SessionFactoryOptionsBuilder optionsBuilder = new SessionFactoryOptionsBuilder(
metadata.getMetadataBuildingOptions().getServiceRegistry(),
bootstrapContext
);
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
optionsBuilder.enableCollectionInDefaultFetchGroup( false );
return new SessionFactoryBuilderImpl( metadata, optionsBuilder, bootstrapContext );
}
);
}
@Before
public void prepare() {
// Create a Parent with one Child // Create a Parent with one Child
originalParent = doInHibernate( this::sessionFactory, s -> { originalParent = scope.fromTransaction( s -> {
Parent p = new Parent(); Parent p = new Parent();
p.setName( "PARENT" ); p.setName( "PARENT" );
p.setLazy( "LAZY" ); p.setLazy( "LAZY" );
@ -92,13 +76,13 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
} }
@Test @Test
public void testManagedWithUninitializedAssociation() { public void testManagedWithUninitializedAssociation(SessionFactoryScope scope) {
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" ) Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
.setParameter( "name", "PARENT" ) .setParameter( "name", "PARENT" )
.uniqueResult(); .uniqueResult();
checkInterceptor( loadedParent, false ); checkInterceptor( scope, loadedParent, false );
assertFalse( Hibernate.isPropertyInitialized( loadedParent, "children" ) ); assertFalse( Hibernate.isPropertyInitialized( loadedParent, "children" ) );
s.delete( loadedParent ); s.delete( loadedParent );
} ); } );
@ -106,14 +90,14 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testManagedWithInitializedAssociation() { public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" ) Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
.setParameter( "name", "PARENT" ) .setParameter( "name", "PARENT" )
.uniqueResult(); .uniqueResult();
checkInterceptor( loadedParent, false ); checkInterceptor( scope, loadedParent, false );
loadedParent.getChildren(); loadedParent.getChildren();
assertTrue( Hibernate.isPropertyInitialized( loadedParent, "children" ) ); assertTrue( Hibernate.isPropertyInitialized( loadedParent, "children" ) );
s.delete( loadedParent ); s.delete( loadedParent );
@ -122,27 +106,27 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedWithUninitializedAssociation() { public void testDetachedWithUninitializedAssociation(SessionFactoryScope scope) {
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> { final Parent detachedParent = scope.fromTransaction( s -> {
return s.get( Parent.class, originalParent.getId() ); return s.get( Parent.class, originalParent.getId() );
} ); } );
assertFalse( Hibernate.isPropertyInitialized( detachedParent, "children" ) ); assertFalse( Hibernate.isPropertyInitialized( detachedParent, "children" ) );
checkInterceptor( detachedParent, false ); checkInterceptor( scope, detachedParent, false );
// Delete the detached Parent with uninitialized children // Delete the detached Parent with uninitialized children
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( detachedParent ); s.delete( detachedParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedWithInitializedAssociation() { public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> { final Parent detachedParent = scope.fromTransaction( s -> {
Parent parent = s.get( Parent.class, originalParent.getId() ); Parent parent = s.get( Parent.class, originalParent.getId() );
assertFalse( Hibernate.isPropertyInitialized( parent, "children" ) ); assertFalse( Hibernate.isPropertyInitialized( parent, "children" ) );
@ -153,33 +137,33 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
assertTrue( Hibernate.isPropertyInitialized( detachedParent, "children" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedParent, "children" ) );
checkInterceptor( detachedParent, false ); checkInterceptor( scope, detachedParent, false );
// Delete the detached Parent with initialized children // Delete the detached Parent with initialized children
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( detachedParent ); s.delete( detachedParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-13129") @JiraKey("HHH-13129")
public void testDetachedOriginal() { public void testDetachedOriginal(SessionFactoryScope scope) {
// originalParent#children should be initialized // originalParent#children should be initialized
assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) ); assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) );
checkInterceptor( originalParent, true ); checkInterceptor( scope, originalParent, true );
// Delete the Parent // Delete the Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.delete( originalParent ); s.delete( originalParent );
} ); } );
// If the lazy relation is not fetch on cascade there is a constraint violation on commit // If the lazy relation is not fetch on cascade there is a constraint violation on commit
} }
private void checkInterceptor(Parent parent, boolean isNullExpected) { private void checkInterceptor(SessionFactoryScope scope, Parent parent, boolean isNullExpected) {
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory().getRuntimeMetamodels() final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( Parent.class ) .getEntityDescriptor( Parent.class )
.getBytecodeEnhancementMetadata(); .getBytecodeEnhancementMetadata();
@ -252,7 +236,7 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
@Entity @Entity
@Table( name = "CHILD" ) @Table( name = "CHILD" )
private static class Child { static class Child {
@Id @Id
@GeneratedValue( strategy = GenerationType.AUTO ) @GeneratedValue( strategy = GenerationType.AUTO )

View File

@ -21,52 +21,42 @@ import org.hibernate.Hibernate;
import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption; import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.cfg.Configuration;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is; import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
import static org.hamcrest.CoreMatchers.not; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue(jiraKey = "HHH-10252") @JiraKey("HHH-10252")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
private SQLStatementInterceptor sqlInterceptor; CascadeDeleteManyToOneTest.Parent.class, CascadeDeleteManyToOneTest.Child.class
}
)
@SessionFactory
@BytecodeEnhanced
public class CascadeDeleteManyToOneTest {
private Child originalChild; private Child originalChild;
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class[] { Parent.class, Child.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
sqlInterceptor = new SQLStatementInterceptor( configuration );
}
@Before
public void prepare() {
// Create a Parent with one Child // Create a Parent with one Child
originalChild = doInHibernate( originalChild = scope.fromTransaction( s -> {
this::sessionFactory, s -> {
Child c = new Child(); Child c = new Child();
c.setName( "CHILD" ); c.setName( "CHILD" );
c.setLazy( "LAZY" ); c.setLazy( "LAZY" );
@ -78,21 +68,22 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testManagedWithInitializedAssociation() { public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
sqlInterceptor.clear();
// Delete the Child // Delete the Child
inTransaction( scope.inTransaction(
(s) -> { (s) -> {
final SQLStatementInspector statementInspector = extractFromSession( s );
statementInspector.clear();
final Child managedChild = (Child) s.createQuery( "SELECT c FROM Child c WHERE name=:name" ) final Child managedChild = (Child) s.createQuery( "SELECT c FROM Child c WHERE name=:name" )
.setParameter( "name", "CHILD" ) .setParameter( "name", "CHILD" )
.uniqueResult(); .uniqueResult();
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) ); statementInspector.assertExecutedCount( 1 );
// parent should be an uninitialized enhanced-proxy // parent should be an uninitialized enhanced-proxy
assertTrue( Hibernate.isPropertyInitialized( managedChild, "parent" ) ); assertTrue( Hibernate.isPropertyInitialized( managedChild, "parent" ) );
assertThat( managedChild.getParent(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( managedChild.getParent() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( managedChild.getParent() ) ); assertFalse( Hibernate.isInitialized( managedChild.getParent() ) );
s.delete( managedChild ); s.delete( managedChild );
@ -100,8 +91,7 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
); );
// Explicitly check that both got deleted // Explicitly check that both got deleted
doInHibernate( scope.inTransaction( s -> {
this::sessionFactory, s -> {
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() ); assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() ); assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
} }
@ -109,18 +99,18 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testDetachedWithInitializedAssociation() { public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
sqlInterceptor.clear(); final Child detachedChild = scope.fromTransaction(
final Child detachedChild = fromTransaction(
(s) -> { (s) -> {
final SQLStatementInspector statementInspector = extractFromSession( s );
statementInspector.clear();
Child child = s.get( Child.class, originalChild.getId() ); Child child = s.get( Child.class, originalChild.getId() );
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) ); statementInspector.assertExecutedCount( 1 );
// parent should be an uninitialized enhanced-proxy // parent should be an uninitialized enhanced-proxy
assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) ); assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) );
assertThat( child.getParent(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( child.getParent() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( child.getParent() ) ); assertFalse( Hibernate.isInitialized( child.getParent() ) );
return child; return child;
@ -129,15 +119,15 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
assertTrue( Hibernate.isPropertyInitialized( detachedChild, "parent" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedChild, "parent" ) );
checkInterceptor( detachedChild, false ); checkInterceptor( scope, detachedChild, false );
// Delete the detached Child with initialized parent // Delete the detached Child with initialized parent
inTransaction( scope.inTransaction(
(s) -> s.delete( detachedChild ) (s) -> s.delete( detachedChild )
); );
// Explicitly check that both got deleted // Explicitly check that both got deleted
inTransaction( scope.inTransaction(
(s) -> { (s) -> {
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() ); assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() ); assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
@ -146,30 +136,28 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testDetachedOriginal() { public void testDetachedOriginal(SessionFactoryScope scope) {
// originalChild#parent should be initialized // originalChild#parent should be initialized
assertTrue( Hibernate.isPropertyInitialized( originalChild, "parent" ) ); assertTrue( Hibernate.isPropertyInitialized( originalChild, "parent" ) );
checkInterceptor( originalChild, true ); checkInterceptor( scope, originalChild, true );
// Delete the Child // Delete the Child
doInHibernate( scope.inTransaction( s -> {
this::sessionFactory, s -> {
s.delete( originalChild ); s.delete( originalChild );
} }
); );
// Explicitly check that both got deleted // Explicitly check that both got deleted
doInHibernate( scope.inTransaction( s -> {
this::sessionFactory, s -> {
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() ); assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() ); assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
} }
); );
} }
private void checkInterceptor(Child child, boolean isNullExpected) { private void checkInterceptor(SessionFactoryScope scope, Child child, boolean isNullExpected) {
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory() final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory()
.getRuntimeMetamodels() .getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( Child.class ) .getEntityDescriptor( Child.class )
@ -206,7 +194,7 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
@Entity(name = "Child") @Entity(name = "Child")
@Table(name = "CHILD") @Table(name = "CHILD")
private static class Child { static class Child {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -6,11 +6,12 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
@ -26,32 +27,31 @@ import jakarta.persistence.Table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10254" ) @JiraKey( "HHH-10254" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class CascadeDetachedTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
CascadeDetachedTest.Author.class, CascadeDetachedTest.Book.class
@Override }
protected Class<?>[] getAnnotatedClasses() { )
return new Class[]{Author.class, Book.class}; @SessionFactory
} @BytecodeEnhanced
public class CascadeDetachedTest {
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
Book book = new Book( "978-1118063330", "Operating System Concepts 9th Edition" ); Book book = new Book( "978-1118063330", "Operating System Concepts 9th Edition" );
book.addAuthor( new Author( "Abraham", "Silberschatz", new char[] { 'a', 'b' } ) ); book.addAuthor( new Author( "Abraham", "Silberschatz", new char[] { 'a', 'b' } ) );
book.addAuthor( new Author( "Peter", "Galvin", new char[] { 'c', 'd' } ) ); book.addAuthor( new Author( "Peter", "Galvin", new char[] { 'c', 'd' } ) );
book.addAuthor( new Author( "Greg", "Gagne", new char[] { 'e', 'f' } ) ); book.addAuthor( new Author( "Greg", "Gagne", new char[] { 'e', 'f' } ) );
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
em.persist( book ); em.persist( book );
} ); } );
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
em.merge( book ); em.merge( book );
} ); } );
} }

View File

@ -1,7 +1,6 @@
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -20,120 +19,133 @@ import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.transaction.TransactionUtil; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static junit.framework.TestCase.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
import static org.hamcrest.CoreMatchers.is; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.CoreMatchers.not; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* @author Bolek Ziobrowski * @author Bolek Ziobrowski
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @JiraKey("HHH-13129")
@TestForIssue(jiraKey = "HHH-13129") @DomainModel(
public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestCase { annotatedClasses = {
private SQLStatementInterceptor sqlInterceptor; CascadeOnUninitializedTest.Person.class, CascadeOnUninitializedTest.Address.class
}
@Override )
protected Class<?>[] getAnnotatedClasses() { @ServiceRegistry(
return new Class<?>[] { Person.class, Address.class }; settings = {
} @Setting( name = AvailableSettings.FORMAT_SQL, value = "true" ),
}
@Override )
protected void addSettings(Map<String,Object> settings) { @SessionFactory
super.addSettings( settings ); @BytecodeEnhanced
settings.put( AvailableSettings.FORMAT_SQL, "true" ); public class CascadeOnUninitializedTest {
sqlInterceptor = new SQLStatementInterceptor( settings );
}
@Test @Test
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne() { public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
final Person person = persistPersonWithManyToOne(); final Person person = persistPersonWithManyToOne(scope);
sqlInterceptor.clear();
// get a detached Person // get a detached Person
final Person detachedPerson = fromTransaction( final Person detachedPerson = scope.fromTransaction(
session -> session.get( Person.class, person.getId() ) session -> {
final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
Person p = session.get( Person.class, person.getId() );
// loading Person should lead to one SQL
statementInspector.assertExecutedCount( 1 );
return p;
}
); );
// loading Person should lead to one SQL
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
// primaryAddress should be "initialized" as an enhanced-proxy // primaryAddress should be "initialized" as an enhanced-proxy
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
// alter the detached reference // alter the detached reference
detachedPerson.setName( "newName" ); detachedPerson.setName( "newName" );
final Person mergedPerson = fromTransaction( final Person mergedPerson = scope.fromTransaction(
session -> (Person) session.merge( detachedPerson ) session -> {
final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
Person merge = session.merge( detachedPerson );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) update Person
session.flush();
statementInspector.assertExecutedCount( 2 );
return merge;
}
); );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) update Person
assertThat( sqlInterceptor.getQueryCount(), is( 3 ) );
// primaryAddress should not be initialized // primaryAddress should not be initialized
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
assertEquals( "newName", mergedPerson.getName() ); assertEquals( "newName", mergedPerson.getName() );
} }
@Test @Test
public void testDeleteEnhancedEntityWithUninitializedManyToOne() { public void testDeleteEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
Person person = persistPersonWithManyToOne(); Person person = persistPersonWithManyToOne(scope);
sqlInterceptor.clear();
// get a detached Person // get a detached Person
Person detachedPerson = fromTransaction( Person detachedPerson = scope.fromTransaction(
session -> session.get( Person.class, person.getId() ) session -> {
); final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
// loading Person should lead to one SQL Person p = session.get( Person.class, person.getId() );
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
// loading Person should lead to one SQL
statementInspector.assertExecutedCount( 1 );
return p;
}
);
// primaryAddress should be initialized as an enhance-proxy // primaryAddress should be initialized as an enhance-proxy
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson, not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
sqlInterceptor.clear();
// deleting detachedPerson should result in detachedPerson.primaryAddress being initialized, // deleting detachedPerson should result in detachedPerson.primaryAddress being initialized,
// so that the DELETE operation can be cascaded to it. // so that the DELETE operation can be cascaded to it.
inTransaction( scope.inTransaction(
session -> session.delete( detachedPerson ) session -> {
final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
session.delete( detachedPerson );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) delete Person
// 4) select primary Address
session.flush();
statementInspector.assertExecutedCount( 4 );
}
); );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) delete Person
// 4) select primary Address
assertThat( sqlInterceptor.getQueryCount(), is( 4 ) );
// both the Person and its Address should be deleted // both the Person and its Address should be deleted
inTransaction( scope.inTransaction(
session -> { session -> {
assertNull( session.get( Person.class, person.getId() ) ); assertNull( session.get( Person.class, person.getId() ) );
assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) ); assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) );
@ -142,26 +154,18 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
} }
@Test @Test
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany() { public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
Person person = persistPersonWithOneToMany(); Person person = persistPersonWithOneToMany( scope );
// get a detached Person // get a detached Person
Person detachedPerson = TransactionUtil.doInHibernate( Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
this::sessionFactory, session -> {
return session.get( Person.class, person.getId() );
}
);
// address should not be initialized in order to reproduce the problem // address should not be initialized in order to reproduce the problem
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
detachedPerson.setName( "newName" ); detachedPerson.setName( "newName" );
Person mergedPerson = TransactionUtil.doInHibernate( Person mergedPerson = scope.fromTransaction( session -> session.merge( detachedPerson ) );
this::sessionFactory, session -> {
return (Person) session.merge( detachedPerson );
}
);
// address still shouldn't be initialized: there's no reason for it to be initialized by a merge. // address still shouldn't be initialized: there's no reason for it to be initialized by a merge.
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
@ -169,37 +173,28 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
} }
@Test @Test
public void testDeleteEnhancedEntityWithUninitializedOneToMany() { public void testDeleteEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
Person person = persistPersonWithOneToMany(); Person person = persistPersonWithOneToMany( scope );
// get a detached Person // get a detached Person
Person detachedPerson = TransactionUtil.doInHibernate( Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
this::sessionFactory, session -> {
return session.get( Person.class, person.getId() );
}
);
// address should not be initialized in order to reproduce the problem // address should not be initialized in order to reproduce the problem
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
// deleting detachedPerson should result in detachedPerson.address being initialized, // deleting detachedPerson should result in detachedPerson.address being initialized,
// so that the DELETE operation can be cascaded to it. // so that the DELETE operation can be cascaded to it.
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.delete( detachedPerson ) );
this::sessionFactory, session -> {
session.delete( detachedPerson );
}
);
// both the Person and its Address should be deleted // both the Person and its Address should be deleted
TransactionUtil.doInHibernate( scope.inTransaction( session -> {
this::sessionFactory, session -> {
assertNull( session.get( Person.class, person.getId() ) ); assertNull( session.get( Person.class, person.getId() ) );
assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) ); assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) );
} }
); );
} }
public Person persistPersonWithManyToOne() { public Person persistPersonWithManyToOne(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
address.setDescription( "ABC" ); address.setDescription( "ABC" );
@ -207,16 +202,12 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
person.setName( "John Doe" ); person.setName( "John Doe" );
person.setPrimaryAddress( address ); person.setPrimaryAddress( address );
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.persist( person ) );
this::sessionFactory, session -> {
session.persist( person );
}
);
return person; return person;
} }
public Person persistPersonWithOneToMany() { public Person persistPersonWithOneToMany(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
address.setDescription( "ABC" ); address.setDescription( "ABC" );
@ -224,11 +215,7 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
person.setName( "John Doe" ); person.setName( "John Doe" );
person.getAddresses().add( address ); person.getAddresses().add( address );
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.persist( person ) );
this::sessionFactory, session -> {
session.persist( person );
}
);
return person; return person;
} }

View File

@ -1,35 +1,31 @@
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import static junit.framework.TestCase.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
import static org.hamcrest.CoreMatchers.is; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.CoreMatchers.not; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption; import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.boot.internal.SessionFactoryBuilderImpl;
import org.hibernate.boot.internal.SessionFactoryOptionsBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.SessionFactoryBuilderService;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.jdbc.SQLStatementInterceptor; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.transaction.TransactionUtil; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -51,116 +47,117 @@ import jakarta.persistence.Table;
* @author Bolek Ziobrowski * @author Bolek Ziobrowski
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @JiraKey("HHH-13129")
@TestForIssue(jiraKey = "HHH-13129") @DomainModel(
public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest extends BaseNonConfigCoreFunctionalTestCase { annotatedClasses = {
private SQLStatementInterceptor sqlInterceptor; CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest.Person.class, CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest.Address.class
}
@Override )
protected Class<?>[] getAnnotatedClasses() { @ServiceRegistry(
return new Class<?>[] { Person.class, Address.class }; settings = {
} @Setting( name = AvailableSettings.FORMAT_SQL, value = "true" ),
}
@Override )
protected void addSettings(Map<String,Object> settings) { @SessionFactory(
super.addSettings( settings ); // We want to test with this setting set to false explicitly,
settings.put( AvailableSettings.FORMAT_SQL, "true" ); // because another test already takes care of the default.
sqlInterceptor = new SQLStatementInterceptor( settings ); applyCollectionsInDefaultFetchGroup = false
} )
@BytecodeEnhanced
@Override public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest {
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addService(
SessionFactoryBuilderService.class,
(SessionFactoryBuilderService) (metadata, bootstrapContext) -> {
SessionFactoryOptionsBuilder optionsBuilder = new SessionFactoryOptionsBuilder(
metadata.getMetadataBuildingOptions().getServiceRegistry(),
bootstrapContext
);
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
optionsBuilder.enableCollectionInDefaultFetchGroup( false );
return new SessionFactoryBuilderImpl( metadata, optionsBuilder, bootstrapContext );
}
);
}
@Test @Test
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne() { public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
final Person person = persistPersonWithManyToOne(); final Person person = persistPersonWithManyToOne(scope);
sqlInterceptor.clear();
// get a detached Person // get a detached Person
final Person detachedPerson = fromTransaction( final Person detachedPerson = scope.fromTransaction(
session -> session.get( Person.class, person.getId() ) session -> {
); final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
// loading Person should lead to one SQL Person p = session.get( Person.class, person.getId() );
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
// loading Person should lead to one SQL
statementInspector.assertExecutedCount( 1 );
return p;
}
);
// primaryAddress should be "initialized" as an enhanced-proxy // primaryAddress should be "initialized" as an enhanced-proxy
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
// alter the detached reference // alter the detached reference
detachedPerson.setName( "newName" ); detachedPerson.setName( "newName" );
final Person mergedPerson = fromTransaction( final Person mergedPerson = scope.fromTransaction(
session -> (Person) session.merge( detachedPerson ) session -> {
final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
Person merged = session.merge( detachedPerson );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) update Person
session.flush();
statementInspector.assertExecutedCount( 2 );
return merged;
}
); );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) update Person
assertThat( sqlInterceptor.getQueryCount(), is( 3 ) );
// primaryAddress should not be initialized // primaryAddress should not be initialized
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
assertEquals( "newName", mergedPerson.getName() ); assertEquals( "newName", mergedPerson.getName() );
} }
@Test @Test
public void testDeleteEnhancedEntityWithUninitializedManyToOne() { public void testDeleteEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
Person person = persistPersonWithManyToOne(); Person person = persistPersonWithManyToOne(scope);
sqlInterceptor.clear();
// get a detached Person // get a detached Person
Person detachedPerson = fromTransaction( Person detachedPerson = scope.fromTransaction(
session -> session.get( Person.class, person.getId() ) session -> {
); final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
Person p = session.get( Person.class, person.getId() );
// loading Person should lead to one SQL // loading Person should lead to one SQL
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) ); statementInspector.assertExecutedCount( 1 );
return p;
}
);
// primaryAddress should be initialized as an enhance-proxy // primaryAddress should be initialized as an enhance-proxy
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) ); assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
assertThat( detachedPerson, not( instanceOf( HibernateProxy.class ) ) ); assertThat( detachedPerson ).isNotInstanceOf( HibernateProxy.class );
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) ); assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
sqlInterceptor.clear();
// deleting detachedPerson should result in detachedPerson.primaryAddress being initialized, // deleting detachedPerson should result in detachedPerson.primaryAddress being initialized,
// so that the DELETE operation can be cascaded to it. // so that the DELETE operation can be cascaded to it.
inTransaction( scope.inTransaction(
session -> session.delete( detachedPerson ) session -> {
final SQLStatementInspector statementInspector = extractFromSession( session );
statementInspector.clear();
session.delete( detachedPerson );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) delete Person
// 4) select primary Address
session.flush();
statementInspector.assertExecutedCount( 4 );
}
); );
// 1) select Person#addresses
// 2) select Person#primaryAddress
// 3) delete Person
// 4) select primary Address
assertThat( sqlInterceptor.getQueryCount(), is( 4 ) );
// both the Person and its Address should be deleted // both the Person and its Address should be deleted
inTransaction( scope.inTransaction(
session -> { session -> {
assertNull( session.get( Person.class, person.getId() ) ); assertNull( session.get( Person.class, person.getId() ) );
assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) ); assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) );
@ -169,26 +166,18 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
} }
@Test @Test
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany() { public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
Person person = persistPersonWithOneToMany(); Person person = persistPersonWithOneToMany(scope);
// get a detached Person // get a detached Person
Person detachedPerson = TransactionUtil.doInHibernate( Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
this::sessionFactory, session -> {
return session.get( Person.class, person.getId() );
}
);
// address should not be initialized // address should not be initialized
assertFalse( Hibernate.isPropertyInitialized( detachedPerson, "addresses" ) ); assertFalse( Hibernate.isPropertyInitialized( detachedPerson, "addresses" ) );
detachedPerson.setName( "newName" ); detachedPerson.setName( "newName" );
Person mergedPerson = TransactionUtil.doInHibernate( Person mergedPerson = scope.fromTransaction( session -> session.merge( detachedPerson ) );
this::sessionFactory, session -> {
return (Person) session.merge( detachedPerson );
}
);
// address should be initialized // address should be initialized
assertTrue( Hibernate.isPropertyInitialized( mergedPerson, "addresses" ) ); assertTrue( Hibernate.isPropertyInitialized( mergedPerson, "addresses" ) );
@ -196,12 +185,11 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
} }
@Test @Test
public void testDeleteEnhancedEntityWithUninitializedOneToMany() { public void testDeleteEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
Person person = persistPersonWithOneToMany(); Person person = persistPersonWithOneToMany(scope);
// get a detached Person // get a detached Person
Person detachedPerson = TransactionUtil.doInHibernate( Person detachedPerson = scope.fromTransaction( session -> {
this::sessionFactory, session -> {
return session.get( Person.class, person.getId() ); return session.get( Person.class, person.getId() );
} }
); );
@ -211,22 +199,17 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
// deleting detachedPerson should result in detachedPerson.address being initialized, // deleting detachedPerson should result in detachedPerson.address being initialized,
// so that the DELETE operation can be cascaded to it. // so that the DELETE operation can be cascaded to it.
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.delete( detachedPerson ) );
this::sessionFactory, session -> {
session.delete( detachedPerson );
}
);
// both the Person and its Address should be deleted // both the Person and its Address should be deleted
TransactionUtil.doInHibernate( scope.inTransaction( session -> {
this::sessionFactory, session -> {
assertNull( session.get( Person.class, person.getId() ) ); assertNull( session.get( Person.class, person.getId() ) );
assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) ); assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) );
} }
); );
} }
public Person persistPersonWithManyToOne() { public Person persistPersonWithManyToOne(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
address.setDescription( "ABC" ); address.setDescription( "ABC" );
@ -234,16 +217,12 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
person.setName( "John Doe" ); person.setName( "John Doe" );
person.setPrimaryAddress( address ); person.setPrimaryAddress( address );
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.persist( person ) );
this::sessionFactory, session -> {
session.persist( person );
}
);
return person; return person;
} }
public Person persistPersonWithOneToMany() { public Person persistPersonWithOneToMany(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
address.setDescription( "ABC" ); address.setDescription( "ABC" );
@ -251,11 +230,7 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
person.setName( "John Doe" ); person.setName( "John Doe" );
person.getAddresses().add( address ); person.getAddresses().add( address );
TransactionUtil.doInHibernate( scope.inTransaction( session -> session.persist( person ) );
this::sessionFactory, session -> {
session.persist( person );
}
);
return person; return person;
} }

View File

@ -6,13 +6,13 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade; package org.hibernate.orm.test.bytecode.enhancement.cascade;
import org.hibernate.testing.TestForIssue; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.assertNull;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -22,28 +22,31 @@ import jakarta.persistence.Table;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-10252" ) @JiraKey( "HHH-10252" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
CascadeWithFkConstraintTest.Garage.class, CascadeWithFkConstraintTest.Car.class
}
)
@SessionFactory
@BytecodeEnhanced
public class CascadeWithFkConstraintTest {
private String garageId, car1Id, car2Id; private String garageId, car1Id, car2Id;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{Garage.class, Car.class};
}
@Before
public void prepare() {
// Create garage, add 2 cars to garage // Create garage, add 2 cars to garage
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
Garage garage = new Garage(); Garage garage = new Garage();
Car car1 = new Car(); Car car1 = new Car();
@ -62,23 +65,23 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
// Remove garage // Remove garage
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
Garage toRemoveGarage = em.find( Garage.class, garageId ); Garage toRemoveGarage = em.find( Garage.class, garageId );
em.remove( toRemoveGarage ); em.remove( toRemoveGarage );
} ); } );
// Check if there is no garage but cars are still present // Check if there is no garage but cars are still present
doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
Garage foundGarage = em.find( Garage.class, garageId ); Garage foundGarage = em.find( Garage.class, garageId );
Assert.assertNull( foundGarage ); assertNull( foundGarage );
Car foundCar1 = em.find( Car.class, car1Id ); Car foundCar1 = em.find( Car.class, car1Id );
Assert.assertEquals( car1Id, foundCar1.id ); assertEquals( car1Id, foundCar1.id );
Car foundCar2 = em.find( Car.class, car2Id ); Car foundCar2 = em.find( Car.class, car2Id );
Assert.assertEquals( car2Id, foundCar2.id ); assertEquals( car2Id, foundCar2.id );
} ); } );
} }
@ -86,7 +89,7 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "GARAGE" ) @Table( name = "GARAGE" )
private static class Garage { static class Garage {
@Id @Id
String id; String id;

View File

@ -17,9 +17,10 @@ import org.hibernate.orm.test.cascade.circle.Route;
import org.hibernate.orm.test.cascade.circle.Tour; import org.hibernate.orm.test.cascade.circle.Tour;
import org.hibernate.orm.test.cascade.circle.Transport; import org.hibernate.orm.test.cascade.circle.Transport;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import jakarta.persistence.PersistenceException; import jakarta.persistence.PersistenceException;
@ -33,7 +34,7 @@ import static org.junit.Assert.fail;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
*/ */
public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctionalTestCase { public abstract class AbstractMultiPathCircleCascadeTest {
private interface EntityOperation { private interface EntityOperation {
boolean isLegacy(); boolean isLegacy();
@ -80,23 +81,23 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
}; };
@Test @Test
public void testMergeEntityWithNonNullableTransientEntity() { public void testMergeEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
testEntityWithNonNullableTransientEntity( MERGE_OPERATION ); testEntityWithNonNullableTransientEntity( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveEntityWithNonNullableTransientEntity() { public void testSaveEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
testEntityWithNonNullableTransientEntity( SAVE_OPERATION ); testEntityWithNonNullableTransientEntity( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateEntityWithNonNullableTransientEntity() { public void testSaveUpdateEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
testEntityWithNonNullableTransientEntity( SAVE_UPDATE_OPERATION ); testEntityWithNonNullableTransientEntity( scope, SAVE_UPDATE_OPERATION );
} }
private void testEntityWithNonNullableTransientEntity( EntityOperation operation) { private void testEntityWithNonNullableTransientEntity(SessionFactoryScope scope, EntityOperation operation) {
Route route = getUpdatedDetachedEntity(); Route route = getUpdatedDetachedEntity( scope );
Node node = (Node) route.getNodes().iterator().next(); Node node = (Node) route.getNodes().iterator().next();
route.getNodes().remove( node ); route.getNodes().remove( node );
@ -106,7 +107,7 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
routeNew.getNodes().add( node ); routeNew.getNodes().add( node );
node.setRoute( routeNew ); node.setRoute( routeNew );
inSession( scope.inSession(
session -> { session -> {
session.beginTransaction(); session.beginTransaction();
try { try {
@ -131,28 +132,28 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeEntityWithNonNullableEntityNull() { public void testMergeEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
testEntityWithNonNullableEntityNull( MERGE_OPERATION ); testEntityWithNonNullableEntityNull( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveEntityWithNonNullableEntityNull() { public void testSaveEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
testEntityWithNonNullableEntityNull( SAVE_OPERATION ); testEntityWithNonNullableEntityNull( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateEntityWithNonNullableEntityNull() { public void testSaveUpdateEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
testEntityWithNonNullableEntityNull( SAVE_UPDATE_OPERATION ); testEntityWithNonNullableEntityNull( scope, SAVE_UPDATE_OPERATION );
} }
private void testEntityWithNonNullableEntityNull( EntityOperation operation) { private void testEntityWithNonNullableEntityNull(SessionFactoryScope scope, EntityOperation operation) {
Route route = getUpdatedDetachedEntity(); Route route = getUpdatedDetachedEntity( scope );
Node node = (Node) route.getNodes().iterator().next(); Node node = (Node) route.getNodes().iterator().next();
route.getNodes().remove( node ); route.getNodes().remove( node );
node.setRoute( null ); node.setRoute( null );
inSession( scope.inSession(
session -> { session -> {
session.beginTransaction(); session.beginTransaction();
try { try {
@ -176,26 +177,26 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeEntityWithNonNullablePropSetToNull() { public void testMergeEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
testEntityWithNonNullablePropSetToNull( MERGE_OPERATION ); testEntityWithNonNullablePropSetToNull( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveEntityWithNonNullablePropSetToNull() { public void testSaveEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
testEntityWithNonNullablePropSetToNull( SAVE_OPERATION ); testEntityWithNonNullablePropSetToNull( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateEntityWithNonNullablePropSetToNull() { public void testSaveUpdateEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
testEntityWithNonNullablePropSetToNull( SAVE_UPDATE_OPERATION ); testEntityWithNonNullablePropSetToNull( scope, SAVE_UPDATE_OPERATION );
} }
private void testEntityWithNonNullablePropSetToNull( EntityOperation operation) { private void testEntityWithNonNullablePropSetToNull(SessionFactoryScope scope, EntityOperation operation) {
Route route = getUpdatedDetachedEntity(); Route route = getUpdatedDetachedEntity( scope );
Node node = (Node) route.getNodes().iterator().next(); Node node = (Node) route.getNodes().iterator().next();
node.setName( null ); node.setName( null );
inSession( scope.inSession(
session -> { session -> {
session.beginTransaction(); session.beginTransaction();
@ -221,31 +222,31 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeRoute() { public void testMergeRoute(SessionFactoryScope scope) {
testRoute( MERGE_OPERATION ); testRoute( MERGE_OPERATION, scope );
} }
// skip SAVE_OPERATION since Route is not transient // skip SAVE_OPERATION since Route is not transient
@Test @Test
public void testSaveUpdateRoute() { public void testSaveUpdateRoute(SessionFactoryScope scope) {
testRoute( SAVE_UPDATE_OPERATION ); testRoute( SAVE_UPDATE_OPERATION, scope );
} }
private void testRoute( EntityOperation operation) { private void testRoute( EntityOperation operation, SessionFactoryScope scope) {
Route r = getUpdatedDetachedEntity(); Route r = getUpdatedDetachedEntity( scope );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> session ->
operation.doEntityOperation( r, session ) operation.doEntityOperation( r, session )
); );
assertInsertCount( 4 ); assertInsertCount( scope, 4 );
assertUpdateCount( 1 ); assertUpdateCount( scope, 1 );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
checkResults( route, true ); checkResults( route, true );
@ -254,27 +255,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergePickupNode() { public void testMergePickupNode(SessionFactoryScope scope) {
testPickupNode( MERGE_OPERATION ); testPickupNode( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSavePickupNode() { public void testSavePickupNode(SessionFactoryScope scope) {
testPickupNode( SAVE_OPERATION ); testPickupNode( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdatePickupNode() { public void testSaveUpdatePickupNode(SessionFactoryScope scope) {
testPickupNode( SAVE_UPDATE_OPERATION ); testPickupNode( scope, SAVE_UPDATE_OPERATION );
} }
private void testPickupNode( EntityOperation operation) { private void testPickupNode(SessionFactoryScope scope, EntityOperation operation) {
Route r = getUpdatedDetachedEntity(); Route r = getUpdatedDetachedEntity( scope );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> { session -> {
Iterator it = r.getNodes().iterator(); Iterator it = r.getNodes().iterator();
Node node = (Node) it.next(); Node node = (Node) it.next();
@ -292,10 +293,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
); );
assertInsertCount( 4 ); assertInsertCount( scope, 4 );
assertUpdateCount( 0 ); assertUpdateCount( scope, 0 );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
checkResults( route, false ); checkResults( route, false );
@ -304,27 +305,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeDeliveryNode() { public void testMergeDeliveryNode(SessionFactoryScope scope) {
testDeliveryNode( MERGE_OPERATION ); testDeliveryNode( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveDeliveryNode() { public void testSaveDeliveryNode(SessionFactoryScope scope) {
testDeliveryNode( SAVE_OPERATION ); testDeliveryNode( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateDeliveryNode() { public void testSaveUpdateDeliveryNode(SessionFactoryScope scope) {
testDeliveryNode( SAVE_UPDATE_OPERATION ); testDeliveryNode( scope, SAVE_UPDATE_OPERATION );
} }
private void testDeliveryNode( EntityOperation operation) { private void testDeliveryNode(SessionFactoryScope scope, EntityOperation operation) {
Route r = getUpdatedDetachedEntity(); Route r = getUpdatedDetachedEntity( scope );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> { session -> {
Iterator it = r.getNodes().iterator(); Iterator it = r.getNodes().iterator();
Node node = (Node) it.next(); Node node = (Node) it.next();
@ -343,10 +344,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
); );
assertInsertCount( 4 ); assertInsertCount( scope, 4 );
assertUpdateCount( 0 ); assertUpdateCount( scope, 0 );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
checkResults( route, false ); checkResults( route, false );
@ -355,35 +356,35 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeTour() { public void testMergeTour(SessionFactoryScope scope) {
testTour( MERGE_OPERATION ); testTour( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveTour() { public void testSaveTour(SessionFactoryScope scope) {
testTour( SAVE_OPERATION ); testTour( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateTour() { public void testSaveUpdateTour(SessionFactoryScope scope) {
testTour( SAVE_UPDATE_OPERATION ); testTour( scope, SAVE_UPDATE_OPERATION );
} }
private void testTour( EntityOperation operation) { private void testTour(SessionFactoryScope scope, EntityOperation operation) {
Route r = getUpdatedDetachedEntity(); Route r = getUpdatedDetachedEntity( scope );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> session ->
operation.doEntityOperation( ( (Node) r.getNodes().toArray()[0] ).getTour(), session ) operation.doEntityOperation( ( (Node) r.getNodes().toArray()[0] ).getTour(), session )
); );
assertInsertCount( 4 ); assertInsertCount( scope, 4 );
assertUpdateCount( 0 ); assertUpdateCount( scope, 0 );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
checkResults( route, false ); checkResults( route, false );
@ -392,27 +393,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeTransport() { public void testMergeTransport(SessionFactoryScope scope) {
testTransport( MERGE_OPERATION ); testTransport( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveTransport() { public void testSaveTransport(SessionFactoryScope scope) {
testTransport( SAVE_OPERATION ); testTransport( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateTransport() { public void testSaveUpdateTransport(SessionFactoryScope scope) {
testTransport( SAVE_UPDATE_OPERATION ); testTransport( scope, SAVE_UPDATE_OPERATION );
} }
private void testTransport( EntityOperation operation) { private void testTransport(SessionFactoryScope scope, EntityOperation operation) {
Route r = getUpdatedDetachedEntity(); Route r = getUpdatedDetachedEntity( scope );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> { session -> {
Transport transport; Transport transport;
Node node = ( (Node) r.getNodes().toArray()[0] ); Node node = ( (Node) r.getNodes().toArray()[0] );
@ -427,10 +428,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
); );
assertInsertCount( 4 ); assertInsertCount( scope, 4 );
assertUpdateCount( 0 ); assertUpdateCount( scope, 0 );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
checkResults( route, false ); checkResults( route, false );
@ -445,10 +446,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
return deliveryNode; return deliveryNode;
} }
private Route getUpdatedDetachedEntity() { private Route getUpdatedDetachedEntity(SessionFactoryScope scope) {
Route route = new Route(); Route route = new Route();
inTransaction( scope.inTransaction(
session -> { session -> {
route.setName( "routeA" ); route.setName( "routeA" );
@ -494,9 +495,9 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
return route; return route;
} }
@After @AfterEach
public void cleanup() { public void cleanup(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
session.createQuery( "delete from Transport" ); session.createQuery( "delete from Transport" );
session.createQuery( "delete from Tour" ); session.createQuery( "delete from Tour" );
@ -563,24 +564,24 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
@Test @Test
public void testMergeData3Nodes() { public void testMergeData3Nodes(SessionFactoryScope scope) {
testData3Nodes( MERGE_OPERATION ); testData3Nodes( scope, MERGE_OPERATION );
} }
@Test @Test
public void testSaveData3Nodes() { public void testSaveData3Nodes(SessionFactoryScope scope) {
testData3Nodes( SAVE_OPERATION ); testData3Nodes( scope, SAVE_OPERATION );
} }
@Test @Test
public void testSaveUpdateData3Nodes() { public void testSaveUpdateData3Nodes(SessionFactoryScope scope) {
testData3Nodes( SAVE_UPDATE_OPERATION ); testData3Nodes( scope, SAVE_UPDATE_OPERATION );
} }
private void testData3Nodes( EntityOperation operation) { private void testData3Nodes(SessionFactoryScope scope, EntityOperation operation) {
Route r = new Route(); Route r = new Route();
inTransaction( scope.inTransaction(
session -> { session -> {
r.setName( "routeA" ); r.setName( "routeA" );
@ -588,9 +589,9 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
); );
clearCounts(); clearCounts( scope );
inTransaction( scope.inTransaction(
session -> { session -> {
Route route = session.get( Route.class, r.getRouteID() ); Route route = session.get( Route.class, r.getRouteID() );
route.setName( "new routA" ); route.setName( "new routA" );
@ -651,8 +652,8 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
); );
assertInsertCount( 6 ); assertInsertCount( scope, 6 );
assertUpdateCount( 1 ); assertUpdateCount( scope, 1 );
} }
protected void checkExceptionFromNullValueForNonNullable( protected void checkExceptionFromNullValueForNonNullable(
@ -668,7 +669,7 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
} }
else { else {
assertTrue( ( ex instanceof JDBCException ) || ( ex.getCause() instanceof JDBCException ) ); Assertions.assertTrue( ( ex instanceof JDBCException ) || ( ex.getCause() instanceof JDBCException ) );
} }
} }
else { else {
@ -681,22 +682,22 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
} }
} }
protected void clearCounts() { protected void clearCounts(SessionFactoryScope scope) {
sessionFactory().getStatistics().clear(); scope.getSessionFactory().getStatistics().clear();
} }
protected void assertInsertCount(int expected) { protected void assertInsertCount(SessionFactoryScope scope, int expected) {
int inserts = (int) sessionFactory().getStatistics().getEntityInsertCount(); int inserts = (int) scope.getSessionFactory().getStatistics().getEntityInsertCount();
assertEquals( "unexpected insert count", expected, inserts ); Assertions.assertEquals( expected, inserts, "unexpected insert count" );
} }
protected void assertUpdateCount(int expected) { protected void assertUpdateCount(SessionFactoryScope scope, int expected) {
int updates = (int) sessionFactory().getStatistics().getEntityUpdateCount(); int updates = (int) scope.getSessionFactory().getStatistics().getEntityUpdateCount();
assertEquals( "unexpected update counts", expected, updates ); Assertions.assertEquals( expected, updates, "unexpected update counts" );
} }
protected void assertDeleteCount(int expected) { protected void assertDeleteCount(SessionFactoryScope scope, int expected) {
int deletes = (int) sessionFactory().getStatistics().getEntityDeleteCount(); int deletes = (int) scope.getSessionFactory().getStatistics().getEntityDeleteCount();
assertEquals( "unexpected delete counts", expected, deletes ); Assertions.assertEquals( expected, deletes, "unexpected delete counts" );
} }
} }

View File

@ -6,32 +6,34 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
@Setting( name = AvailableSettings.CHECK_NULLABILITY, value = "false" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeCheckNullFalseDelayedInsertTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeCheckNullFalseDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
configuration.setProperty( Environment.CHECK_NULLABILITY, false );
}
} }

View File

@ -6,32 +6,35 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
@Setting( name = AvailableSettings.CHECK_NULLABILITY, value = "false" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeCheckNullTrueDelayedInsertTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeCheckNullTrueDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
configuration.setProperty( Environment.CHECK_NULLABILITY, true );
}
} }

View File

@ -6,33 +6,35 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
@Setting( name = AvailableSettings.CHECK_NULLABILITY, value = "false" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeCheckNullibilityFalseTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeCheckNullibilityFalseTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
configuration.setProperty( Environment.CHECK_NULLABILITY, false );
}
} }

View File

@ -6,32 +6,35 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
@Setting( name = AvailableSettings.CHECK_NULLABILITY, value = "false" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeCheckNullibilityTrueTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeCheckNullibilityTrueTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
configuration.setProperty( Environment.CHECK_NULLABILITY, true );
}
} }

View File

@ -6,31 +6,34 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeDelayedInsertTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascadeDelayedInsert.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
}
} }

View File

@ -6,14 +6,16 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle; package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.junit.runner.RunWith; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
/** /**
* The test case uses the following model: * The test case uses the following model:
@ -37,19 +39,20 @@ import org.junit.runner.RunWith;
* *
* @author Pavol Zibrita, Gail Badner * @author Pavol Zibrita, Gail Badner
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "0" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class MultiPathCircleCascadeTest extends AbstractMultiPathCircleCascadeTest { public class MultiPathCircleCascadeTest extends AbstractMultiPathCircleCascadeTest {
@Override
protected String[] getOrmXmlFiles() {
return new String[] {
"org/hibernate/orm/test/cascade/circle/MultiPathCircleCascade.hbm.xml"
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( Environment.GENERATE_STATISTICS, true );
configuration.setProperty( Environment.STATEMENT_BATCH_SIZE, 0 );
}
} }

View File

@ -3,11 +3,11 @@ package org.hibernate.orm.test.bytecode.enhancement.collectionelement.flush;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import jakarta.persistence.CollectionTable; import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -16,24 +16,26 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(BytecodeEnhancerRunner.class) import org.junit.jupiter.api.Test;
@TestForIssue(jiraKey = "HHH-16337")
public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = {
ElementCollectionFlushAfterQueryTest.MyEntity.class,
ElementCollectionFlushAfterQueryTest.MyOtherEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
@JiraKey("HHH-16337")
public class ElementCollectionFlushAfterQueryTest {
private static final Long MY_ENTITY_ID = 1l; private static final Long MY_ENTITY_ID = 1l;
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
MyEntity.class,
MyOtherEntity.class
};
}
@Test @Test
public void testAutoFlush() { public void testAutoFlush(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" ); MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" );
myEntity.addRedirectUris( "1" ); myEntity.addRedirectUris( "1" );
@ -41,7 +43,7 @@ public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTest
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID ); MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
@ -53,7 +55,7 @@ public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTest
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID ); MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
Set<String> redirectUris = myEntity.getRedirectUris(); Set<String> redirectUris = myEntity.getRedirectUris();

View File

@ -6,82 +6,74 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate; package org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate.BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest.MyEntity;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.After; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OrderColumn; import jakarta.persistence.OrderColumn;
import static org.assertj.core.api.Assertions.assertThat; @DomainModel(
import static org.junit.Assert.assertTrue; annotatedClasses = {
MyEntity.class,
@RunWith(BytecodeEnhancerRunner.class) }
)
@SessionFactory
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
@EnhancementOptions(lazyLoading = true) @EnhancementOptions(lazyLoading = true)
@TestForIssue(jiraKey = "HHH-14387") @JiraKey("HHH-14387")
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest {
extends BaseNonConfigCoreFunctionalTestCase {
@Override @BeforeEach
protected Class[] getAnnotatedClasses() { public void check(SessionFactoryScope scope) {
return new Class[] { scope.inSession(
MyEntity.class
};
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( true );
}
@Before
public void check() {
inSession(
session -> session ->
assertTrue( session.getSessionFactory().getSessionFactoryOptions() assertTrue( session.getSessionFactory().getSessionFactoryOptions()
.isCollectionsInDefaultFetchGroupEnabled() ) .isCollectionsInDefaultFetchGroupEnabled() )
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session ->
session.createQuery( "delete from myentity" ).executeUpdate() session.createQuery( "delete from myentity" ).executeUpdate()
); );
} }
@Test @Test
public void testRecreateCollection() { public void testRecreateCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -89,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testRecreateCollectionFind() { public void testRecreateCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -111,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testDeleteCollection() { public void testDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -132,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testDeleteCollectionFind() { public void testDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -153,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollection() { public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.get( MyEntity.class, 1 ) session.get( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );
@ -174,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() { public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.find( MyEntity.class, 1 ) session.find( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );

View File

@ -6,80 +6,74 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate; package org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.orm.test.bytecode.enhancement.collectionelement.recreate.BytecodeEnhancementElementCollectionRecreateTest.MyEntity;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.After; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OrderColumn; import jakarta.persistence.OrderColumn;
import static org.assertj.core.api.Assertions.assertThat; @DomainModel(
import static org.junit.Assert.assertFalse; annotatedClasses = {
MyEntity.class,
@RunWith(BytecodeEnhancerRunner.class) }
)
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
@BytecodeEnhanced
@EnhancementOptions(lazyLoading = true) @EnhancementOptions(lazyLoading = true)
@TestForIssue(jiraKey = "HHH-14387") @JiraKey("HHH-14387")
public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonConfigCoreFunctionalTestCase { public class BytecodeEnhancementElementCollectionRecreateTest {
@Override @BeforeEach
protected Class[] getAnnotatedClasses() { public void check(SessionFactoryScope scope) {
return new Class[] { scope.inSession(
MyEntity.class
};
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( false );
}
@Before
public void check() {
inSession(
session -> session ->
assertFalse( session.getSessionFactory().getSessionFactoryOptions() assertFalse( session.getSessionFactory().getSessionFactoryOptions()
.isCollectionsInDefaultFetchGroupEnabled() ) .isCollectionsInDefaultFetchGroupEnabled() )
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session ->
session.createQuery( "delete from myentity" ).executeUpdate() session.createQuery( "delete from myentity" ).executeUpdate()
); );
} }
@Test @Test
public void testRecreateCollection() { public void testRecreateCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -87,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testRecreateCollectionFind() { public void testRecreateCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( Arrays.asList( "two", "three" ) ); entity.setElements( Arrays.asList( "two", "three" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "two", "three" ); .containsExactlyInAnyOrder( "two", "three" );
@ -109,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testDeleteCollection() { public void testDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -130,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testDeleteCollectionFind() { public void testDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
entity.setElements( new ArrayList<>() ); entity.setElements( new ArrayList<>() );
} ); } );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.isEmpty(); .isEmpty();
@ -151,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollection() { public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.get( MyEntity.class, 1 ) session.get( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.get( MyEntity.class, 1 ); MyEntity entity = session.get( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );
@ -172,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
} }
@Test @Test
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() { public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = new MyEntity(); MyEntity entity = new MyEntity();
entity.setId( 1 ); entity.setId( 1 );
entity.setElements( Arrays.asList( "one", "two", "four" ) ); entity.setElements( Arrays.asList( "one", "two", "four" ) );
session.persist( entity ); session.persist( entity );
} ); } );
inTransaction( session -> scope.inTransaction( session ->
session.find( MyEntity.class, 1 ) session.find( MyEntity.class, 1 )
); );
inTransaction( session -> { scope.inTransaction( session -> {
MyEntity entity = session.find( MyEntity.class, 1 ); MyEntity entity = session.find( MyEntity.class, 1 );
assertThat( entity.getElements() ) assertThat( entity.getElements() )
.containsExactlyInAnyOrder( "one", "two", "four" ); .containsExactlyInAnyOrder( "one", "two", "four" );

View File

@ -13,39 +13,37 @@ import org.hibernate.orm.test.deletetransient.Note;
import org.hibernate.orm.test.deletetransient.Person; import org.hibernate.orm.test.deletetransient.Person;
import org.hibernate.orm.test.deletetransient.Suite; import org.hibernate.orm.test.deletetransient.Suite;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
xmlMappings = {
"org/hibernate/orm/test/deletetransient/Person.hbm.xml"
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase { public class DeleteTransientEntityTest {
@Override @AfterEach
protected String getBaseForMappings() { void tearDown(SessionFactoryScope scope) {
return "org/hibernate/orm/test/"; scope.inTransaction( session -> session.createQuery( "from java.lang.Object", Object.class ).list().forEach( session::remove ) );
}
@Override
public String[] getMappings() {
return new String[] { "deletetransient/Person.hbm.xml" };
}
@Override
protected boolean isCleanupTestDataRequired() {
return true;
} }
@Test @Test
public void testTransientEntityDeletionNoCascades() { public void testTransientEntityDeletionNoCascades(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
session.remove( new Address() ); session.remove( new Address() );
} }
@ -53,8 +51,8 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testTransientEntityDeletionCascadingToTransientAssociation() { public void testTransientEntityDeletionCascadingToTransientAssociation(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person p = new Person(); Person p = new Person();
p.getAddresses().add( new Address() ); p.getAddresses().add( new Address() );
@ -64,8 +62,8 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testTransientEntityDeleteCascadingToCircularity() { public void testTransientEntityDeleteCascadingToCircularity(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person p1 = new Person(); Person p1 = new Person();
Person p2 = new Person(); Person p2 = new Person();
@ -77,16 +75,16 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testTransientEntityDeletionCascadingToDetachedAssociation() { public void testTransientEntityDeletionCascadingToDetachedAssociation(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
inTransaction( scope.inTransaction(
session -> { session -> {
address.setInfo( "123 Main St." ); address.setInfo( "123 Main St." );
session.persist( address ); session.persist( address );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person p = new Person(); Person p = new Person();
p.getAddresses().add( address ); p.getAddresses().add( address );
@ -94,18 +92,18 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 ); Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 );
assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue() ); assertEquals( 0, count.longValue(), "delete not cascaded properly across transient entity" );
} }
); );
} }
@Test @Test
public void testTransientEntityDeletionCascadingToPersistentAssociation() { public void testTransientEntityDeletionCascadingToPersistentAssociation(SessionFactoryScope scope) {
Long id = fromTransaction( Long id = scope.fromTransaction(
session -> { session -> {
Address address = new Address(); Address address = new Address();
address.setInfo( "123 Main St." ); address.setInfo( "123 Main St." );
@ -114,7 +112,7 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Address address = session.get( Address.class, id ); Address address = session.get( Address.class, id );
Person p = new Person(); Person p = new Person();
@ -123,20 +121,20 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 ); Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 );
assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue() ); assertEquals( 0, count.longValue(), "delete not cascaded properly across transient entity" );
} }
); );
} }
@Test @Test
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public void testCascadeAllFromClearedPersistentAssnToTransientEntity() { public void testCascadeAllFromClearedPersistentAssnToTransientEntity(SessionFactoryScope scope) {
final Person p = new Person(); final Person p = new Person();
Address address = new Address(); Address address = new Address();
inTransaction( scope.inTransaction(
session -> { session -> {
address.setInfo( "123 Main St." ); address.setInfo( "123 Main St." );
p.getAddresses().add( address ); p.getAddresses().add( address );
@ -144,7 +142,7 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Suite suite = new Suite(); Suite suite = new Suite();
address.getSuites().add( suite ); address.getSuites().add( suite );
@ -153,10 +151,10 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.get( p.getClass(), p.getId() ); Person person = session.get( p.getClass(), p.getId() );
assertEquals( "persistent collection not cleared", 0, person.getAddresses().size() ); assertEquals( 0, person.getAddresses().size(), "persistent collection not cleared" );
Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 ); Long count = (Long) session.createQuery( "select count(*) from Address" ).list().get( 0 );
assertEquals( 1, count.longValue() ); assertEquals( 1, count.longValue() );
count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 ); count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 );
@ -167,19 +165,19 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
@Test @Test
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() { public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity(SessionFactoryScope scope) {
Address address = new Address(); Address address = new Address();
address.setInfo( "123 Main St." ); address.setInfo( "123 Main St." );
Suite suite = new Suite(); Suite suite = new Suite();
address.getSuites().add( suite ); address.getSuites().add( suite );
inTransaction( scope.inTransaction(
session -> { session -> {
session.save( address ); session.save( address );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Note note = new Note(); Note note = new Note();
note.setDescription( "a description" ); note.setDescription( "a description" );
@ -190,13 +188,13 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Long count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 ); Long count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 );
assertEquals( assertEquals(
"all-delete-orphan not cascaded properly to cleared persistent collection entities",
0, 0,
count.longValue() count.longValue(),
"all-delete-orphan not cascaded properly to cleared persistent collection entities"
); );
count = (Long) session.createQuery( "select count(*) from Note" ).list().get( 0 ); count = (Long) session.createQuery( "select count(*) from Note" ).list().get( 0 );
assertEquals( 0, count.longValue() ); assertEquals( 0, count.longValue() );

View File

@ -1,45 +1,48 @@
package org.hibernate.orm.test.bytecode.enhancement.detached; package org.hibernate.orm.test.bytecode.enhancement.detached;
import org.hibernate.SessionFactory; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.transaction.TransactionUtil; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.junit.Assert.assertNotNull; import org.hibernate.SessionFactory;
import org.junit.jupiter.api.Test;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-11426" ) @JiraKey( "HHH-11426" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DetachedGetIdentifierTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
DetachedGetIdentifierTest.SimpleEntity.class
@Override }
public Class<?>[] getAnnotatedClasses() { )
return new Class<?>[]{SimpleEntity.class}; @org.hibernate.testing.orm.junit.SessionFactory
} @BytecodeEnhanced
public class DetachedGetIdentifierTest {
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
SimpleEntity[] entities = new SimpleEntity[2]; SimpleEntity[] entities = new SimpleEntity[2];
entities[0] = new SimpleEntity(); entities[0] = new SimpleEntity();
entities[0].name = "test"; entities[0].name = "test";
TransactionUtil.doInJPA( this::sessionFactory, em -> { scope.inTransaction( em -> {
entities[1] = em.merge( entities[0] ); entities[1] = em.merge( entities[0] );
assertNotNull( em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier( entities[1] ) ); assertNotNull( em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier( entities[1] ) );
} ); } );
// Call as detached entity // Call as detached entity
try ( SessionFactory sessionFactory = sessionFactory() ) { try ( SessionFactory sessionFactory = scope.getSessionFactory() ) {
assertNotNull( sessionFactory.getPersistenceUnitUtil().getIdentifier( entities[1] ) ); assertNotNull( sessionFactory.getPersistenceUnitUtil().getIdentifier( entities[1] ) );
} }
} }
@ -48,7 +51,7 @@ public class DetachedGetIdentifierTest extends BaseCoreFunctionalTestCase {
@Entity(name = "SimpleEntity") @Entity(name = "SimpleEntity")
@Table( name = "SIMPLE_ENTITY" ) @Table( name = "SIMPLE_ENTITY" )
private static class SimpleEntity { static class SimpleEntity {
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -12,14 +12,14 @@ import java.util.List;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.transaction.TransactionUtil; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.AfterEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -34,27 +34,25 @@ import jakarta.persistence.OneToMany;
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue(jiraKey = "HHH-14387") @TestForIssue(jiraKey = "HHH-14387")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
annotatedClasses = {
RemoveUninitializedLazyCollectionTest.Parent.class,
RemoveUninitializedLazyCollectionTest.Child1.class,
RemoveUninitializedLazyCollectionTest.Child2.class
}
)
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions( @EnhancementOptions(
lazyLoading = true, lazyLoading = true,
inlineDirtyChecking = true, inlineDirtyChecking = true,
biDirectionalAssociationManagement = true biDirectionalAssociationManagement = true
) )
public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTestCase { public class RemoveUninitializedLazyCollectionTest {
@Override @AfterEach
public Class<?>[] getAnnotatedClasses() { public void tearDown(SessionFactoryScope scope) {
return new Class<?>[]{ scope.inTransaction(
Parent.class,
Child1.class,
Child2.class
};
}
@After
public void tearDown() {
TransactionUtil.doInJPA(
this::sessionFactory,
session -> { session -> {
session.createQuery( "delete from Child1" ).executeUpdate(); session.createQuery( "delete from Child1" ).executeUpdate();
session.createQuery( "delete from Child2" ).executeUpdate(); session.createQuery( "delete from Child2" ).executeUpdate();
@ -63,11 +61,10 @@ public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTes
); );
} }
@Before @BeforeEach
public void setup() { public void setup(SessionFactoryScope scope) {
Parent parent = new Parent( 1L, "test" ); Parent parent = new Parent( 1L, "test" );
TransactionUtil.doInJPA( scope.inTransaction(
this::sessionFactory,
entityManager -> { entityManager -> {
entityManager.persist( parent ); entityManager.persist( parent );
entityManager.persist( new Child2( 1L, "child2", parent ) ); entityManager.persist( new Child2( 1L, "child2", parent ) );
@ -76,8 +73,8 @@ public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTes
} }
@Test @Test
public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef() { public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef(SessionFactoryScope scope) {
EntityManager em = sessionFactory().createEntityManager(); EntityManager em = scope.getSessionFactory().createEntityManager();
try { try {
// Lazily initialize the child1 collection // Lazily initialize the child1 collection
List<Child1> child1 = em.find( Parent.class, 1L ).getChild1(); List<Child1> child1 = em.find( Parent.class, 1L ).getChild1();

View File

@ -6,34 +6,32 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.hibernate.boot.internal.SessionFactoryBuilderImpl;
import org.hibernate.boot.internal.SessionFactoryOptionsBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.SessionFactoryBuilderService;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
@ -46,35 +44,23 @@ import jakarta.persistence.Table;
* *
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue( jiraKey = "HHH-14348" ) @JiraKey( "HHH-14348" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
DirtyTrackingCollectionInDefaultFetchGroupFalseTest.StringsEntity.class
}
)
@SessionFactory(
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
applyCollectionsInDefaultFetchGroup = false
)
@BytecodeEnhanced
public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{StringsEntity.class}; scope.inTransaction( em -> {
}
@Override
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addService(
SessionFactoryBuilderService.class,
(SessionFactoryBuilderService) (metadata, bootstrapContext) -> {
SessionFactoryOptionsBuilder optionsBuilder = new SessionFactoryOptionsBuilder(
metadata.getMetadataBuildingOptions().getServiceRegistry(),
bootstrapContext
);
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
optionsBuilder.enableCollectionInDefaultFetchGroup( false );
return new SessionFactoryBuilderImpl( metadata, optionsBuilder, bootstrapContext );
}
);
}
@Before
public void prepare() {
doInJPA( this::sessionFactory, em -> {
StringsEntity entity = new StringsEntity(); StringsEntity entity = new StringsEntity();
entity.id = 1L; entity.id = 1L;
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) ); entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
@ -83,8 +69,8 @@ public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCor
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
entityManager.flush(); entityManager.flush();
BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity ) BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity )
@ -98,13 +84,14 @@ public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCor
// --- // // --- //
@Entity @Entity
@Table( name = "STRINGS_ENTITY" ) @Table(name = "STRINGS_ENTITY")
private static class StringsEntity { static class StringsEntity {
@Id @Id
Long id; Long id;
@ElementCollection @ElementCollection
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
List<String> someStrings; List<String> someStrings;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)

View File

@ -11,53 +11,48 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
/** /**
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue( jiraKey = "HHH-14348" ) @JiraKey( "HHH-14348" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfigCoreFunctionalTestCase { annotatedClasses = {
DirtyTrackingCollectionInDefaultFetchGroupTest.StringsEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
public class DirtyTrackingCollectionInDefaultFetchGroupTest {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{StringsEntity.class}; assertTrue( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
} scope.inTransaction( em -> {
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( true );
}
@Before
public void prepare() {
assertTrue( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
doInJPA( this::sessionFactory, em -> {
StringsEntity entity = new StringsEntity(); StringsEntity entity = new StringsEntity();
entity.id = 1L; entity.id = 1L;
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) ); entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
@ -66,8 +61,8 @@ public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfi
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
entityManager.flush(); entityManager.flush();
@ -88,12 +83,13 @@ public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfi
@Entity @Entity
@Table( name = "STRINGS_ENTITY" ) @Table( name = "STRINGS_ENTITY" )
private static class StringsEntity { static class StringsEntity {
@Id @Id
Long id; Long id;
@ElementCollection @ElementCollection
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
List<String> someStrings; List<String> someStrings;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)

View File

@ -11,53 +11,50 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
/** /**
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue( jiraKey = "HHH-14348" ) @JiraKey( "HHH-14348" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonConfigCoreFunctionalTestCase { annotatedClasses = {
DirtyTrackingCollectionNotInDefaultFetchGroupTest.StringsEntity.class
}
)
@SessionFactory(
applyCollectionsInDefaultFetchGroup = false
)
@BytecodeEnhanced
public class DirtyTrackingCollectionNotInDefaultFetchGroupTest {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{StringsEntity.class}; assertFalse( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
} scope.inTransaction( em -> {
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( false );
}
@Before
public void prepare() {
assertFalse( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
doInJPA( this::sessionFactory, em -> {
StringsEntity entity = new StringsEntity(); StringsEntity entity = new StringsEntity();
entity.id = 1L; entity.id = 1L;
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) ); entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
@ -66,8 +63,8 @@ public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonCo
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
entityManager.flush(); entityManager.flush();
BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity ) BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity )
@ -82,12 +79,13 @@ public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonCo
@Entity @Entity
@Table( name = "STRINGS_ENTITY" ) @Table( name = "STRINGS_ENTITY" )
private static class StringsEntity { static class StringsEntity {
@Id @Id
Long id; Long id;
@ElementCollection @ElementCollection
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
List<String> someStrings; List<String> someStrings;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)

View File

@ -6,12 +6,13 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -21,24 +22,24 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-11293" ) @JiraKey( "HHH-11293" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
DirtyTrackingCollectionTest.StringsEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
public class DirtyTrackingCollectionTest {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{StringsEntity.class}; scope.inTransaction( em -> {
}
@Before
public void prepare() {
doInJPA( this::sessionFactory, em -> {
StringsEntity entity = new StringsEntity(); StringsEntity entity = new StringsEntity();
entity.id = 1L; entity.id = 1L;
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) ); entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
@ -47,25 +48,25 @@ public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
entity.someStrings.clear(); entity.someStrings.clear();
} ); } );
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
assertEquals( 0, entity.someStrings.size() ); assertEquals( 0, entity.someStrings.size() );
entity.someStrings.add( "d" ); entity.someStrings.add( "d" );
} ); } );
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
assertEquals( 1, entity.someStrings.size() ); assertEquals( 1, entity.someStrings.size() );
entity.someStrings = new ArrayList<>(); entity.someStrings = new ArrayList<>();
} ); } );
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
StringsEntity entity = entityManager.find( StringsEntity.class, 1L ); StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
assertEquals( 0, entity.someStrings.size() ); assertEquals( 0, entity.someStrings.size() );
} ); } );
@ -75,7 +76,7 @@ public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "STRINGS_ENTITY" ) @Table( name = "STRINGS_ENTITY" )
private static class StringsEntity { static class StringsEntity {
@Id @Id
Long id; Long id;

View File

@ -4,12 +4,13 @@ import java.util.List;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
@ -23,26 +24,29 @@ import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
DirtyTrackingDynamicUpdateAndInheritanceTest.SuperEntity.class,
DirtyTrackingDynamicUpdateAndInheritanceTest.ChildEntity.class,
DirtyTrackingDynamicUpdateAndInheritanceTest.AbstractVersion.class,
DirtyTrackingDynamicUpdateAndInheritanceTest.FileVersion.class
}
)
@SessionFactory(
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
applyCollectionsInDefaultFetchGroup = false
)
@BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFunctionalTestCase { public class DirtyTrackingDynamicUpdateAndInheritanceTest {
public static final int ID = 1; public static final int ID = 1;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
SuperEntity.class,
ChildEntity.class,
AbstractVersion.class,
FileVersion.class
};
}
@Test @Test
@JiraKey("HHH-16688") @JiraKey("HHH-16688")
public void testDynamicUpdateWithInheritance() { public void testDynamicUpdateWithInheritance(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
ChildEntity entity = new ChildEntity( ID ); ChildEntity entity = new ChildEntity( ID );
entity.setaSuper( "aSuper before" ); entity.setaSuper( "aSuper before" );
@ -58,7 +62,7 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
String aChildNewValue = "aChild after"; String aChildNewValue = "aChild after";
String bChildNewValue = "bChild after"; String bChildNewValue = "bChild after";
inTransaction( scope.inTransaction(
session -> { session -> {
ChildEntity entity = session.find( ChildEntity.class, ID ); ChildEntity entity = session.find( ChildEntity.class, ID );
entity.setaSuper( aSuperNewValue ); entity.setaSuper( aSuperNewValue );
@ -69,7 +73,7 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
ChildEntity entity = session.find( ChildEntity.class, ID ); ChildEntity entity = session.find( ChildEntity.class, ID );
assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue ); assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue );
@ -82,9 +86,8 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
@Test @Test
@JiraKey("HHH-16379") @JiraKey("HHH-16379")
public void testWithDynamicUpdate() { public void testWithDynamicUpdate(SessionFactoryScope scope) {
scope.inTransaction(
inTransaction(
session -> { session -> {
FileVersion version = new FileVersion(); FileVersion version = new FileVersion();
version.setId( "1" ); version.setId( "1" );

View File

@ -1,33 +1,35 @@
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
DirtyTrackingDynamicUpdateTest.TestEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions(inlineDirtyChecking = true) @EnhancementOptions(inlineDirtyChecking = true)
@JiraKey("HHH-16688") @JiraKey("HHH-16688")
public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase { public class DirtyTrackingDynamicUpdateTest {
public static final int ID = 1; public static final int ID = 1;
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class<?>[] { TestEntity.class }; scope.inTransaction(
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
TestEntity testEntity = new TestEntity( ID ); TestEntity testEntity = new TestEntity( ID );
@ -41,14 +43,14 @@ public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testDynamicUpdate() { public void testDynamicUpdate(SessionFactoryScope scope) {
String aSuperNewValue = "aSuper after"; String aSuperNewValue = "aSuper after";
String bSuperNewValue = "bSuper after"; String bSuperNewValue = "bSuper after";
String aChildNewValue = "aChild after"; String aChildNewValue = "aChild after";
String bChildNewValue = "bChild after"; String bChildNewValue = "bChild after";
inTransaction( scope.inTransaction(
session -> { session -> {
TestEntity entity = session.find( TestEntity.class, ID ); TestEntity entity = session.find( TestEntity.class, ID );
entity.setaSuper( aSuperNewValue ); entity.setaSuper( aSuperNewValue );
@ -59,7 +61,7 @@ public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
TestEntity entity = session.find( TestEntity.class, ID ); TestEntity entity = session.find( TestEntity.class, ID );
assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue ); assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue );

View File

@ -6,11 +6,10 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -19,7 +18,7 @@ import jakarta.persistence.Id;
@JiraKey( "HHH-16774" ) @JiraKey( "HHH-16774" )
@JiraKey( "HHH-16952" ) @JiraKey( "HHH-16952" )
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class DirtyTrackingEmbeddableTest { public class DirtyTrackingEmbeddableTest {
@Test @Test

View File

@ -6,13 +6,11 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.Jira;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -24,7 +22,7 @@ import jakarta.persistence.MappedSuperclass;
* @author Yoann Rodière * @author Yoann Rodière
* @author Marco Belladelli * @author Marco Belladelli
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
@EnhancementOptions( inlineDirtyChecking = true ) @EnhancementOptions( inlineDirtyChecking = true )
@Jira( "https://hibernate.atlassian.net/browse/HHH-16459" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-16459" )
public class DirtyTrackingInheritanceTest { public class DirtyTrackingInheritanceTest {

View File

@ -6,12 +6,11 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.Jira;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -23,7 +22,7 @@ import jakarta.persistence.MappedSuperclass;
* @author Yoann Rodière * @author Yoann Rodière
* @author Marco Belladelli * @author Marco Belladelli
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
@EnhancementOptions( inlineDirtyChecking = true ) @EnhancementOptions( inlineDirtyChecking = true )
@Jira( "https://hibernate.atlassian.net/browse/HHH-16459" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-16459" )
public class DirtyTrackingInheritanceWithGenericsTest { public class DirtyTrackingInheritanceWithGenericsTest {

View File

@ -6,11 +6,12 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -20,23 +21,22 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.persistence.Version; import jakarta.persistence.Version;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-12051" ) @JiraKey( "HHH-12051" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class DirtyTrackingNonUpdateableTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
DirtyTrackingNonUpdateableTest.Thing.class
@Override }
public Class<?>[] getAnnotatedClasses() { )
return new Class<?>[]{Thing.class}; @SessionFactory
} @BytecodeEnhanced
public class DirtyTrackingNonUpdateableTest {
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInJPA( this::sessionFactory, entityManager -> { scope.inTransaction( entityManager -> {
Thing thing = new Thing(); Thing thing = new Thing();
entityManager.persist( thing ); entityManager.persist( thing );

View File

@ -11,15 +11,13 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
@ -36,40 +34,37 @@ import jakarta.persistence.OrderColumn;
import jakarta.persistence.Temporal; import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType; import jakarta.persistence.TemporalType;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse;
import org.junit.jupiter.api.Test;
/** /**
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue(jiraKey = "HHH-14360") @JiraKey("HHH-14360")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
DirtyTrackingNotInDefaultFetchGroupPersistTest.HotherEntity.class,
DirtyTrackingNotInDefaultFetchGroupPersistTest.Hentity.class
}
)
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
@BytecodeEnhanced
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class DirtyTrackingNotInDefaultFetchGroupPersistTest extends BaseNonConfigCoreFunctionalTestCase { public class DirtyTrackingNotInDefaultFetchGroupPersistTest {
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { HotherEntity.class, Hentity.class };
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( false );
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
assertFalse( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() ); assertFalse( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
Hentity hentity = new Hentity(); Hentity hentity = new Hentity();
HotherEntity hotherEntity = new HotherEntity(); HotherEntity hotherEntity = new HotherEntity();
hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) ); hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) );
hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) ); hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.persist( hentity ); session.persist( hentity );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
hentity.bumpNumber(); hentity.bumpNumber();
session.saveOrUpdate( hentity ); session.saveOrUpdate( hentity );
} ); } );

View File

@ -25,50 +25,46 @@ import jakarta.persistence.OrderColumn;
import jakarta.persistence.Temporal; import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType; import jakarta.persistence.TemporalType;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/** /**
* @author Christian Beikov * @author Christian Beikov
*/ */
@TestForIssue(jiraKey = "HHH-14360") @JiraKey("HHH-14360")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
DirtyTrackingPersistTest.HotherEntity.class, DirtyTrackingPersistTest.Hentity.class
}
)
@SessionFactory
@BytecodeEnhanced
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class DirtyTrackingPersistTest extends BaseNonConfigCoreFunctionalTestCase { public class DirtyTrackingPersistTest {
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { HotherEntity.class, Hentity.class };
}
@Override
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
super.configureSessionFactoryBuilder( sfb );
sfb.applyCollectionsInDefaultFetchGroup( true );
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
assertTrue( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() ); assertTrue( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
Hentity hentity = new Hentity(); Hentity hentity = new Hentity();
HotherEntity hotherEntity = new HotherEntity(); HotherEntity hotherEntity = new HotherEntity();
hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) ); hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) );
hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) ); hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.persist( hentity ); session.persist( hentity );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
hentity.bumpNumber(); hentity.bumpNumber();
session.saveOrUpdate( hentity ); session.saveOrUpdate( hentity );
} ); } );

View File

@ -6,10 +6,9 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.dirty; package org.hibernate.orm.test.bytecode.enhancement.dirty;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils; import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
import org.junit.Test; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -24,7 +23,7 @@ import java.util.Set;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @BytecodeEnhanced
public class DirtyTrackingTest { public class DirtyTrackingTest {
@Test @Test

View File

@ -5,12 +5,13 @@ import java.time.LocalDate;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -20,23 +21,22 @@ import jakarta.persistence.OneToOne;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class DynamicUpdateTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
DynamicUpdateTest.Payment.class,
DynamicUpdateTest.StuffToPay.class
}
)
@SessionFactory
@BytecodeEnhanced
public class DynamicUpdateTest {
public static final Long STUFF_TO_PAY_ID = 1l; public static final Long STUFF_TO_PAY_ID = 1l;
public static final Long PAYMENT_ID = 2l; public static final Long PAYMENT_ID = 2l;
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
Payment.class,
StuffToPay.class
};
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
Payment payment = new Payment(PAYMENT_ID); Payment payment = new Payment(PAYMENT_ID);
payment.setFee( new BigDecimal( 42 ) ); payment.setFee( new BigDecimal( 42 ) );
@ -51,8 +51,8 @@ public class DynamicUpdateTest extends BaseCoreFunctionalTestCase {
@Test @Test
@JiraKey("HHH-16577") @JiraKey("HHH-16577")
public void testSetAttribute() { public void testSetAttribute(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
StuffToPay stuffToPay = session.find( StuffToPay.class, STUFF_TO_PAY_ID ); StuffToPay stuffToPay = session.find( StuffToPay.class, STUFF_TO_PAY_ID );
stuffToPay.confirmPayment(); stuffToPay.confirmPayment();
@ -61,7 +61,7 @@ public class DynamicUpdateTest extends BaseCoreFunctionalTestCase {
assertThat( payment.getPaidAt() ).isNotNull(); } assertThat( payment.getPaidAt() ).isNotNull(); }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Payment payment = session.find( Payment.class, PAYMENT_ID ); Payment payment = session.find( Payment.class, PAYMENT_ID );
assertThat(payment).isNotNull(); assertThat(payment).isNotNull();

View File

@ -7,11 +7,13 @@
package org.hibernate.orm.test.bytecode.enhancement.eviction; package org.hibernate.orm.test.bytecode.enhancement.eviction;
import org.hibernate.engine.spi.ManagedEntity; import org.hibernate.engine.spi.ManagedEntity;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Before; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -20,27 +22,27 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class EvictionTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
EvictionTest.Parent.class
}
)
@SessionFactory
@BytecodeEnhanced
public class EvictionTest {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{Parent.class};
}
@Before
public void prepare() {
// Create a Parent // Create a Parent
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent p = new Parent(); Parent p = new Parent();
p.name = "PARENT"; p.name = "PARENT";
s.persist( p ); s.persist( p );
@ -48,8 +50,8 @@ public class EvictionTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
// Delete the Parent // Delete the Parent
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" ) Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
@ -91,7 +93,7 @@ public class EvictionTest extends BaseCoreFunctionalTestCase {
@Entity( name = "Parent" ) @Entity( name = "Parent" )
@Table( name = "PARENT" ) @Table( name = "PARENT" )
private static class Parent { static class Parent {
@Id @Id
@GeneratedValue( strategy = GenerationType.AUTO ) @GeneratedValue( strategy = GenerationType.AUTO )

View File

@ -4,37 +4,37 @@ import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
@TestForIssue(jiraKey = "HHH-16337") annotatedClasses = {
public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
private static final Long MY_ENTITY_ID = 1l;
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
CollectionFlushAfterQueryTest.MyEntity.class, CollectionFlushAfterQueryTest.MyEntity.class,
CollectionFlushAfterQueryTest.MyOtherEntity.class, CollectionFlushAfterQueryTest.MyOtherEntity.class,
CollectionFlushAfterQueryTest.MyAnotherEntity.class CollectionFlushAfterQueryTest.MyAnotherEntity.class
}; }
} )
@SessionFactory
@BytecodeEnhanced
@JiraKey("HHH-16337")
public class CollectionFlushAfterQueryTest {
private static final Long MY_ENTITY_ID = 1l;
@Test @Test
public void testAutoFlush() { public void testAutoFlush(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" ); MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" );
MyOtherEntity otherEntity = new MyOtherEntity( 2l, "my other entity" ); MyOtherEntity otherEntity = new MyOtherEntity( 2l, "my other entity" );
@ -44,7 +44,7 @@ public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID ); MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
@ -57,7 +57,7 @@ public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID ); MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
Set<MyOtherEntity> redirectUris = myEntity.getOtherEntities(); Set<MyOtherEntity> redirectUris = myEntity.getOtherEntities();

View File

@ -12,14 +12,14 @@ import org.hibernate.Session;
import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption; import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@ -33,29 +33,32 @@ import jakarta.persistence.criteria.JoinType;
import static org.hibernate.Hibernate.isInitialized; import static org.hibernate.Hibernate.isInitialized;
import static org.hibernate.Hibernate.isPropertyInitialized; import static org.hibernate.Hibernate.isPropertyInitialized;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
@TestForIssue( jiraKey = "HHH-3949" ) import org.junit.jupiter.api.BeforeEach;
@RunWith( BytecodeEnhancerRunner.class ) import org.junit.jupiter.api.Test;
public class HHH3949Test extends BaseCoreFunctionalTestCase {
@Override @JiraKey( "HHH-3949" )
public Class<?>[] getAnnotatedClasses() { @DomainModel(
return new Class<?>[]{Person.class, Vehicle.class}; annotatedClasses = {
} HHH3949Test.Person.class, HHH3949Test.Vehicle.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ),
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
// see HHH-3949 for further details ^^^^^
}
)
@SessionFactory
@BytecodeEnhanced
public class HHH3949Test {
@Override @BeforeEach
protected void configure(Configuration configuration) { public void prepare(SessionFactoryScope scope) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false ); scope.inTransaction( s -> {
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, true );
// see HHH-3949 for further details ^^^^^
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
// it is important that the data associations remain as follows: // it is important that the data associations remain as follows:
// * Johnny <-> Volkswagen Golf // * Johnny <-> Volkswagen Golf
@ -87,19 +90,19 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test1() { public void test1(SessionFactoryScope scope) {
performQueryAndVerifyPersonResults( "from Person p left join fetch p.vehicle" ); performQueryAndVerifyPersonResults( scope, "from Person p left join fetch p.vehicle" );
} }
@Test @Test
public void test2() { public void test2(SessionFactoryScope scope) {
performQueryAndVerifyVehicleResults( "from Vehicle v left join fetch v.driver" ); performQueryAndVerifyVehicleResults( scope, "from Vehicle v left join fetch v.driver" );
} }
@Test @Test
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
public void test3() { public void test3(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
CriteriaQuery<Person> criteria = criteriaBuilder.createQuery( Person.class ); CriteriaQuery<Person> criteria = criteriaBuilder.createQuery( Person.class );
criteria.from( Person.class ).fetch( "vehicle", JoinType.LEFT ); criteria.from( Person.class ).fetch( "vehicle", JoinType.LEFT );
@ -116,10 +119,10 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
@Test @Test
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
public void test4() { public void test4(SessionFactoryScope scope) {
List<Vehicle> vehicles; List<Vehicle> vehicles;
try ( Session s = openSession() ) { try ( Session s = scope.getSessionFactory().openSession() ) {
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
CriteriaQuery<Vehicle> criteria = criteriaBuilder.createQuery( Vehicle.class ); CriteriaQuery<Vehicle> criteria = criteriaBuilder.createQuery( Vehicle.class );
criteria.from( Vehicle.class ).fetch( "driver", JoinType.LEFT ); criteria.from( Vehicle.class ).fetch( "driver", JoinType.LEFT );
@ -138,9 +141,9 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
// --- // // --- //
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
private void performQueryAndVerifyPersonResults(String query) { private void performQueryAndVerifyPersonResults(SessionFactoryScope scope, String query) {
List<Person> persons; List<Person> persons;
try ( Session s = openSession() ) { try ( Session s = scope.getSessionFactory().openSession() ) {
persons = (List<Person>) s.createQuery( query ).list(); persons = (List<Person>) s.createQuery( query ).list();
} }
for ( Person person : persons ) { for ( Person person : persons ) {
@ -159,9 +162,9 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
private void performQueryAndVerifyVehicleResults(String query) { private void performQueryAndVerifyVehicleResults(SessionFactoryScope scope, String query) {
List<Vehicle> vehicles; List<Vehicle> vehicles;
try ( Session s = openSession() ) { try ( Session s = scope.getSessionFactory().openSession() ) {
vehicles = (List<Vehicle>) s.createQuery( query ).list(); vehicles = (List<Vehicle>) s.createQuery( query ).list();
} }
for ( Vehicle vehicle : vehicles ) { for ( Vehicle vehicle : vehicles ) {
@ -189,7 +192,7 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
@Entity( name = "Person" ) @Entity( name = "Person" )
@Table( name = "PERSON" ) @Table( name = "PERSON" )
private static class Person { static class Person {
@Id @Id
@GeneratedValue @GeneratedValue
@ -219,7 +222,7 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
@Entity( name = "Vehicle" ) @Entity( name = "Vehicle" )
@Table( name = "VEHICLE" ) @Table( name = "VEHICLE" )
private static class Vehicle { static class Vehicle {
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -23,28 +23,27 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.bytecode.enhance.spi.UnloadedField; import org.hibernate.bytecode.enhance.spi.UnloadedField;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext; import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.not; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.CoreMatchers.sameInstance; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/** /**
* Tests removing non-owning side of the bidirectional association, * Tests removing non-owning side of the bidirectional association,
@ -52,31 +51,32 @@ import static org.junit.Assert.assertTrue;
* *
* @author Gail Badner * @author Gail Badner
*/ */
@TestForIssue(jiraKey = "HHH-13241") @JiraKey("HHH-13241")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
BidirectionalLazyTest.Employer.class, BidirectionalLazyTest.Employee.class, BidirectionalLazyTest.Unrelated.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ),
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ @CustomEnhancementContext({
EnhancerTestContext.class, // supports laziness and dirty-checking EnhancerTestContext.class, // supports laziness and dirty-checking
BidirectionalLazyTest.NoDirtyCheckEnhancementContext.class // supports laziness; does not support dirty-checking BidirectionalLazyTest.NoDirtyCheckEnhancementContext.class // supports laziness; does not support dirty-checking
}) })
public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase { public class BidirectionalLazyTest {
// NOTE : tests in this class seem redundant because they assert things that happened // NOTE : tests in this class seem redundant because they assert things that happened
// in previous versions that have been fixed // in previous versions that have been fixed
public Class<?>[] getAnnotatedClasses() {
return new Class[] { Employer.class, Employee.class, Unrelated.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false );
}
@Test @Test
public void testRemoveWithDeletedAssociatedEntity() { public void testRemoveWithDeletedAssociatedEntity(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employer employer = new Employer( "RedHat" ); Employer employer = new Employer( "RedHat" );
@ -90,7 +90,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employer employer = session.get( Employer.class, "RedHat" ); Employer employer = session.get( Employer.class, "RedHat" );
@ -109,7 +109,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
assertNull( session.find( Employer.class, "RedHat" ) ); assertNull( session.find( Employer.class, "RedHat" ) );
assertTrue( session.createQuery( "from Employee e", Employee.class ).getResultList().isEmpty() ); assertTrue( session.createQuery( "from Employee e", Employee.class ).getResultList().isEmpty() );
@ -118,9 +118,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testRemoveWithNonAssociatedRemovedEntity() { public void testRemoveWithNonAssociatedRemovedEntity(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employer employer = new Employer( "RedHat" ); Employer employer = new Employer( "RedHat" );
session.persist( employer ); session.persist( employer );
@ -131,7 +131,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
// Delete an entity that is not associated with Employee // Delete an entity that is not associated with Employee
session.remove( session.get( Unrelated.class, 1 ) ); session.remove( session.get( Unrelated.class, 1 ) );
@ -145,7 +145,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
assertNull( session.find( Unrelated.class, 1 ) ); assertNull( session.find( Unrelated.class, 1 ) );
assertNull( session.find( Employee.class, "Jack" ) ); assertNull( session.find( Employee.class, "Jack" ) );
@ -155,9 +155,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testRemoveWithNoRemovedEntities() { public void testRemoveWithNoRemovedEntities(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employer employer = new Employer( "RedHat" ); Employer employer = new Employer( "RedHat" );
session.persist( employer ); session.persist( employer );
@ -167,7 +167,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
// Don't delete any entities before deleting the Employee // Don't delete any entities before deleting the Employee
final Employee employee = session.get( Employee.class, "Jack" ); final Employee employee = session.get( Employee.class, "Jack" );
@ -178,13 +178,13 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
Employer employer = session.get( Employer.class, "RedHat" ); Employer employer = session.get( Employer.class, "RedHat" );
verifyBaseState( employer ); verifyBaseState( employer );
assertThat( employee.getEmployer(), sameInstance( employer ) ); assertThat( employee.getEmployer() ).isInstanceOf( employer.getClass() );
checkEntityEntryState( session, employee, employer, false ); checkEntityEntryState( session, employee, employer, false );
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
assertNull( session.find( Employee.class, "Jack" ) ); assertNull( session.find( Employee.class, "Jack" ) );
session.remove( session.find( Employer.class, "RedHat" ) ); session.remove( session.find( Employer.class, "RedHat" ) );
@ -193,9 +193,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testRemoveEntityWithNullLazyManyToOne() { public void testRemoveEntityWithNullLazyManyToOne(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employer employer = new Employer( "RedHat" ); Employer employer = new Employer( "RedHat" );
session.persist( employer ); session.persist( employer );
@ -204,7 +204,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
(session) -> { (session) -> {
Employee employee = session.get( Employee.class, "Jack" ); Employee employee = session.get( Employee.class, "Jack" );
verifyBaseState( employee ); verifyBaseState( employee );
@ -224,8 +224,8 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
* deleting the Employer linked to the loaded Employee * deleting the Employer linked to the loaded Employee
*/ */
@Test @Test
public void testRemoveEntityWithLinkedLazyManyToOne() { public void testRemoveEntityWithLinkedLazyManyToOne(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Employer employer = new Employer( "RedHat" ); Employer employer = new Employer( "RedHat" );
session.persist( employer ); session.persist( employer );
@ -235,7 +235,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Employee employee = session.get( Employee.class, "Jack" ); Employee employee = session.get( Employee.class, "Jack" );
verifyBaseState( employee ); verifyBaseState( employee );
@ -244,7 +244,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
Employer employer = session.get( Employer.class, "RedHat" ); Employer employer = session.get( Employer.class, "RedHat" );
verifyBaseState( employer ); verifyBaseState( employer );
assertThat( employee.getEmployer(), sameInstance( employer ) ); assertThat( employee.getEmployer() ).isInstanceOf( employer.getClass() );
session.remove( employer ); session.remove( employer );
session.remove( employee ); session.remove( employee );
@ -265,7 +265,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
final Employer employer = employee.getEmployer(); final Employer employer = employee.getEmployer();
if ( employer != null ) { if ( employer != null ) {
assertFalse( Hibernate.isInitialized( employer ) ); assertFalse( Hibernate.isInitialized( employer ) );
assertThat(employer, not( instanceOf( HibernateProxy.class ) ) ); assertThat( employer ).isNotInstanceOf( HibernateProxy.class );
} }
} }

View File

@ -5,14 +5,15 @@ import java.util.List;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.AfterEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -22,25 +23,24 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@JiraKey("HHH-17049") @JiraKey("HHH-17049")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
ConstructorInitializationAndDynamicUpdateTest.Person.class,
ConstructorInitializationAndDynamicUpdateTest.LoginAccount.class,
ConstructorInitializationAndDynamicUpdateTest.AccountPreferences.class
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunctionalTestCase { public class ConstructorInitializationAndDynamicUpdateTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
Person.class,
LoginAccount.class,
AccountPreferences.class
};
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
Person person = new Person( 1l, "Henry" ); Person person = new Person( 1l, "Henry" );
LoginAccount loginAccount = new LoginAccount(); LoginAccount loginAccount = new LoginAccount();
@ -50,7 +50,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -67,9 +67,9 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
session.createMutationQuery( "delete from Person" ).executeUpdate(); session.createMutationQuery( "delete from Person" ).executeUpdate();
session.createMutationQuery( "delete from LoginAccount" ).executeUpdate(); session.createMutationQuery( "delete from LoginAccount" ).executeUpdate();
@ -79,15 +79,15 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
@Test @Test
public void findTest() { public void findTest(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -105,15 +105,15 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
@Test @Test
public void getReferenceTest() { public void getReferenceTest(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.getReference( Person.class, 1L ); Person person = session.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -131,8 +131,8 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
@Test @Test
public void findTest2() { public void findTest2(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -142,7 +142,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );
@ -167,8 +167,8 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
@Test @Test
public void getReferenceTest2() { public void getReferenceTest2(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.getReference( Person.class, 1L ); Person person = session.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -178,7 +178,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );

View File

@ -5,14 +5,15 @@ import java.util.List;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.NoDirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.NoDirtyCheckEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.AfterEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -22,25 +23,24 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@JiraKey("HHH-17049") @JiraKey("HHH-17049")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
ConstructorInitializationTest.Person.class,
ConstructorInitializationTest.LoginAccount.class,
ConstructorInitializationTest.AccountPreferences.class
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ DirtyCheckEnhancementContext.class, NoDirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ DirtyCheckEnhancementContext.class, NoDirtyCheckEnhancementContext.class })
public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase { public class ConstructorInitializationTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction(
Person.class,
LoginAccount.class,
AccountPreferences.class
};
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
Person person = new Person( 1l, "Henry" ); Person person = new Person( 1l, "Henry" );
LoginAccount loginAccount = new LoginAccount(); LoginAccount loginAccount = new LoginAccount();
@ -50,7 +50,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -67,9 +67,9 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
); );
} }
@After @AfterEach
public void tearDown(){ public void tearDown(SessionFactoryScope scope){
inTransaction( scope.inTransaction(
session-> { session-> {
session.createMutationQuery( "delete from Person" ).executeUpdate(); session.createMutationQuery( "delete from Person" ).executeUpdate();
session.createMutationQuery( "delete from LoginAccount" ).executeUpdate(); session.createMutationQuery( "delete from LoginAccount" ).executeUpdate();
@ -79,15 +79,15 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void findTest() { public void findTest(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -105,15 +105,15 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void getReferenceTest() { public void getReferenceTest(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.getReference( Person.class, 1L ); Person person = session.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
List<LoginAccount> accounts = session.createQuery( List<LoginAccount> accounts = session.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
@ -131,8 +131,8 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void findTest2() { public void findTest2(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -142,7 +142,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );
@ -167,8 +167,8 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void getReferenceTest2() { public void getReferenceTest2(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.getReference( Person.class, 1L ); Person person = session.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -178,7 +178,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( scope.inTransaction(
session -> { session -> {
Person person = session.find( Person.class, 1L ); Person person = session.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );

View File

@ -10,12 +10,14 @@ import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade; import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType; import org.hibernate.annotations.CascadeType;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -26,22 +28,21 @@ import jakarta.persistence.Table;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; @JiraKey( "HHH-10708" )
@DomainModel(
@TestForIssue( jiraKey = "HHH-10708" ) annotatedClasses = {
@RunWith( BytecodeEnhancerRunner.class ) UnexpectedDeleteTest1.Foo.class, UnexpectedDeleteTest1.Bar.class
public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase { }
)
@SessionFactory
@BytecodeEnhanced
public class UnexpectedDeleteTest1 {
private long fooId; private long fooId;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class[]{Foo.class, Bar.class}; scope.inTransaction( s -> {
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Bar bar1 = new Bar(); Bar bar1 = new Bar();
Bar bar2 = new Bar(); Bar bar2 = new Bar();
Foo foo = new Foo(); Foo foo = new Foo();
@ -55,8 +56,8 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Foo foo = s.get( Foo.class, fooId ); Foo foo = s.get( Foo.class, fooId );
// accessing the collection results in an exception // accessing the collection results in an exception
@ -68,7 +69,7 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
@Entity(name = "Bar") @Entity(name = "Bar")
@Table( name = "BAR" ) @Table( name = "BAR" )
private static class Bar { static class Bar {
@Id @Id
@GeneratedValue @GeneratedValue
@ -81,7 +82,7 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
@Entity(name = "Foo") @Entity(name = "Foo")
@Table( name = "FOO" ) @Table( name = "FOO" )
private static class Foo { static class Foo {
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -6,13 +6,15 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708; package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708;
import org.hibernate.testing.TestForIssue; import static org.junit.jupiter.api.Assertions.assertFalse;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Assert; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Before; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@ -23,22 +25,21 @@ import jakarta.persistence.Table;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; @JiraKey( "HHH-10708" )
@DomainModel(
@TestForIssue( jiraKey = "HHH-10708" ) annotatedClasses = {
@RunWith( BytecodeEnhancerRunner.class ) UnexpectedDeleteTest2.Foo.class, UnexpectedDeleteTest2.Bar.class
public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase { }
)
@SessionFactory
@BytecodeEnhanced
public class UnexpectedDeleteTest2 {
private Bar myBar; private Bar myBar;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class[]{Foo.class, Bar.class}; scope.inTransaction( s -> {
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Bar bar = new Bar(); Bar bar = new Bar();
Foo foo1 = new Foo(); Foo foo1 = new Foo();
Foo foo2 = new Foo(); Foo foo2 = new Foo();
@ -54,17 +55,17 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.refresh( myBar ); s.refresh( myBar );
Assert.assertFalse( myBar.foos.isEmpty() ); assertFalse( myBar.foos.isEmpty() );
// The issue is that currently, for some unknown reason, foos are deleted on flush // The issue is that currently, for some unknown reason, foos are deleted on flush
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Bar bar = s.get( Bar.class, myBar.id ); Bar bar = s.get( Bar.class, myBar.id );
Assert.assertFalse( bar.foos.isEmpty() ); assertFalse( bar.foos.isEmpty() );
} ); } );
} }
@ -72,7 +73,7 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
@Entity(name = "Bar") @Entity(name = "Bar")
@Table( name = "BAR" ) @Table( name = "BAR" )
private static class Bar { static class Bar {
@Id @Id
@GeneratedValue @GeneratedValue
@ -84,7 +85,7 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
@Entity(name = "Foo") @Entity(name = "Foo")
@Table( name = "FOO" ) @Table( name = "FOO" )
private static class Foo { static class Foo {
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -6,13 +6,13 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708; package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection; import jakarta.persistence.ElementCollection;
@ -25,20 +25,21 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertEquals;
@TestForIssue( jiraKey = "HHH-10708" ) @JiraKey("HHH-10708")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase { annotatedClasses = {
UnexpectedDeleteTest3.Parent.class, UnexpectedDeleteTest3.Child.class
}
)
@SessionFactory
@BytecodeEnhanced
public class UnexpectedDeleteTest3 {
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class[]{Parent.class, Child.class}; scope.inTransaction( s -> {
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Child child = new Child(); Child child = new Child();
child.setId( 2L ); child.setId( 2L );
s.save( child ); s.save( child );
@ -53,8 +54,8 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.get( Parent.class, 1L ); Parent parent = s.get( Parent.class, 1L );
Child child = new Child(); Child child = new Child();
@ -67,9 +68,9 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
s.save( parent ); s.save( parent );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent application = s.get( Parent.class, 1L ); Parent application = s.get( Parent.class, 1L );
Assert.assertEquals( "Loaded Children collection has unexpected size", 2, application.getChildren().size() ); assertEquals( 2, application.getChildren().size(), "Loaded Children collection has unexpected size" );
} ); } );
} }
@ -77,7 +78,7 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "CHILD" ) @Table( name = "CHILD" )
private static class Child { static class Child {
Long id; Long id;
@ -94,7 +95,7 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "PARENT" ) @Table( name = "PARENT" )
private static class Parent { static class Parent {
Long id; Long id;
Set<String> names; Set<String> names;

View File

@ -11,34 +11,34 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import org.hibernate.Hibernate; 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.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Before; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@TestForIssue(jiraKey = "HHH-14571") @JiraKey("HHH-14571")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
IdInUninitializedProxyTest.AnEntity.class
}
)
@SessionFactory
@BytecodeEnhanced
@EnhancementOptions(lazyLoading = true, extendedEnhancement = true) @EnhancementOptions(lazyLoading = true, extendedEnhancement = true)
public class IdInUninitializedProxyTest extends BaseNonConfigCoreFunctionalTestCase { public class IdInUninitializedProxyTest {
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { AnEntity.class };
}
@Test @Test
public void testIdIsAlwaysConsideredInitialized() { public void testIdIsAlwaysConsideredInitialized(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
final AnEntity e = session.byId( AnEntity.class ).getReference( 1 ); final AnEntity e = session.byId( AnEntity.class ).getReference( 1 );
assertFalse( Hibernate.isInitialized( e ) ); assertFalse( Hibernate.isInitialized( e ) );
// This is the gist of the problem // This is the gist of the problem
@ -52,9 +52,9 @@ public class IdInUninitializedProxyTest extends BaseNonConfigCoreFunctionalTestC
} ); } );
} }
@Before @BeforeEach
public void prepareTestData() { public void prepareTestData(SessionFactoryScope scope) {
inTransaction( session -> { scope.inTransaction( session -> {
AnEntity anEntity = new AnEntity(); AnEntity anEntity = new AnEntity();
anEntity.id = 1; anEntity.id = 1;
anEntity.name = "George"; anEntity.name = "George";

View File

@ -4,15 +4,16 @@ import java.util.List;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.AfterEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -22,26 +23,24 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
@JiraKey("HHH-17049") @JiraKey("HHH-17049")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
JpaConstructorInitializationAndDynamicUpdateTest.Person.class,
JpaConstructorInitializationAndDynamicUpdateTest.LoginAccount.class,
JpaConstructorInitializationAndDynamicUpdateTest.AccountPreferences.class
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntityManagerFunctionalTestCase { public class JpaConstructorInitializationAndDynamicUpdateTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction( em -> {
Person.class,
LoginAccount.class,
AccountPreferences.class
};
}
@Before
public void setUp() {
doInJPA( this::entityManagerFactory, em -> {
Person person = new Person( 1l, "Henry" ); Person person = new Person( 1l, "Henry" );
LoginAccount loginAccount = new LoginAccount(); LoginAccount loginAccount = new LoginAccount();
loginAccount.setOwner( person ); loginAccount.setOwner( person );
@ -50,7 +49,7 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -66,9 +65,9 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.createQuery( "delete from Person" ).executeUpdate(); em.createQuery( "delete from Person" ).executeUpdate();
em.createQuery( "delete from LoginAccount" ).executeUpdate(); em.createQuery( "delete from LoginAccount" ).executeUpdate();
em.createQuery( "delete from AccountPreferences" ).executeUpdate(); em.createQuery( "delete from AccountPreferences" ).executeUpdate();
@ -77,15 +76,15 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
@Test @Test
public void findTest() { public void findTest(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -102,15 +101,15 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
@Test @Test
public void getReferenceTest() { public void getReferenceTest(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.getReference( Person.class, 1L ); Person person = em.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -127,8 +126,8 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
@Test @Test
public void findTest2() { public void findTest2(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -138,7 +137,7 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );
@ -162,8 +161,8 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
@Test @Test
public void getReferenceTest2() { public void getReferenceTest2(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.getReference( Person.class, 1L ); Person person = em.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -173,7 +172,7 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );

View File

@ -3,15 +3,16 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
import java.util.List; import java.util.List;
import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext; import org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking.DirtyCheckEnhancementContext;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.After; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.Test; import org.junit.jupiter.api.AfterEach;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@ -21,26 +22,24 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
@JiraKey("HHH-17049") @JiraKey("HHH-17049")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
JpaConstructorInitializationTest.Person.class,
JpaConstructorInitializationTest.LoginAccount.class,
JpaConstructorInitializationTest.AccountPreferences.class
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class }) @CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
public class JpaConstructorInitializationTest extends BaseEntityManagerFunctionalTestCase { public class JpaConstructorInitializationTest {
@Override @BeforeEach
protected Class<?>[] getAnnotatedClasses() { public void setUp(SessionFactoryScope scope) {
return new Class[] { scope.inTransaction( em -> {
Person.class,
LoginAccount.class,
AccountPreferences.class
};
}
@Before
public void setUp() {
doInJPA( this::entityManagerFactory, em -> {
Person person = new Person( 1l, "Henry" ); Person person = new Person( 1l, "Henry" );
LoginAccount loginAccount = new LoginAccount(); LoginAccount loginAccount = new LoginAccount();
loginAccount.setOwner( person ); loginAccount.setOwner( person );
@ -49,7 +48,7 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -65,9 +64,9 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
); );
} }
@After @AfterEach
public void tearDown() { public void tearDown(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.createQuery( "delete from Person" ).executeUpdate(); em.createQuery( "delete from Person" ).executeUpdate();
em.createQuery( "delete from LoginAccount" ).executeUpdate(); em.createQuery( "delete from LoginAccount" ).executeUpdate();
em.createQuery( "delete from AccountPreferences" ).executeUpdate(); em.createQuery( "delete from AccountPreferences" ).executeUpdate();
@ -76,15 +75,15 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
@Test @Test
public void findTest() { public void findTest(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -101,15 +100,15 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
@Test @Test
public void getReferenceTest() { public void getReferenceTest(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.getReference( Person.class, 1L ); Person person = em.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
List<LoginAccount> accounts = em.createQuery( List<LoginAccount> accounts = em.createQuery(
"select la from LoginAccount la", "select la from LoginAccount la",
LoginAccount.class LoginAccount.class
@ -126,8 +125,8 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
@Test @Test
public void findTest2() { public void findTest2(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -137,7 +136,7 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );
@ -161,8 +160,8 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
@Test @Test
public void getReferenceTest2() { public void getReferenceTest2(SessionFactoryScope scope) {
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
em.clear(); em.clear();
Person person = em.getReference( Person.class, 1L ); Person person = em.getReference( Person.class, 1L );
person.setFirstName( "Liza" ); person.setFirstName( "Liza" );
@ -172,7 +171,7 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
} }
); );
doInJPA( this::entityManagerFactory, em -> { scope.inTransaction( em -> {
Person person = em.find( Person.class, 1L ); Person person = em.find( Person.class, 1L );
assertThat( person.getFirstName() ).isEqualTo( "Liza" ); assertThat( person.getFirstName() ).isEqualTo( "Liza" );

View File

@ -1,15 +1,15 @@
package org.hibernate.orm.test.bytecode.enhancement.lazy; package org.hibernate.orm.test.bytecode.enhancement.lazy;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.DiscriminatorValue;
@ -22,38 +22,31 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
LazyAbstractManyToOneNoProxyTest.User.class,
LazyAbstractManyToOneNoProxyTest.UserGroup.class,
}
)
@SessionFactory
@BytecodeEnhanced
@JiraKey("HHH-16794") @JiraKey("HHH-16794")
public class LazyAbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase { public class LazyAbstractManyToOneNoProxyTest {
private static final String USER_1_NAME = "Andrea"; private static final String USER_1_NAME = "Andrea";
private static final String USER_2_NAME = "Fab"; private static final String USER_2_NAME = "Fab";
private static final String USER_GROUP_1_NAME = "group1"; private static final String USER_GROUP_1_NAME = "group1";
private static final String USER_GROUP_2_NAME = "group2"; private static final String USER_GROUP_2_NAME = "group2";
@Override SQLStatementInspector statementInspector(SessionFactoryScope scope) {
protected Class<?>[] getAnnotatedClasses() { return (SQLStatementInspector) scope.getSessionFactory().getSessionFactoryOptions().getStatementInspector();
return new Class[] {
User.class,
UserGroup.class,
};
} }
@Override @BeforeEach
protected void afterConfigurationBuilt(Configuration configuration) { public void setUp(SessionFactoryScope scope) {
super.afterConfigurationBuilt( configuration ); scope.inTransaction(
configuration.setStatementInspector( new SQLStatementInspector() );
}
SQLStatementInspector statementInspector() {
return (SQLStatementInspector) sessionFactory().getSessionFactoryOptions().getStatementInspector();
}
@Before
public void setUp() {
inTransaction(
session -> { session -> {
UserGroup group1 = new UserGroup( 1l, USER_GROUP_1_NAME ); UserGroup group1 = new UserGroup( 1l, USER_GROUP_1_NAME );
UserGroup group2 = new UserGroup( 2l, USER_GROUP_2_NAME ); UserGroup group2 = new UserGroup( 2l, USER_GROUP_2_NAME );
@ -70,10 +63,10 @@ public class LazyAbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase
} }
@Test @Test
public void testSelect() { public void testSelect(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
SQLStatementInspector statementInspector = statementInspector(); SQLStatementInspector statementInspector = statementInspector( scope );
statementInspector.clear(); statementInspector.clear();
User user = session.getReference( User.class, 1 ); User user = session.getReference( User.class, 1 );

View File

@ -17,43 +17,34 @@ import jakarta.persistence.Lob;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.Hibernate; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.cfg.Configuration; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.tuple.NonIdentifierAttribute; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.TestForIssue; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@TestForIssue( jiraKey = "HHH-11117") @JiraKey("HHH-11117")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class LazyBasicFieldMergeTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyBasicFieldMergeTest.Company.class,
@Override LazyBasicFieldMergeTest.Manager.class,
protected Class<?>[] getAnnotatedClasses() { }
return new Class<?>[] { )
Company.class, @SessionFactory
Manager.class, @BytecodeEnhanced
}; public class LazyBasicFieldMergeTest {
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
Manager manager = new Manager(); Manager manager = new Manager();
manager.setName("John Doe"); manager.setName("John Doe");
manager.setResume(new byte[] {1, 2, 3}); manager.setResume(new byte[] {1, 2, 3});

View File

@ -8,19 +8,21 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Assert; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -30,33 +32,34 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
@TestForIssue( jiraKey = "HHH-9937") @JiraKey("HHH-9937")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyBasicFieldNotInitializedTest.TestEntity.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ),
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class LazyBasicFieldNotInitializedTest {
private Long entityId; private Long entityId;
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{TestEntity.class};
}
@Override @BeforeEach
protected void configure(Configuration configuration) { public void prepare(SessionFactoryScope scope) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false ); scope.inTransaction( s -> {
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, true );
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
TestEntity entity = new TestEntity(); TestEntity entity = new TestEntity();
entity.description = "desc"; entity.description = "desc";
s.persist( entity ); s.persist( entity );
@ -65,18 +68,18 @@ public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
TestEntity entity = s.get( TestEntity.class, entityId ); TestEntity entity = s.get( TestEntity.class, entityId );
Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
EntityPersister entityPersister = sessionFactory().getRuntimeMetamodels() EntityPersister entityPersister = scope.getSessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( TestEntity.class ); .getEntityDescriptor( TestEntity.class );
boolean[] propertyLaziness = entityPersister.getPropertyLaziness(); boolean[] propertyLaziness = entityPersister.getPropertyLaziness();
assertEquals( 1, propertyLaziness.length ); assertEquals( 1, propertyLaziness.length );
assertTrue( propertyLaziness[0] ); Assertions.assertTrue( propertyLaziness[0] );
// Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551) // Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551)
final AttributeMapping theBytesAttr = entityPersister.findAttributeMapping( "description" ); final AttributeMapping theBytesAttr = entityPersister.findAttributeMapping( "description" );
@ -89,7 +92,7 @@ public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase
@Entity(name = "TestEntity") @Entity(name = "TestEntity")
@Table( name = "TEST_ENTITY" ) @Table( name = "TEST_ENTITY" )
private static class TestEntity { static class TestEntity {
@Id @Id
@GeneratedValue @GeneratedValue

View File

@ -7,14 +7,16 @@
package org.hibernate.orm.test.bytecode.enhancement.lazy; package org.hibernate.orm.test.bytecode.enhancement.lazy;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -29,32 +31,34 @@ import jakarta.persistence.Table;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse;
/** /**
* @author Luis Barreiro * @author Luis Barreiro
*/ */
@TestForIssue( jiraKey = "HHH-11576" ) @JiraKey("HHH-11576")
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyCollectionDeletedTest.Post.class,
LazyCollectionDeletedTest.Tag.class,
LazyCollectionDeletedTest.AdditionalDetails.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ),
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class LazyCollectionDeletedTest {
private Long postId; private Long postId;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{Post.class, Tag.class, AdditionalDetails.class}; scope.inTransaction( s -> {
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false );
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, true );
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Post post = new Post(); Post post = new Post();
Tag tag1 = new Tag( "tag1" ); Tag tag1 = new Tag( "tag1" );
@ -75,8 +79,8 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Query query = s.createQuery( "from AdditionalDetails where id=" + postId ); Query query = s.createQuery( "from AdditionalDetails where id=" + postId );
AdditionalDetails additionalDetails = (AdditionalDetails) query.getSingleResult(); AdditionalDetails additionalDetails = (AdditionalDetails) query.getSingleResult();
additionalDetails.details = "New data"; additionalDetails.details = "New data";
@ -85,11 +89,11 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
// additionalDetails.post.tags get deleted on commit // additionalDetails.post.tags get deleted on commit
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Query query = s.createQuery( "from Post where id=" + postId ); Query query = s.createQuery( "from Post where id=" + postId );
Post retrievedPost = (Post) query.getSingleResult(); Post retrievedPost = (Post) query.getSingleResult();
assertFalse( "No tags found", retrievedPost.tags.isEmpty() ); assertFalse( retrievedPost.tags.isEmpty(), "No tags found" );
retrievedPost.tags.forEach( tag -> System.out.println( "Found tag: " + tag ) ); retrievedPost.tags.forEach( tag -> System.out.println( "Found tag: " + tag ) );
} ); } );
} }
@ -98,7 +102,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
@Entity( name = "Tag" ) @Entity( name = "Tag" )
@Table( name = "TAG" ) @Table( name = "TAG" )
private static class Tag { static class Tag {
@Id @Id
@GeneratedValue @GeneratedValue
@ -116,7 +120,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
@Entity( name = "Post" ) @Entity( name = "Post" )
@Table( name = "POST" ) @Table( name = "POST" )
private static class Post { static class Post {
@Id @Id
@GeneratedValue @GeneratedValue
@ -131,7 +135,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
@Entity( name = "AdditionalDetails" ) @Entity( name = "AdditionalDetails" )
@Table( name = "ADDITIONAL_DETAILS" ) @Table( name = "ADDITIONAL_DETAILS" )
private static class AdditionalDetails { static class AdditionalDetails {
@Id @Id
Long id; Long id;

View File

@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.Hibernate.isInitialized; import static org.hibernate.Hibernate.isInitialized;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,28 +28,32 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@TestForIssue(jiraKey = "HHH-12260") @JiraKey("HHH-12260")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyCollectionDetachTest.Parent.class, LazyCollectionDetachTest.Child.class
}
)
@SessionFactory
@BytecodeEnhanced
public class LazyCollectionDetachTest {
private static final int CHILDREN_SIZE = 10; private static final int CHILDREN_SIZE = 10;
private Long parentID; private Long parentID;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{ Parent.class, Child.class }; scope.inTransaction( s -> {
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Parent parent = new Parent(); Parent parent = new Parent();
parent.setChildren( new ArrayList<>() ); parent.setChildren( new ArrayList<>() );
for ( int i = 0; i < CHILDREN_SIZE; i++ ) { for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
@ -63,9 +66,14 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
} ); } );
} }
@AfterEach
void tearDown(SessionFactoryScope scope) {
scope.inTransaction( session -> session.createQuery( "from java.lang.Object", Object.class ).list().forEach( session::remove ) );
}
@Test @Test
public void testDetach() { public void testDetach(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.find( Parent.class, parentID ); Parent parent = s.find( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
@ -80,8 +88,8 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testDetachProxy() { public void testDetachProxy(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.getReference( Parent.class, parentID ); Parent parent = s.getReference( Parent.class, parentID );
checkDirtyTracking( parent ); checkDirtyTracking( parent );
@ -93,8 +101,8 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testRefresh() { public void testRefresh(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.find( Parent.class, parentID ); Parent parent = s.find( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
@ -111,7 +119,7 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
@Entity(name = "Parent") @Entity(name = "Parent")
@Table(name = "PARENT") @Table(name = "PARENT")
private static class Parent { static class Parent {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@ -127,7 +135,7 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
@Entity(name = "Child") @Entity(name = "Child")
@Table(name = "CHILD") @Table(name = "CHILD")
private static class Child { static class Child {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -12,24 +12,20 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.Hibernate.isPropertyInitialized; import static org.hibernate.Hibernate.isPropertyInitialized;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.boot.internal.SessionFactoryBuilderImpl;
import org.hibernate.boot.internal.SessionFactoryOptionsBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.SessionFactoryBuilderService;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -47,38 +43,23 @@ import jakarta.persistence.Table;
* <p> * <p>
* Kept here for <a href="https://github.com/hibernate/hibernate-orm/pull/5252#pullrequestreview-1095843220">historical reasons</a>. * Kept here for <a href="https://github.com/hibernate/hibernate-orm/pull/5252#pullrequestreview-1095843220">historical reasons</a>.
*/ */
@TestForIssue(jiraKey = "HHH-12260") @JiraKey("HHH-12260")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest.Parent.class,
LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest.Child.class
}
)
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
@BytecodeEnhanced
public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest {
private static final int CHILDREN_SIZE = 10; private static final int CHILDREN_SIZE = 10;
private Long parentID; private Long parentID;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{ Parent.class, Child.class }; scope.inTransaction( s -> {
}
@Override
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addService(
SessionFactoryBuilderService.class,
(SessionFactoryBuilderService) (metadata, bootstrapContext) -> {
SessionFactoryOptionsBuilder optionsBuilder = new SessionFactoryOptionsBuilder(
metadata.getMetadataBuildingOptions().getServiceRegistry(),
bootstrapContext
);
// We want to test with this setting set to false explicitly,
// because another test already takes care of the default.
optionsBuilder.enableCollectionInDefaultFetchGroup( false );
return new SessionFactoryBuilderImpl( metadata, optionsBuilder, bootstrapContext );
}
);
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Parent parent = new Parent(); Parent parent = new Parent();
parent.setChildren( new ArrayList<>() ); parent.setChildren( new ArrayList<>() );
for ( int i = 0; i < CHILDREN_SIZE; i++ ) { for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
@ -92,8 +73,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
} }
@Test @Test
public void testDetach() { public void testDetach(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.find( Parent.class, parentID ); Parent parent = s.find( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
@ -108,8 +89,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
} }
@Test @Test
public void testDetachProxy() { public void testDetachProxy(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.getReference( Parent.class, parentID ); Parent parent = s.getReference( Parent.class, parentID );
checkDirtyTracking( parent ); checkDirtyTracking( parent );
@ -121,8 +102,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
} }
@Test @Test
public void testRefresh() { public void testRefresh(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.find( Parent.class, parentID ); Parent parent = s.find( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
@ -139,7 +120,7 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
@Entity(name = "Parent") @Entity(name = "Parent")
@Table(name = "PARENT") @Table(name = "PARENT")
private static class Parent { static class Parent {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@ -155,7 +136,7 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
@Entity(name = "Child") @Entity(name = "Child")
@Table(name = "CHILD") @Table(name = "CHILD")
private static class Child { static class Child {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.lazy; package org.hibernate.orm.test.bytecode.enhancement.lazy;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
@ -18,28 +16,26 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToMany;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.runner.RunWith; import org.junit.jupiter.api.Test;
@TestForIssue(jiraKey = "") @DomainModel(
@RunWith(BytecodeEnhancerRunner.class) annotatedClasses = {
public class LazyCollectionHandlingTest extends BaseCoreFunctionalTestCase { LazyCollectionHandlingTest.JafSid.class, LazyCollectionHandlingTest.UserGroup.class
}
)
@SessionFactory
@BytecodeEnhanced
public class LazyCollectionHandlingTest {
private Integer id; private Integer id;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
JafSid.class, UserGroup.class
};
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
JafSid sid = new JafSid(); JafSid sid = new JafSid();
s.save( sid ); s.save( sid );
@ -49,7 +45,7 @@ public class LazyCollectionHandlingTest extends BaseCoreFunctionalTestCase {
this.id = sid.getId(); this.id = sid.getId();
}); });
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
s.get( JafSid.class, this.id ); s.get( JafSid.class, this.id );
} ); } );
} }

View File

@ -9,14 +9,16 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption; import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Before; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.junit.Test; import org.hibernate.testing.orm.junit.SessionFactory;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -39,9 +41,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.Hibernate.isInitialized; import static org.hibernate.Hibernate.isInitialized;
import static org.hibernate.Hibernate.isPropertyInitialized; import static org.hibernate.Hibernate.isPropertyInitialized;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
/** /**
* Simple test for lazy collection handling in the new bytecode support. * Simple test for lazy collection handling in the new bytecode support.
@ -52,27 +53,28 @@ import static org.junit.Assert.assertTrue;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@TestForIssue( jiraKey = "HHH-10055" ) @JiraKey( "HHH-10055" )
@RunWith( BytecodeEnhancerRunner.class ) @DomainModel(
public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase { annotatedClasses = {
LazyCollectionLoadingTest.Parent.class, LazyCollectionLoadingTest.Child.class
}
)
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ),
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
}
)
@SessionFactory
@BytecodeEnhanced
public class LazyCollectionLoadingTest {
private static final int CHILDREN_SIZE = 10; private static final int CHILDREN_SIZE = 10;
private Long parentID; private Long parentID;
private Parent parent; private Parent parent;
@Override @BeforeEach
public Class<?>[] getAnnotatedClasses() { public void prepare(SessionFactoryScope scope) {
return new Class<?>[]{Parent.class, Child.class}; scope.inTransaction( s -> {
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false );
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, true );
}
@Before
public void prepare() {
doInHibernate( this::sessionFactory, s -> {
Parent parent = new Parent(); Parent parent = new Parent();
parent.setChildren( new ArrayList<>() ); parent.setChildren( new ArrayList<>() );
for ( int i = 0; i < CHILDREN_SIZE; i++ ) { for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
@ -86,8 +88,8 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testTransaction() { public void testTransaction(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Parent parent = s.load( Parent.class, parentID ); Parent parent = s.load( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) );
@ -109,9 +111,9 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-14620" ) @JiraKey( "HHH-14620" )
public void testTransaction_noProxy() { public void testTransaction_noProxy(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
// find will not return a proxy, which is exactly what we want here. // find will not return a proxy, which is exactly what we want here.
Parent parent = s.find( Parent.class, parentID ); Parent parent = s.find( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
@ -136,8 +138,8 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void testNoTransaction() { public void testNoTransaction(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
parent = s.load( Parent.class, parentID ); parent = s.load( Parent.class, parentID );
assertThat( parent, notNullValue() ); assertThat( parent, notNullValue() );
assertThat( parent, not( instanceOf( HibernateProxy.class ) ) ); assertThat( parent, not( instanceOf( HibernateProxy.class ) ) );
@ -161,7 +163,7 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "PARENT" ) @Table( name = "PARENT" )
private static class Parent { static class Parent {
@Id @Id
@GeneratedValue( strategy = GenerationType.AUTO ) @GeneratedValue( strategy = GenerationType.AUTO )
@ -177,7 +179,7 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
@Entity @Entity
@Table( name = "CHILD" ) @Table( name = "CHILD" )
private static class Child { static class Child {
@Id @Id
@GeneratedValue( strategy = GenerationType.AUTO ) @GeneratedValue( strategy = GenerationType.AUTO )

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.orm.test.bytecode.enhancement.lazy; package org.hibernate.orm.test.bytecode.enhancement.lazy;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -17,30 +15,33 @@ import jakarta.persistence.Lob;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.bytecode.enhance.spi.UnloadedClass;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext; import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.junit.Test; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.runner.RunWith; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
/** /**
* @author Guillaume Smet * @author Guillaume Smet
*/ */
@TestForIssue(jiraKey = "HHH-12633") @JiraKey("HHH-12633")
@RunWith(BytecodeEnhancerRunner.class) @DomainModel(
annotatedClasses = {
LazyInitializationWithoutInlineDirtyTrackingTest.File.class
}
)
@SessionFactory
@BytecodeEnhanced
@CustomEnhancementContext( {EnhancerTestContext.class, LazyInitializationWithoutInlineDirtyTrackingTest.NoInlineDirtyTrackingContext.class} ) @CustomEnhancementContext( {EnhancerTestContext.class, LazyInitializationWithoutInlineDirtyTrackingTest.NoInlineDirtyTrackingContext.class} )
public class LazyInitializationWithoutInlineDirtyTrackingTest extends BaseCoreFunctionalTestCase { public class LazyInitializationWithoutInlineDirtyTrackingTest {
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{ File.class };
}
@Test @Test
public void test() { public void test(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
File file = new File(); File file = new File();
file.setId( 1L ); file.setId( 1L );
file.setName( "file" ); file.setName( "file" );
@ -49,7 +50,7 @@ public class LazyInitializationWithoutInlineDirtyTrackingTest extends BaseCoreFu
s.persist( file ); s.persist( file );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
File file = s.find( File.class, 1L ); File file = s.find( File.class, 1L );
file.setBytes( new byte[]{ 1 } ); file.setBytes( new byte[]{ 1 } );
s.persist( file ); s.persist( file );

Some files were not shown because too many files have changed in this diff Show More