Convert bytecodeenhanced tests to use JUnit 5 extensions
This commit is contained in:
parent
85364a2c53
commit
19e495d8da
|
@ -6,82 +6,74 @@
|
|||
*/
|
||||
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.Arrays;
|
||||
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.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OrderColumn;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MyEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
|
||||
@EnhancementOptions(lazyLoading = true)
|
||||
@TestForIssue(jiraKey = "HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest
|
||||
extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( true );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void check() {
|
||||
inSession(
|
||||
@BeforeEach
|
||||
public void check(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session ->
|
||||
assertTrue( session.getSessionFactory().getSessionFactoryOptions()
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from myentity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -89,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -111,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -132,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -153,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
@ -174,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
|
|
@ -6,80 +6,73 @@
|
|||
*/
|
||||
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.Arrays;
|
||||
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.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OrderColumn;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MyEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
|
||||
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
|
||||
@EnhancementOptions(lazyLoading = true)
|
||||
@TestForIssue(jiraKey = "HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateTest {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( false );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void check() {
|
||||
inSession(
|
||||
@BeforeEach
|
||||
public void check(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session ->
|
||||
assertFalse( session.getSessionFactory().getSessionFactoryOptions()
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from myentity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -87,21 +80,21 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -109,20 +102,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -130,20 +123,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -151,19 +144,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
@ -172,19 +165,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
|
|
@ -6,23 +6,6 @@
|
|||
*/
|
||||
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.extractor.Extractors.resultOf;
|
||||
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_HAS_CHANGED_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")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
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)
|
||||
@JiraKey("HHH-13759")
|
||||
public class DirtyCheckingWithEmbeddableAndMappedSuperclassTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -34,18 +34,17 @@ import java.lang.reflect.Method;
|
|||
import org.hibernate.bytecode.enhance.internal.tracker.CompositeOwnerTracker;
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest {
|
||||
|
||||
|
@ -99,7 +98,7 @@ public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassTest
|
|||
assertThat( entity )
|
||||
.extracting( TRACKER_FIELD_NAME ).isInstanceOf( SimpleFieldTracker.class );
|
||||
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_GET_NAME ) )
|
||||
|
|
|
@ -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_SUSPEND_NAME;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
@ -33,7 +32,7 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
@JiraKey("HHH-17035")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddableAndNonVisibleGenericMappedSuperclassWithDifferentGenericParameterNameTest {
|
||||
|
||||
|
|
|
@ -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_WRITER_PREFIX;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
@ -23,7 +22,7 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest {
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
*/
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
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_WRITER_PREFIX;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddableExtedingAnotherEmbeddableAndTwiceRemovedNonVisibleGenericMappedSuperclassTest {
|
||||
|
||||
|
|
|
@ -8,12 +8,13 @@ package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Test;
|
||||
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.Embeddable;
|
||||
import jakarta.persistence.Embedded;
|
||||
|
@ -23,29 +24,25 @@ import jakarta.persistence.MappedSuperclass;
|
|||
import jakarta.persistence.Tuple;
|
||||
|
||||
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)
|
||||
public class DirtyCheckingWithEmbeddableExtendingMappedSuperclassTest extends
|
||||
BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
public class DirtyCheckingWithEmbeddableExtendingMappedSuperclassTest {
|
||||
|
||||
@JiraKey("HHH-17041")
|
||||
@Test
|
||||
public void testQueryEmbeddableFields() {
|
||||
inTransaction(
|
||||
public void testQueryEmbeddableFields(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = new MyEntity(1, "one");
|
||||
session.persist( myEntity );
|
||||
}
|
||||
);
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list();
|
||||
assertThat( result.size() ).isEqualTo( 1 );
|
||||
|
|
|
@ -9,44 +9,43 @@ package org.hibernate.orm.test.bytecode.enhance.internal.bytebuddy;
|
|||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Test;
|
||||
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.Embeddable;
|
||||
import jakarta.persistence.Embedded;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.Tuple;
|
||||
|
||||
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)
|
||||
public class DirtyCheckingWithEmbeddableNonVisibleGenericExtendsSerializableMappedSuperclassTest extends
|
||||
BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
public class DirtyCheckingWithEmbeddableNonVisibleGenericExtendsSerializableMappedSuperclassTest {
|
||||
|
||||
@JiraKey("HHH-17041")
|
||||
@Test
|
||||
public void testQueryEmbeddableFields() {
|
||||
inTransaction(
|
||||
public void testQueryEmbeddableFields(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = new MyEntity(1, "one");
|
||||
session.persist( myEntity );
|
||||
}
|
||||
);
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Tuple> result = session.createQuery( "select m.embedded.text, m.embedded.name from MyEntity m", Tuple.class ).list();
|
||||
assertThat( result.size() ).isEqualTo( 1 );
|
||||
|
|
|
@ -16,11 +16,10 @@ import jakarta.persistence.Id;
|
|||
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 org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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_SUSPEND_NAME;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-13764")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-13764")
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddedOnGetterTest {
|
||||
|
||||
|
|
|
@ -16,13 +16,12 @@ import jakarta.persistence.Id;
|
|||
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 org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
|
||||
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.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_SUSPEND_NAME;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-13764")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-13764")
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
public class DirtyCheckingWithEmbeddedTest {
|
||||
|
||||
|
@ -64,7 +63,8 @@ public class DirtyCheckingWithEmbeddedTest {
|
|||
.hasDeclaredMethods( PERSISTENT_FIELD_READER_PREFIX + "name", PERSISTENT_FIELD_WRITER_PREFIX + "name" )
|
||||
.hasDeclaredMethods( ENTITY_INSTANCE_GETTER_NAME, ENTITY_ENTRY_GETTER_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
|
||||
|
@ -76,7 +76,8 @@ public class DirtyCheckingWithEmbeddedTest {
|
|||
@Test
|
||||
public void shouldDeclareMethodsInEmbeddedClass() {
|
||||
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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -6,20 +6,6 @@
|
|||
*/
|
||||
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.extractor.Extractors.resultOf;
|
||||
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_SUSPEND_NAME;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-13759")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
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)
|
||||
public class DirtyCheckingWithMappedsuperclassTest {
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.access;
|
||||
|
||||
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.EnhancerTestContext;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Access;
|
||||
import jakarta.persistence.AccessType;
|
||||
|
@ -27,7 +28,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
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
|
||||
|
@ -35,23 +37,24 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|||
*
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10851" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@CustomEnhancementContext( MixedAccessTest.NoDirtyCheckingContext.class )
|
||||
public class MixedAccessTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-10851" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
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 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 + "\"}";
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{TestEntity.class, TestOtherEntity.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
TestEntity testEntity = new TestEntity( ID );
|
||||
testEntity.setParamsAsString( PARAMS_AS_STR );
|
||||
s.persist( testEntity );
|
||||
|
@ -63,13 +66,13 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
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 );
|
||||
Assert.assertEquals( PARAMS_AS_STR, testOtherEntity.getParamsAsString() );
|
||||
assertEquals( PARAMS_AS_STR, testOtherEntity.getParamsAsString() );
|
||||
|
||||
// Clean parameters
|
||||
testEntity.setParamsAsString( "{}" );
|
||||
|
@ -77,14 +80,14 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@AfterEach
|
||||
public void cleanup(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
TestEntity testEntity = s.get( TestEntity.class, ID );
|
||||
Assert.assertTrue( testEntity.getParams().isEmpty() );
|
||||
assertTrue( testEntity.getParams().isEmpty() );
|
||||
|
||||
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
|
||||
@Table( name = "TEST_ENTITY" )
|
||||
private static class TestEntity {
|
||||
static class TestEntity {
|
||||
|
||||
@Id
|
||||
String name;
|
||||
|
@ -137,7 +140,7 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase {
|
|||
@Entity
|
||||
@Table( name = "OTHER_ENTITY" )
|
||||
@Access( AccessType.FIELD )
|
||||
private static class TestOtherEntity {
|
||||
static class TestOtherEntity {
|
||||
|
||||
@Id
|
||||
String name;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.access;
|
||||
|
||||
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.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.junit.After;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.Access;
|
||||
import jakarta.persistence.AccessType;
|
||||
|
@ -17,44 +17,46 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
PropertyAccessTest.SomeEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@JiraKey("HHH-16799")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class PropertyAccessTest extends BaseCoreFunctionalTestCase {
|
||||
@BytecodeEnhanced
|
||||
public class PropertyAccessTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { SomeEntity.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( new SomeEntity( 1L, "field", "property" ) );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
SomeEntity entity = session.get( SomeEntity.class, 1L );
|
||||
assertThat( entity.property ).isEqualTo( "from getter: property" );
|
||||
|
||||
entity.setProperty( "updated" );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
SomeEntity entity = session.get( SomeEntity.class, 1L );
|
||||
assertThat( entity.property ).isEqualTo( "from getter: updated" );
|
||||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
@AfterEach
|
||||
public void cleanup(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.remove( session.get( SomeEntity.class, 1L ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "SOME_ENTITY")
|
||||
private static class SomeEntity {
|
||||
static class SomeEntity {
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ import org.hibernate.annotations.Fetch;
|
|||
import org.hibernate.annotations.LazyGroup;
|
||||
import org.hibernate.annotations.LazyToOne;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -25,25 +26,24 @@ import static jakarta.persistence.CascadeType.ALL;
|
|||
import static jakarta.persistence.FetchType.LAZY;
|
||||
import static org.hibernate.annotations.FetchMode.SELECT;
|
||||
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")
|
||||
public class BidirectionalOneToOneWithNonAggregateIdTest extends BaseCoreFunctionalTestCase {
|
||||
public class BidirectionalOneToOneWithNonAggregateIdTest {
|
||||
|
||||
static final int ENTITY_ID = 1;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Entity1.class,
|
||||
Entity2.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Entity1 e1 = new Entity1( ENTITY_ID );
|
||||
Entity2 e2 = new Entity2();
|
||||
|
@ -60,8 +60,8 @@ public class BidirectionalOneToOneWithNonAggregateIdTest extends BaseCoreFunctio
|
|||
|
||||
|
||||
@Test
|
||||
public void testRemovingChild() {
|
||||
inTransaction(
|
||||
public void testRemovingChild(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Entity1 e1 = session.byId( Entity1.class ).load( ENTITY_ID );
|
||||
Entity2 child = e1.getChild();
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.association;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.DiscriminatorColumn;
|
||||
import jakarta.persistence.DiscriminatorType;
|
||||
|
@ -24,56 +25,55 @@ import jakarta.persistence.InheritanceType;
|
|||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11050" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@JiraKey("HHH-11050")
|
||||
@BytecodeEnhanced
|
||||
public class InheritedAttributeAssociationTest {
|
||||
|
||||
@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
|
||||
@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
|
||||
|
||||
// If enhancement of 'items' attribute fails, 'name' won't be enhanced
|
||||
Author author = new Author();
|
||||
author.name = "Bernardo Soares";
|
||||
EnhancerTestUtils.checkDirtyTracking( author, "name" );
|
||||
}
|
||||
// If enhancement of 'items' attribute fails, 'name' won't be enhanced
|
||||
Author author = new Author();
|
||||
author.name = "Bernardo Soares";
|
||||
EnhancerTestUtils.checkDirtyTracking( author, "name" );
|
||||
}
|
||||
|
||||
// --- //
|
||||
// --- //
|
||||
|
||||
@Entity
|
||||
private static class Author {
|
||||
@Entity
|
||||
private static class Author {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
Long id;
|
||||
@Id
|
||||
@GeneratedValue
|
||||
Long id;
|
||||
|
||||
@OneToMany( fetch = FetchType.LAZY, mappedBy = "author" )
|
||||
List<ChildItem> items;
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "author")
|
||||
List<ChildItem> items;
|
||||
|
||||
// keep this field after 'items'
|
||||
String name;
|
||||
}
|
||||
// keep this field after 'items'
|
||||
String name;
|
||||
}
|
||||
|
||||
@MappedSuperclass
|
||||
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
|
||||
@DiscriminatorColumn( name = "type", discriminatorType = DiscriminatorType.STRING )
|
||||
private static abstract class Item {
|
||||
@MappedSuperclass
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
|
||||
private static abstract class Item {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
Long id;
|
||||
@Id
|
||||
@GeneratedValue
|
||||
Long id;
|
||||
|
||||
@ManyToOne( fetch = FetchType.LAZY )
|
||||
Author author;
|
||||
}
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
Author author;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue( "child" )
|
||||
private static class ChildItem extends Item {
|
||||
}
|
||||
@Entity
|
||||
@DiscriminatorValue("child")
|
||||
private static class ChildItem extends Item {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.association;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -15,15 +17,14 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class ManyToManyAssociationListTest {
|
||||
@Test
|
||||
public void testBidirectionalExisting() {
|
||||
|
@ -36,8 +37,8 @@ public class ManyToManyAssociationListTest {
|
|||
user.setGroups( new ArrayList<>( Collections.singleton( group ) ) );
|
||||
user.setGroups( new ArrayList<>( Arrays.asList( group, anotherGroup ) ) );
|
||||
|
||||
Assert.assertEquals( 1, group.getUsers().size() );
|
||||
Assert.assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
assertEquals( 1, group.getUsers().size() );
|
||||
assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
}
|
||||
|
||||
// -- //
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.association;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -22,7 +23,7 @@ import java.util.Set;
|
|||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class ManyToManyAssociationTest {
|
||||
|
||||
@Test
|
||||
|
@ -37,34 +38,34 @@ public class ManyToManyAssociationTest {
|
|||
user.addGroup( anotherGroup );
|
||||
anotherUser.addGroup( group );
|
||||
|
||||
Assert.assertEquals( 2, group.getUsers().size() );
|
||||
Assert.assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
assertEquals( 2, group.getUsers().size() );
|
||||
assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
|
||||
group.resetUsers();
|
||||
|
||||
Assert.assertEquals( 1, user.getGroups().size() );
|
||||
Assert.assertEquals( 0, anotherUser.getGroups().size() );
|
||||
assertEquals( 1, user.getGroups().size() );
|
||||
assertEquals( 0, anotherUser.getGroups().size() );
|
||||
|
||||
// Test remove
|
||||
user.addGroup( group );
|
||||
anotherUser.addGroup( group );
|
||||
|
||||
Assert.assertEquals( 2, group.getUsers().size() );
|
||||
Assert.assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
assertEquals( 2, group.getUsers().size() );
|
||||
assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
|
||||
Set<Group> groups = new HashSet<>( user.getGroups() );
|
||||
groups.remove( group );
|
||||
user.setGroups( groups );
|
||||
|
||||
Assert.assertEquals( 1, group.getUsers().size() );
|
||||
Assert.assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
assertEquals( 1, group.getUsers().size() );
|
||||
assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
|
||||
groups.remove( anotherGroup );
|
||||
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
|
||||
Assert.assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
assertEquals( 1, anotherGroup.getUsers().size() );
|
||||
}
|
||||
|
||||
// -- //
|
||||
|
|
|
@ -6,10 +6,13 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.association;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
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.Entity;
|
||||
|
@ -24,43 +27,43 @@ import java.util.List;
|
|||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class OneToManyAssociationTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Customer customer = new Customer();
|
||||
Assert.assertTrue( customer.getInventories().isEmpty() );
|
||||
assertTrue( customer.getInventories().isEmpty() );
|
||||
|
||||
CustomerInventory customerInventory = new CustomerInventory();
|
||||
customerInventory.setCustomer( customer );
|
||||
|
||||
Assert.assertEquals( 1, customer.getInventories().size() );
|
||||
Assert.assertTrue( customer.getInventories().contains( customerInventory ) );
|
||||
assertEquals( 1, customer.getInventories().size() );
|
||||
assertTrue( customer.getInventories().contains( customerInventory ) );
|
||||
|
||||
Customer anotherCustomer = new Customer();
|
||||
Assert.assertTrue( anotherCustomer.getInventories().isEmpty() );
|
||||
assertTrue( anotherCustomer.getInventories().isEmpty() );
|
||||
customerInventory.setCustomer( anotherCustomer );
|
||||
|
||||
Assert.assertTrue( customer.getInventories().isEmpty() );
|
||||
Assert.assertEquals( 1, anotherCustomer.getInventories().size() );
|
||||
Assert.assertSame( customerInventory, anotherCustomer.getInventories().get( 0 ) );
|
||||
assertTrue( customer.getInventories().isEmpty() );
|
||||
assertEquals( 1, anotherCustomer.getInventories().size() );
|
||||
assertSame( customerInventory, anotherCustomer.getInventories().get( 0 ) );
|
||||
|
||||
customer.addInventory( customerInventory );
|
||||
|
||||
Assert.assertSame( customer, customerInventory.getCustomer() );
|
||||
Assert.assertTrue( anotherCustomer.getInventories().isEmpty() );
|
||||
Assert.assertEquals( 1, customer.getInventories().size() );
|
||||
assertSame( customer, customerInventory.getCustomer() );
|
||||
assertTrue( anotherCustomer.getInventories().isEmpty() );
|
||||
assertEquals( 1, customer.getInventories().size() );
|
||||
|
||||
customer.addInventory( new CustomerInventory() );
|
||||
Assert.assertEquals( 2, customer.getInventories().size() );
|
||||
assertEquals( 2, customer.getInventories().size() );
|
||||
|
||||
// Test remove
|
||||
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
|
||||
Assert.assertNotNull( customerInventory.getCustomer() );
|
||||
assertNotNull( customerInventory.getCustomer() );
|
||||
}
|
||||
|
||||
// --- //
|
||||
|
|
|
@ -10,14 +10,15 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
|
@ -34,21 +35,21 @@ import static org.junit.Assert.assertTrue;
|
|||
* @author Marco Belladelli
|
||||
* @author Tomas Cerskus
|
||||
*/
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-16136")
|
||||
public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
User.class,
|
||||
Order.class,
|
||||
OrderItem.class
|
||||
};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
OneToManyLazyAndEagerTest.User.class,
|
||||
OneToManyLazyAndEagerTest.Order.class,
|
||||
OneToManyLazyAndEagerTest.OrderItem.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@JiraKey("HHH-16136")
|
||||
public class OneToManyLazyAndEagerTest {
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
final User user = new User( "User 1", "Marco" );
|
||||
final User targetUser = new User( "User 2", "Andrea" );
|
||||
final Order order = new Order( "Order 1", user, targetUser );
|
||||
|
@ -61,9 +62,9 @@ public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCa
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.createQuery( "delete from OrderItem" ).executeUpdate();
|
||||
em.createQuery( "delete from Order" ).executeUpdate();
|
||||
em.createQuery( "delete from User" ).executeUpdate();
|
||||
|
@ -71,8 +72,8 @@ public class OneToManyLazyAndEagerTest extends BaseEntityManagerFunctionalTestCa
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQuery() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void testQuery(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
final Order order = em.createQuery( "select o from Order o", Order.class )
|
||||
.getResultList()
|
||||
.get( 0 );
|
||||
|
|
|
@ -6,42 +6,46 @@
|
|||
*/
|
||||
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.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Marco Belladelli
|
||||
* @author Tomas Cerskus
|
||||
*/
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-16477")
|
||||
public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
User.class,
|
||||
Coupon.class,
|
||||
Order.class
|
||||
};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
OneToManyLazyAndEagerTest2.User.class,
|
||||
OneToManyLazyAndEagerTest2.Coupon.class,
|
||||
OneToManyLazyAndEagerTest2.Order.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@JiraKey("HHH-16477")
|
||||
public class OneToManyLazyAndEagerTest2 {
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
final User user = new User( "User 1", "Marco" );
|
||||
final User targetUser = new User( "User 2", "Andrea" );
|
||||
final Coupon coupon = new Coupon( "Coupon 1", targetUser );
|
||||
|
@ -53,9 +57,9 @@ public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestC
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.createQuery( "delete from Order" ).executeUpdate();
|
||||
em.createQuery( "delete from Coupon" ).executeUpdate();
|
||||
em.createQuery( "delete from User" ).executeUpdate();
|
||||
|
@ -63,22 +67,22 @@ public class OneToManyLazyAndEagerTest2 extends BaseEntityManagerFunctionalTestC
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQuery() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void testQuery(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
final Order order = em.createQuery( "select o from Order o", Order.class )
|
||||
.getResultList()
|
||||
.get( 0 );
|
||||
|
||||
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() );
|
||||
|
||||
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() );
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,16 @@ package org.hibernate.orm.test.bytecode.enhancement.association;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -18,30 +20,30 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
|
||||
@JiraKey("HHH-17173")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class OneToOnEnhancedEntityLoadedAsReferenceTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
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 entityId2;
|
||||
private long containedEntityId;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { ContainingEntity.class, ContainedEntity.class };
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
ContainingEntity entity = new ContainingEntity();
|
||||
ContainedEntity containedEntity = new ContainedEntity();
|
||||
containedEntity.setValue( "value" );
|
||||
|
@ -60,8 +62,8 @@ public class OneToOnEnhancedEntityLoadedAsReferenceTest extends BaseCoreFunction
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
ContainingEntity entity2 = em.getReference( ContainingEntity.class, entityId2 );
|
||||
ContainingEntity entity = em.getReference( ContainingEntity.class, entityId );
|
||||
ContainedEntity containedEntity = em.getReference( ContainedEntity.class, containedEntityId );
|
||||
|
|
|
@ -6,22 +6,23 @@
|
|||
*/
|
||||
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.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class OneToOneAssociationTest {
|
||||
|
||||
@Test
|
||||
|
@ -32,7 +33,7 @@ public class OneToOneAssociationTest {
|
|||
Customer customer = new Customer();
|
||||
customer.setUser( user );
|
||||
|
||||
Assert.assertEquals( customer, user.getCustomer() );
|
||||
assertEquals( customer, user.getCustomer() );
|
||||
|
||||
// check dirty tracking is set automatically with bi-directional association management
|
||||
EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" );
|
||||
|
@ -42,12 +43,12 @@ public class OneToOneAssociationTest {
|
|||
|
||||
customer.setUser( anotherUser );
|
||||
|
||||
Assert.assertNull( user.getCustomer() );
|
||||
Assert.assertEquals( customer, anotherUser.getCustomer() );
|
||||
assertNull( user.getCustomer() );
|
||||
assertEquals( customer, anotherUser.getCustomer() );
|
||||
|
||||
user.setCustomer( new Customer() );
|
||||
|
||||
Assert.assertEquals( user, user.getCustomer().getUser() );
|
||||
assertEquals( user, user.getCustomer().getUser() );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -58,15 +59,15 @@ public class OneToOneAssociationTest {
|
|||
Customer customer = new Customer();
|
||||
customer.setUser( user );
|
||||
|
||||
Assert.assertEquals( customer, user.getCustomer() );
|
||||
assertEquals( customer, user.getCustomer() );
|
||||
|
||||
// check dirty tracking is set automatically with bi-directional association management
|
||||
EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" );
|
||||
|
||||
user.setCustomer( null );
|
||||
|
||||
Assert.assertNull( user.getCustomer() );
|
||||
Assert.assertNull( customer.getUser() );
|
||||
assertNull( user.getCustomer() );
|
||||
assertNull( customer.getUser() );
|
||||
}
|
||||
|
||||
// --- //
|
||||
|
|
|
@ -1,40 +1,39 @@
|
|||
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.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class BagAndSetFetchTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
EntityA.class,
|
||||
EntityB.class,
|
||||
EntityC.class,
|
||||
EntityD.class,
|
||||
};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BagAndSetFetchTest.EntityA.class,
|
||||
BagAndSetFetchTest.EntityB.class,
|
||||
BagAndSetFetchTest.EntityC.class,
|
||||
BagAndSetFetchTest.EntityD.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BagAndSetFetchTest {
|
||||
|
||||
@Test
|
||||
public void testIt() {
|
||||
inTransaction(
|
||||
public void testIt(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
EntityB b = new EntityB( 1l, "b" );
|
||||
|
||||
|
@ -85,7 +84,7 @@ public class BagAndSetFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
EntityA entityA = session.find( EntityA.class, 1l );
|
||||
Collection<EntityB> attributes = entityA.attributes;
|
||||
|
|
|
@ -1,38 +1,39 @@
|
|||
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.LinkedList;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class EagerBagsTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
EntityA.class,
|
||||
EntityB.class,
|
||||
EntityC.class,
|
||||
EntityD.class,
|
||||
};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
EagerBagsTest.EntityA.class,
|
||||
EagerBagsTest.EntityB.class,
|
||||
EagerBagsTest.EntityC.class,
|
||||
EagerBagsTest.EntityD.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class EagerBagsTest {
|
||||
|
||||
@Test
|
||||
public void testIt() {
|
||||
inTransaction(
|
||||
public void testIt(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
EntityB b = new EntityB( 1l, "b" );
|
||||
|
||||
|
@ -70,7 +71,7 @@ public class EagerBagsTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
EntityA entityA = session.find( EntityA.class, 1l );
|
||||
Collection<EntityB> attributes = entityA.attributes;
|
||||
|
|
|
@ -10,14 +10,11 @@ import org.hibernate.Version;
|
|||
import org.hibernate.bytecode.enhance.spi.EnhancementInfo;
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
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.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.Jira;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
@ -26,18 +23,18 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class BasicEnhancementTest {
|
||||
|
||||
@Test
|
||||
|
@ -62,10 +59,10 @@ public class BasicEnhancementTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13439")
|
||||
@Jira("HHH-13439")
|
||||
public void enhancementInfoTest() {
|
||||
EnhancementInfo info = SimpleEntity.class.getAnnotation( EnhancementInfo.class );
|
||||
assertNotNull( "EnhancementInfo was not applied", info );
|
||||
assertNotNull( info, "EnhancementInfo was not applied" );
|
||||
|
||||
assertEquals( Version.getVersionString(), info.version() );
|
||||
}
|
||||
|
@ -114,7 +111,7 @@ public class BasicEnhancementTest {
|
|||
( (PersistentAttributeInterceptable) entity ).$$_hibernate_setInterceptor( null );
|
||||
|
||||
entity.id = 1234567890L;
|
||||
Assert.assertEquals( 1234567890L, (long) entity.getId() );
|
||||
assertEquals( 1234567890L, (long) entity.getId() );
|
||||
|
||||
entity.name = "Entity Name";
|
||||
assertSame( "Entity Name", entity.name );
|
||||
|
|
|
@ -8,42 +8,44 @@ package org.hibernate.orm.test.bytecode.enhancement.basic;
|
|||
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class BasicSessionTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{ MyEntity.class};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BasicSessionTest.MyEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BasicSessionTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
s.save( new MyEntity( 1L ) );
|
||||
s.save( new MyEntity( 2L ) );
|
||||
} );
|
||||
|
||||
MyEntity[] entities = new MyEntity[2];
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
entities[0] = s.get( MyEntity.class, 1L );
|
||||
entities[1] = s.get( MyEntity.class, 2L );
|
||||
|
||||
|
@ -70,7 +72,7 @@ public class BasicSessionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "MyEntity" )
|
||||
@Table( name = "MY_ENTITY" )
|
||||
private static class MyEntity implements ManagedEntity {
|
||||
static class MyEntity implements ManagedEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.basic;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.Test;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
|
@ -21,44 +22,45 @@ import jakarta.persistence.MapsId;
|
|||
import jakarta.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-9529" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class CrossEnhancementTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Parent.class, Child.class, ChildKey.class};
|
||||
}
|
||||
@JiraKey( "HHH-9529" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CrossEnhancementTest.Parent.class, CrossEnhancementTest.Child.class, CrossEnhancementTest.ChildKey.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CrossEnhancementTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
sessionFactory().close();
|
||||
buildSessionFactory();
|
||||
}
|
||||
public void test(SessionFactoryScope scope) {
|
||||
// sessionFactory().close();
|
||||
// buildSessionFactory();
|
||||
scope.getSessionFactory().close();
|
||||
// TODO: I do not get this test ^ and not sure how to update it ...
|
||||
}
|
||||
|
||||
// --- //
|
||||
|
||||
@Entity
|
||||
@Table( name = "PARENT" )
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
@Id
|
||||
String id;
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
private static class ChildKey implements Serializable {
|
||||
static class ChildKey implements Serializable {
|
||||
String parent;
|
||||
String type;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table( name = "CHILD" )
|
||||
private static class Child {
|
||||
static class Child {
|
||||
@EmbeddedId
|
||||
ChildKey id;
|
||||
|
||||
|
|
|
@ -6,26 +6,25 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.basic;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator;
|
||||
|
||||
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
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class ExtendedAssociationManagementTest {
|
||||
|
||||
@Test
|
||||
|
@ -46,7 +45,7 @@ public class ExtendedAssociationManagementTest {
|
|||
|
||||
customer.user = anotherUser;
|
||||
|
||||
Assert.assertNull( user.customer );
|
||||
assertNull( user.customer );
|
||||
assertEquals( customer, getFieldByReflection( anotherUser, "customer" ) );
|
||||
|
||||
user.customer = new Customer();
|
||||
|
|
|
@ -4,11 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -21,19 +22,18 @@ import jakarta.persistence.Id;
|
|||
* static accessors, accessors defined in a subclass,
|
||||
* 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)
|
||||
public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyAbstractEntity.class, MyAbstractConfusingEntity.class, MyConcreteEntity.class
|
||||
};
|
||||
}
|
||||
public class ExtendedEnhancementNonStandardAccessTest {
|
||||
|
||||
@Test
|
||||
public void nonStandardInstanceGetterSetterPublicField() {
|
||||
public void nonStandardInstanceGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -44,11 +44,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForPublicField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonStandardInstanceGetterSetterProtectedField() {
|
||||
public void nonStandardInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -59,11 +59,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForProtectedField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonStandardInstanceGetterSetterPackagePrivateField() {
|
||||
public void nonStandardInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -74,11 +74,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForPackagePrivateField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonStandardInstanceGetterSetterPrivateField() {
|
||||
public void nonStandardInstanceGetterSetterPrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -89,11 +89,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForPrivateField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticGetterSetterPublicField() {
|
||||
public void staticGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -104,11 +104,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.staticGetPublicField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticGetterSetterProtectedField() {
|
||||
public void staticGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -119,11 +119,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.staticGetProtectedField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticGetterSetterPackagePrivateField() {
|
||||
public void staticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -134,11 +134,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.staticGetPackagePrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticGetterSetterPrivateField() {
|
||||
public void staticGetterSetterPrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -149,11 +149,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.staticGetPrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassStaticGetterSetterPublicField() {
|
||||
public void innerClassStaticGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -164,11 +164,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.InnerClassAccessors.staticGetPublicField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassStaticGetterSetterProtectedField() {
|
||||
public void innerClassStaticGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -179,11 +179,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.InnerClassAccessors.staticGetProtectedField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassStaticGetterSetterPackagePrivateField() {
|
||||
public void innerClassStaticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -194,11 +194,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.InnerClassAccessors.staticGetPackagePrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassStaticGetterSetterPrivateField() {
|
||||
public void innerClassStaticGetterSetterPrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -209,11 +209,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return MyConcreteEntity.InnerClassAccessors.staticGetPrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassInstanceGetterSetterPublicField() {
|
||||
public void innerClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -224,11 +224,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new MyConcreteEntity.InnerClassAccessors().instanceGetPublicField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassInstanceGetterSetterProtectedField() {
|
||||
public void innerClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -239,11 +239,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new MyConcreteEntity.InnerClassAccessors().instanceGetProtectedField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassInstanceGetterSetterPackagePrivateField() {
|
||||
public void innerClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -254,11 +254,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new MyConcreteEntity.InnerClassAccessors().instanceGetPackagePrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerClassInstanceGetterSetterPrivateField() {
|
||||
public void innerClassInstanceGetterSetterPrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -269,11 +269,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new MyConcreteEntity.InnerClassAccessors().instanceGetPrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassStaticGetterSetterPublicField() {
|
||||
public void externalClassStaticGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -284,11 +284,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return ExternalClassAccessors.staticGetPublicField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassStaticGetterSetterProtectedField() {
|
||||
public void externalClassStaticGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -299,11 +299,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return ExternalClassAccessors.staticGetProtectedField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassStaticGetterSetterPackagePrivateField() {
|
||||
public void externalClassStaticGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -314,11 +314,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return ExternalClassAccessors.staticGetPackagePrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassInstanceGetterSetterPublicField() {
|
||||
public void externalClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -329,11 +329,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new ExternalClassAccessors().instanceGetPublicField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassInstanceGetterSetterProtectedField() {
|
||||
public void externalClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -344,11 +344,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new ExternalClassAccessors().instanceGetProtectedField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalClassInstanceGetterSetterPackagePrivateField() {
|
||||
public void externalClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -359,11 +359,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return new ExternalClassAccessors().instanceGetPackagePrivateField( entity );
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassInstanceGetterSetterPublicField() {
|
||||
public void subClassInstanceGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -374,11 +374,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.getAbstractEntityPublicField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassInstanceGetterSetterProtectedField() {
|
||||
public void subClassInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -389,11 +389,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.getAbstractEntityProtectedField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassInstanceGetterSetterPackagePrivateField() {
|
||||
public void subClassInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -404,11 +404,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.getAbstractEntityPackagePrivateField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassNonStandardInstanceGetterSetterPublicField() {
|
||||
public void subClassNonStandardInstanceGetterSetterPublicField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -419,11 +419,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForAbstractEntityPublicField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassNonStandardInstanceGetterSetterProtectedField() {
|
||||
public void subClassNonStandardInstanceGetterSetterProtectedField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -434,11 +434,11 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForAbstractEntityProtectedField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subClassNonStandardInstanceGetterSetterPackagePrivateField() {
|
||||
public void subClassNonStandardInstanceGetterSetterPackagePrivateField(SessionFactoryScope scope) {
|
||||
doTestFieldAccess( new AccessDelegate() {
|
||||
@Override
|
||||
public void setValue(MyConcreteEntity entity, Long value) {
|
||||
|
@ -449,33 +449,33 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
public Long getValue(MyConcreteEntity entity) {
|
||||
return entity.nonStandardGetterForAbstractEntityPackagePrivateField();
|
||||
}
|
||||
} );
|
||||
}, scope );
|
||||
}
|
||||
|
||||
// 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.
|
||||
private void doTestFieldAccess(AccessDelegate delegate) {
|
||||
Long id = fromTransaction( em -> {
|
||||
private void doTestFieldAccess(AccessDelegate delegate, SessionFactoryScope scope) {
|
||||
Long id = scope.fromTransaction( em -> {
|
||||
var entity = new MyConcreteEntity();
|
||||
em.persist( entity );
|
||||
return entity.id;
|
||||
} );
|
||||
|
||||
inTransaction( em -> {
|
||||
scope.inTransaction( em -> {
|
||||
var entity = em.find( MyConcreteEntity.class, id );
|
||||
assertThat( delegate.getValue( entity ) )
|
||||
.as( "Loaded value before update" )
|
||||
.isNull();
|
||||
} );
|
||||
|
||||
inTransaction( em -> {
|
||||
scope.inTransaction( em -> {
|
||||
var entity = em.getReference( MyConcreteEntity.class, id );
|
||||
// Since field access is replaced with accessor calls,
|
||||
// we expect this change to be detected by dirty tracking and persisted.
|
||||
delegate.setValue( entity, 42L );
|
||||
} );
|
||||
|
||||
inTransaction( em -> {
|
||||
scope.inTransaction( em -> {
|
||||
var entity = em.find( MyConcreteEntity.class, id );
|
||||
// We're working on an initialized entity.
|
||||
assertThat( entity )
|
||||
|
@ -487,7 +487,7 @@ public class ExtendedEnhancementNonStandardAccessTest extends BaseCoreFunctional
|
|||
.isEqualTo( 42L );
|
||||
} );
|
||||
|
||||
inTransaction( em -> {
|
||||
scope.inTransaction( em -> {
|
||||
var entity = em.getReference( MyConcreteEntity.class, id );
|
||||
// We're working on an uninitialized entity.
|
||||
assertThat( entity )
|
||||
|
|
|
@ -18,24 +18,25 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
|
||||
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.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
EntityWithFinalField.class,
|
||||
EntityWithEmbeddedIdWithFinalField.class, EntityWithEmbeddedIdWithFinalField.EmbeddableId.class,
|
||||
EntityWithEmbeddedNonIdWithFinalField.class, EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId.class
|
||||
};
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
FinalFieldEnhancementTest.EntityWithFinalField.class,
|
||||
FinalFieldEnhancementTest.EntityWithEmbeddedIdWithFinalField.class, FinalFieldEnhancementTest.EntityWithEmbeddedIdWithFinalField.EmbeddableId.class,
|
||||
FinalFieldEnhancementTest.EntityWithEmbeddedNonIdWithFinalField.class, FinalFieldEnhancementTest.EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class FinalFieldEnhancementTest {
|
||||
|
||||
@Test
|
||||
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
|
||||
@Test
|
||||
public void entityWithFinalField_smokeTest() {
|
||||
public void entityWithFinalField_smokeTest(SessionFactoryScope scope) {
|
||||
EntityWithFinalField persistedEntity = new EntityWithFinalField( "foo" );
|
||||
persistedEntity.setName( "Some name" );
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( persistedEntity );
|
||||
} );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
EntityWithFinalField entity = s.find( EntityWithFinalField.class, persistedEntity.getId() );
|
||||
assertThat( entity ).extracting( EntityWithFinalField::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
|
||||
@Test
|
||||
public void embeddableIdWithFinalField_smokeTest() {
|
||||
public void embeddableIdWithFinalField_smokeTest(SessionFactoryScope scope) {
|
||||
EntityWithEmbeddedIdWithFinalField persistedEntity = new EntityWithEmbeddedIdWithFinalField();
|
||||
persistedEntity.setName( "Some name" );
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( persistedEntity );
|
||||
} );
|
||||
|
||||
// Read with the same ID instance
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, persistedEntity.getId() );
|
||||
assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id )
|
||||
.isEqualTo( persistedEntity.getId().id );
|
||||
} );
|
||||
|
||||
// Read with a new ID instance
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
EntityWithEmbeddedIdWithFinalField entity = s.find( EntityWithEmbeddedIdWithFinalField.class, EntityWithEmbeddedIdWithFinalField.EmbeddableId.of( persistedEntity.getId().id ) );
|
||||
assertThat( entity ).extracting( EntityWithEmbeddedIdWithFinalField::getId ).extracting( i -> i.id )
|
||||
.isEqualTo( persistedEntity.getId().id );
|
||||
|
@ -87,7 +88,7 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase {
|
|||
// we know Hibernate ORM *has to* instantiate the EmbeddableIdType itself:
|
||||
// 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...
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
EntityWithEmbeddedIdWithFinalField entity =
|
||||
s.createQuery( "from embidwithfinal e where e.name = :name", EntityWithEmbeddedIdWithFinalField.class )
|
||||
.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
|
||||
@Test
|
||||
public void embeddableNonIdWithFinalField_smokeTest() {
|
||||
public void embeddableNonIdWithFinalField_smokeTest(SessionFactoryScope scope) {
|
||||
EntityWithEmbeddedNonIdWithFinalField persistedEntity = new EntityWithEmbeddedNonIdWithFinalField();
|
||||
persistedEntity.setName( "Some name" );
|
||||
persistedEntity.setEmbedded( new EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId( "foo" ) );
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( persistedEntity );
|
||||
} );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
EntityWithEmbeddedNonIdWithFinalField entity = s.find( EntityWithEmbeddedNonIdWithFinalField.class, persistedEntity.getId() );
|
||||
assertThat( entity ).extracting( EntityWithEmbeddedNonIdWithFinalField::getEmbedded )
|
||||
.extracting( EntityWithEmbeddedNonIdWithFinalField.EmbeddableNonId::getImmutableProperty )
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
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.AccessType;
|
||||
|
@ -17,16 +18,16 @@ import jakarta.persistence.MappedSuperclass;
|
|||
|
||||
import org.hibernate.annotations.Cache;
|
||||
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 {
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12579")
|
||||
@JiraKey("HHH-12579")
|
||||
public void enhanceClassWithGenericReturnValueOnMappedSuperclass() {
|
||||
SimpleEntity implementation = new SimpleEntity();
|
||||
|
||||
|
|
|
@ -4,13 +4,12 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
|
|||
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
|
||||
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.EnhancerTestContext;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
@ -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.clearDirtyTracking;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
* @author Craig Andrews
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11284" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@JiraKey( "HHH-11284" )
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext( {EnhancerTestContext.class, InheritedTest.EagerEnhancementContext.class} )
|
||||
public class InheritedTest {
|
||||
|
||||
|
@ -62,7 +61,7 @@ public class InheritedTest {
|
|||
|
||||
// Adapted from BasicEnhancementTest#basicExtendedEnhancementTest
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-14006")
|
||||
@JiraKey("HHH-14006")
|
||||
public void extendedEnhancementTest() {
|
||||
// This test only works if lazy loading bytecode enhancement is enabled,
|
||||
// otherwise extended bytecode enhancement does not do anything we can check.
|
||||
|
|
|
@ -4,13 +4,12 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
|
|||
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
|
||||
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.EnhancerTestContext;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
@ -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.clearDirtyTracking;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10646" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@JiraKey( "HHH-10646" )
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext( {EnhancerTestContext.class, MappedSuperclassTest.EagerEnhancementContext.class} )
|
||||
public class MappedSuperclassTest {
|
||||
|
||||
|
@ -49,7 +48,7 @@ public class MappedSuperclassTest {
|
|||
|
||||
// Adapted from BasicEnhancementTest#basicExtendedEnhancementTest
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-14006")
|
||||
@JiraKey("HHH-14006")
|
||||
public void extendedEnhancementTest() {
|
||||
// This test only works if lazy loading bytecode enhancement is enabled,
|
||||
// otherwise extended bytecode enhancement does not do anything we can check.
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
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.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
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)
|
||||
* and once in the concrete entity class.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-15505")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class OverriddenFieldTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { AbstractEntity.class, Fruit.class };
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
}
|
||||
@JiraKey("HHH-15505")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
OverriddenFieldTest.AbstractEntity.class, OverriddenFieldTest.Fruit.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class OverriddenFieldTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Fruit testEntity = new Fruit();
|
||||
testEntity.setId( 1 );
|
||||
testEntity.setName( "John" );
|
||||
s.persist( testEntity );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Fruit testEntity = s.get( Fruit.class, 1 );
|
||||
Assert.assertEquals( "John", testEntity.getName() );
|
||||
assertEquals( "John", testEntity.getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,18 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.annotations.BatchSize;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -33,21 +34,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@JiraKey("HHH-16890")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BatchEntityOneToManyTest.Order.class, BatchEntityOneToManyTest.Product.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BatchEntityOneToManyTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
Product cheese1 = new Product( 1l, "Cheese 1" );
|
||||
Product cheese2 = new Product( 2l, "Cheese 2" );
|
||||
Product cheese3 = new Product( 3l, "Cheese 3" );
|
||||
|
@ -57,7 +59,7 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
|||
order.addProduct( cheese1 );
|
||||
order.addProduct( cheese2 );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( cheese1 );
|
||||
s.persist( cheese2 );
|
||||
s.persist( cheese3 );
|
||||
|
@ -65,9 +67,9 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery( "delete from Order" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from Product" ).executeUpdate();
|
||||
|
@ -76,8 +78,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Order o = s.get( Order.class, 1 );
|
||||
|
@ -89,8 +91,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
|
||||
@Test
|
||||
public void testGetProduct() {
|
||||
inSession( s -> {
|
||||
public void testGetProduct(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
Product product = s.getReference( Product.class, 3l );
|
||||
|
||||
|
@ -102,8 +104,8 @@ public class BatchEntityOneToManyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQuery() {
|
||||
inSession( s -> {
|
||||
public void testCriteriaQuery(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||
|
|
|
@ -9,15 +9,17 @@ import org.hibernate.annotations.Fetch;
|
|||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -33,21 +35,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@JiraKey("HHH-16890")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BatchEntityOneToManyWithDisabledProxyTest.Order.class, BatchEntityOneToManyWithDisabledProxyTest.Product.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BatchEntityOneToManyWithDisabledProxyTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
Product cheese1 = new Product( 1l, "Cheese 1" );
|
||||
Product cheese2 = new Product( 2l, "Cheese 2" );
|
||||
Product cheese3 = new Product( 3l, "Cheese 3" );
|
||||
|
@ -57,7 +60,7 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
|
|||
order.addProduct( cheese1 );
|
||||
order.addProduct( cheese2 );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( cheese1 );
|
||||
s.persist( cheese2 );
|
||||
s.persist( cheese3 );
|
||||
|
@ -65,9 +68,9 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery( "delete from Order" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from Product" ).executeUpdate();
|
||||
|
@ -76,8 +79,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Order o = s.get( Order.class, 1 );
|
||||
|
@ -89,8 +92,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
|
|||
|
||||
|
||||
@Test
|
||||
public void testGetProduct() {
|
||||
inSession( s -> {
|
||||
public void testGetProduct(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
Product product = s.getReference( Product.class, 3l );
|
||||
|
||||
|
@ -102,8 +105,8 @@ public class BatchEntityOneToManyWithDisabledProxyTest extends BaseCoreFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQuery() {
|
||||
inSession( s -> {
|
||||
public void testCriteriaQuery(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||
|
|
|
@ -7,15 +7,17 @@ import org.hibernate.annotations.BatchSize;
|
|||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -33,24 +35,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@JiraKey("HHH-16890")
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BatchEntityWithSelectFetchTest.Order.class,
|
||||
BatchEntityWithSelectFetchTest.Product.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BatchEntityWithSelectFetchTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
Product cheese1 = new Product( 1l, "Cheese 1" );
|
||||
Product cheese2 = new Product( 2l, "Cheese 2" );
|
||||
Product cheese3 = new Product( 3l, "Cheese 3" );
|
||||
|
@ -61,7 +62,7 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
order.setProduct( cheese2 );
|
||||
order2.setProduct( cheese1 );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( cheese1 );
|
||||
s.persist( cheese2 );
|
||||
s.persist( cheese3 );
|
||||
|
@ -70,9 +71,9 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(){
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope){
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery( "delete from Order" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from Product" ).executeUpdate();
|
||||
|
@ -81,8 +82,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product1 = s.getReference( Product.class, 1l );
|
||||
|
@ -96,8 +97,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder2() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder2(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product = s.getReference( Product.class, 2l );
|
||||
|
@ -110,8 +111,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetProduct() {
|
||||
inSession( s -> {
|
||||
public void testGetProduct(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product3 = s.getReference( Product.class, 3l );
|
||||
|
@ -125,8 +126,8 @@ public class BatchEntityWithSelectFetchTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQuery() {
|
||||
inSession( s -> {
|
||||
public void testCriteriaQuery(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product1 = s.getReference( Product.class, 1l );
|
||||
|
|
|
@ -8,15 +8,17 @@ import org.hibernate.annotations.Fetch;
|
|||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -34,24 +36,23 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@JiraKey("HHH-16890")
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
BatchEntityWithSelectFetchWithDisableProxyTest.Order.class,
|
||||
BatchEntityWithSelectFetchWithDisableProxyTest.Product.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class BatchEntityWithSelectFetchWithDisableProxyTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
@BeforeEach
|
||||
public void setupData(SessionFactoryScope scope) {
|
||||
Product cheese1 = new Product( 1l, "Cheese 1" );
|
||||
Product cheese2 = new Product( 2l, "Cheese 2" );
|
||||
Product cheese3 = new Product( 3l, "Cheese 3" );
|
||||
|
@ -62,7 +63,7 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
order.setProduct( cheese2 );
|
||||
order2.setProduct( cheese1 );
|
||||
|
||||
inTransaction( s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.persist( cheese1 );
|
||||
s.persist( cheese2 );
|
||||
s.persist( cheese3 );
|
||||
|
@ -71,9 +72,9 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
} );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(){
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope){
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery( "delete from Order" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from Product" ).executeUpdate();
|
||||
|
@ -82,8 +83,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product1 = s.getReference( Product.class, 1l );
|
||||
|
@ -97,8 +98,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrder2() {
|
||||
inSession( s -> {
|
||||
public void testGetOrder2(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product = s.getReference( Product.class, 2l );
|
||||
|
@ -111,8 +112,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetProduct() {
|
||||
inSession( s -> {
|
||||
public void testGetProduct(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product3 = s.getReference( Product.class, 3l );
|
||||
|
@ -126,8 +127,8 @@ public class BatchEntityWithSelectFetchWithDisableProxyTest extends BaseCoreFunc
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCriteriaQuery() {
|
||||
inSession( s -> {
|
||||
public void testCriteriaQuery(SessionFactoryScope scope) {
|
||||
scope.inSession( s -> {
|
||||
s.getSessionFactory().getCache().evictAllRegions();
|
||||
|
||||
Product product1 = s.getReference( Product.class, 1l );
|
||||
|
|
|
@ -7,14 +7,16 @@ import org.hibernate.annotations.Fetch;
|
|||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.DiscriminatorColumn;
|
||||
|
@ -33,31 +35,30 @@ import jakarta.persistence.Table;
|
|||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@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_B_NAME = "Bob";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
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(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
|
||||
User user1 = new User();
|
||||
|
@ -87,7 +88,7 @@ public class AbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.getSessionFactory().getCache().evictAllRegions();
|
||||
}
|
||||
|
@ -95,8 +96,8 @@ public class AbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
inTransaction(
|
||||
public void testSelect(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
User user = session.getReference( User.class, 1 );
|
||||
|
||||
|
|
|
@ -7,14 +7,16 @@ import org.hibernate.annotations.Fetch;
|
|||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Proxy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.DiscriminatorColumn;
|
||||
|
@ -33,31 +35,31 @@ import jakarta.persistence.Table;
|
|||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@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_B_NAME = "Bob";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
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(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
|
||||
User user1 = new User();
|
||||
|
@ -87,7 +89,7 @@ public class ManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.getSessionFactory().getCache().evictAllRegions();
|
||||
}
|
||||
|
@ -95,8 +97,8 @@ public class ManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
inTransaction(
|
||||
public void testSelect(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
User user = session.getReference( User.class, 1 );
|
||||
|
||||
|
|
|
@ -6,14 +6,16 @@ import org.hibernate.annotations.BatchSize;
|
|||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -26,28 +28,27 @@ import jakarta.persistence.NamedQuery;
|
|||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue( jiraKey = "HHH-16193")
|
||||
public class ManyToOneTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-16193")
|
||||
@DomainModel(
|
||||
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";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
EntityA.class,
|
||||
EntityB.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, true );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
EntityB b1 = new EntityB( ENTITY_B_NAME );
|
||||
session.persist( b1 );
|
||||
|
@ -58,8 +59,8 @@ public class ManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
List<EntityA> entities = fromTransaction(
|
||||
public void testSelect(SessionFactoryScope scope) {
|
||||
List<EntityA> entities = scope.fromTransaction(
|
||||
session ->
|
||||
session.createNamedQuery( "PersonType.selectAll", EntityA.class )
|
||||
.getResultList()
|
||||
|
|
|
@ -9,14 +9,16 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
|
|||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Cacheable;
|
||||
import jakarta.persistence.DiscriminatorColumn;
|
||||
|
@ -34,31 +36,30 @@ import jakarta.persistence.OneToMany;
|
|||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@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
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
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(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Fridge fridge = new Fridge();
|
||||
FruitContainer fruitContainer = new FruitContainer();
|
||||
|
@ -91,8 +92,8 @@ public class ManyToOneTestReusedColumn extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
inTransaction(
|
||||
public void testSelect(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Fridge fridge = session.getReference( Fridge.class, 1 );
|
||||
|
||||
|
|
|
@ -9,12 +9,13 @@ package org.hibernate.orm.test.bytecode.enhancement.callbacks;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
|
@ -27,17 +28,18 @@ import jakarta.persistence.PostLoad;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@JiraKey("HHH-17019")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
PostLoadLazyListenerTest.Person.class, PostLoadLazyListenerTest.Tag.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class PostLoadLazyListenerTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class, Tag.class };
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction( session -> {
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
session.createQuery( "delete from Tag" ).executeUpdate();
|
||||
session.createQuery( "delete from Person" ).executeUpdate();
|
||||
}
|
||||
|
@ -45,8 +47,8 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void smoke() {
|
||||
inTransaction(
|
||||
public void smoke(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = new Person( 1, "name" );
|
||||
Tag tag = new Tag( 100, person );
|
||||
|
@ -57,7 +59,7 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Tag tag = session.find( Tag.class, 100 );
|
||||
assertThat( tag )
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
*/
|
||||
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.util.List;
|
||||
import java.util.Map;
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -20,42 +22,44 @@ import jakarta.persistence.PrePersist;
|
|||
import jakarta.persistence.PreUpdate;
|
||||
|
||||
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.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@JiraKey("HHH-12718")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Person.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( AvailableSettings.CLASSLOADERS, getClass().getClassLoader() );
|
||||
options.put( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, "true" );
|
||||
options.put( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING, "true" );
|
||||
}
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
PreUpdateBytecodeEnhancementTest.Person.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
// TODO: how to convert this, or even is it needed?
|
||||
// options.put( AvailableSettings.CLASSLOADERS, getClass().getClassLoader() );
|
||||
@Setting( name = AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, value = "true" ),
|
||||
@Setting( name = AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class PreUpdateBytecodeEnhancementTest {
|
||||
|
||||
@Test
|
||||
public void testPreUpdateModifications() {
|
||||
public void testPreUpdateModifications(SessionFactoryScope scope) {
|
||||
Person person = new Person();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
entityManager.persist( person );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Person p = entityManager.find( Person.class, person.id );
|
||||
assertNotNull( p );
|
||||
assertNotNull( p.createdAt );
|
||||
|
@ -64,14 +68,14 @@ public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctiona
|
|||
p.setName( "Changed Name" );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Person p = entityManager.find( Person.class, person.id );
|
||||
assertNotNull( p.lastUpdatedAt );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Person")
|
||||
private static class Person {
|
||||
static class Person {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
|
|
@ -6,12 +6,18 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
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.CascadeType;
|
||||
|
@ -25,35 +31,30 @@ import jakarta.persistence.ManyToOne;
|
|||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
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
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10252" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10252" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeDeleteCollectionTest.Parent.class, CascadeDeleteCollectionTest.Child.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CascadeDeleteCollectionTest {
|
||||
private Parent originalParent;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{Parent.class, Child.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
// Create a Parent with one Child
|
||||
originalParent = doInHibernate( this::sessionFactory, s -> {
|
||||
originalParent = scope.fromTransaction( s -> {
|
||||
Parent p = new Parent();
|
||||
p.setName( "PARENT" );
|
||||
p.setLazy( "LAZY" );
|
||||
|
@ -65,13 +66,13 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testManagedWithUninitializedAssociation() {
|
||||
public void testManagedWithUninitializedAssociation(SessionFactoryScope scope) {
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
|
||||
.setParameter( "name", "PARENT" )
|
||||
.uniqueResult();
|
||||
checkInterceptor( loadedParent, false );
|
||||
checkInterceptor( scope, loadedParent, false );
|
||||
assertFalse( Hibernate.isInitialized( loadedParent.getChildren() ) );
|
||||
s.delete( loadedParent );
|
||||
} );
|
||||
|
@ -79,14 +80,14 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testManagedWithInitializedAssociation() {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
|
||||
.setParameter( "name", "PARENT" )
|
||||
.uniqueResult();
|
||||
checkInterceptor( loadedParent, false );
|
||||
checkInterceptor( scope, loadedParent, false );
|
||||
loadedParent.getChildren().size();
|
||||
assertTrue( Hibernate.isInitialized( loadedParent.getChildren() ) );
|
||||
s.delete( loadedParent );
|
||||
|
@ -95,27 +96,27 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedWithUninitializedAssociation() {
|
||||
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedWithUninitializedAssociation(SessionFactoryScope scope) {
|
||||
final Parent detachedParent = scope.fromTransaction( s -> {
|
||||
return s.get( Parent.class, originalParent.getId() );
|
||||
} );
|
||||
|
||||
assertFalse( Hibernate.isInitialized( detachedParent.getChildren() ) );
|
||||
|
||||
checkInterceptor( detachedParent, false );
|
||||
checkInterceptor( scope, detachedParent, false );
|
||||
|
||||
// Delete the detached Parent with uninitialized children
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( detachedParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedWithInitializedAssociation() {
|
||||
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
final Parent detachedParent = scope.fromTransaction( s -> {
|
||||
Parent parent = s.get( Parent.class, originalParent.getId() );
|
||||
// initialize collection before detaching
|
||||
parent.getChildren().size();
|
||||
|
@ -124,33 +125,33 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
assertTrue( Hibernate.isInitialized( detachedParent.getChildren() ) );
|
||||
|
||||
checkInterceptor( detachedParent, false );
|
||||
checkInterceptor( scope, detachedParent, false );
|
||||
|
||||
// Delete the detached Parent with initialized children
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( detachedParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedOriginal() {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedOriginal(SessionFactoryScope scope) {
|
||||
|
||||
// originalParent#children should be initialized
|
||||
assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) );
|
||||
|
||||
checkInterceptor( originalParent, true );
|
||||
checkInterceptor( scope, originalParent, true );
|
||||
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( originalParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
private void checkInterceptor(Parent parent, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory().getRuntimeMetamodels()
|
||||
private void checkInterceptor(SessionFactoryScope scope, Parent parent, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory().getRuntimeMetamodels()
|
||||
.getMappingMetamodel()
|
||||
.getEntityDescriptor( Parent.class )
|
||||
.getBytecodeEnhancementMetadata();
|
||||
|
@ -223,7 +224,7 @@ public class CascadeDeleteCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity
|
||||
@Table( name = "CHILD" )
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -17,18 +16,15 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
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.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.CascadeType;
|
||||
|
@ -50,37 +46,25 @@ import jakarta.persistence.Table;
|
|||
*
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10252" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10252" )
|
||||
@DomainModel(
|
||||
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;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
// Create a Parent with one Child
|
||||
originalParent = doInHibernate( this::sessionFactory, s -> {
|
||||
originalParent = scope.fromTransaction( s -> {
|
||||
Parent p = new Parent();
|
||||
p.setName( "PARENT" );
|
||||
p.setLazy( "LAZY" );
|
||||
|
@ -92,13 +76,13 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testManagedWithUninitializedAssociation() {
|
||||
public void testManagedWithUninitializedAssociation(SessionFactoryScope scope) {
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
|
||||
.setParameter( "name", "PARENT" )
|
||||
.uniqueResult();
|
||||
checkInterceptor( loadedParent, false );
|
||||
checkInterceptor( scope, loadedParent, false );
|
||||
assertFalse( Hibernate.isPropertyInitialized( loadedParent, "children" ) );
|
||||
s.delete( loadedParent );
|
||||
} );
|
||||
|
@ -106,14 +90,14 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testManagedWithInitializedAssociation() {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Parent loadedParent = (Parent) s.createQuery( "SELECT p FROM Parent p WHERE name=:name" )
|
||||
.setParameter( "name", "PARENT" )
|
||||
.uniqueResult();
|
||||
checkInterceptor( loadedParent, false );
|
||||
checkInterceptor( scope, loadedParent, false );
|
||||
loadedParent.getChildren();
|
||||
assertTrue( Hibernate.isPropertyInitialized( loadedParent, "children" ) );
|
||||
s.delete( loadedParent );
|
||||
|
@ -122,27 +106,27 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedWithUninitializedAssociation() {
|
||||
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedWithUninitializedAssociation(SessionFactoryScope scope) {
|
||||
final Parent detachedParent = scope.fromTransaction( s -> {
|
||||
return s.get( Parent.class, originalParent.getId() );
|
||||
} );
|
||||
|
||||
assertFalse( Hibernate.isPropertyInitialized( detachedParent, "children" ) );
|
||||
|
||||
checkInterceptor( detachedParent, false );
|
||||
checkInterceptor( scope, detachedParent, false );
|
||||
|
||||
// Delete the detached Parent with uninitialized children
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( detachedParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedWithInitializedAssociation() {
|
||||
final Parent detachedParent = doInHibernate( this::sessionFactory, s -> {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
final Parent detachedParent = scope.fromTransaction( s -> {
|
||||
Parent parent = s.get( Parent.class, originalParent.getId() );
|
||||
assertFalse( Hibernate.isPropertyInitialized( parent, "children" ) );
|
||||
|
||||
|
@ -153,33 +137,33 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
|
|||
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedParent, "children" ) );
|
||||
|
||||
checkInterceptor( detachedParent, false );
|
||||
checkInterceptor( scope, detachedParent, false );
|
||||
|
||||
// Delete the detached Parent with initialized children
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( detachedParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public void testDetachedOriginal() {
|
||||
@JiraKey("HHH-13129")
|
||||
public void testDetachedOriginal(SessionFactoryScope scope) {
|
||||
|
||||
// originalParent#children should be initialized
|
||||
assertTrue( Hibernate.isPropertyInitialized( originalParent, "children" ) );
|
||||
|
||||
checkInterceptor( originalParent, true );
|
||||
checkInterceptor( scope, originalParent, true );
|
||||
|
||||
// Delete the Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( originalParent );
|
||||
} );
|
||||
// If the lazy relation is not fetch on cascade there is a constraint violation on commit
|
||||
}
|
||||
|
||||
private void checkInterceptor(Parent parent, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory().getRuntimeMetamodels()
|
||||
private void checkInterceptor(SessionFactoryScope scope, Parent parent, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory().getRuntimeMetamodels()
|
||||
.getMappingMetamodel()
|
||||
.getEntityDescriptor( Parent.class )
|
||||
.getBytecodeEnhancementMetadata();
|
||||
|
@ -252,7 +236,7 @@ public class CascadeDeleteCollectionWithCollectionInDefaultFetchGroupFalseTest e
|
|||
|
||||
@Entity
|
||||
@Table( name = "CHILD" )
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
|
|
|
@ -21,52 +21,42 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.annotations.LazyToOne;
|
||||
import org.hibernate.annotations.LazyToOneOption;
|
||||
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
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 static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
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.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10252")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
||||
private SQLStatementInterceptor sqlInterceptor;
|
||||
@JiraKey("HHH-10252")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeDeleteManyToOneTest.Parent.class, CascadeDeleteManyToOneTest.Child.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CascadeDeleteManyToOneTest {
|
||||
private Child originalChild;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Parent.class, Child.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
sqlInterceptor = new SQLStatementInterceptor( configuration );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
// Create a Parent with one Child
|
||||
originalChild = doInHibernate(
|
||||
this::sessionFactory, s -> {
|
||||
originalChild = scope.fromTransaction( s -> {
|
||||
Child c = new Child();
|
||||
c.setName( "CHILD" );
|
||||
c.setLazy( "LAZY" );
|
||||
|
@ -78,21 +68,22 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testManagedWithInitializedAssociation() {
|
||||
sqlInterceptor.clear();
|
||||
|
||||
public void testManagedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
// Delete the Child
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
final SQLStatementInspector statementInspector = extractFromSession( s );
|
||||
statementInspector.clear();
|
||||
|
||||
final Child managedChild = (Child) s.createQuery( "SELECT c FROM Child c WHERE name=:name" )
|
||||
.setParameter( "name", "CHILD" )
|
||||
.uniqueResult();
|
||||
|
||||
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
// parent should be an uninitialized enhanced-proxy
|
||||
assertTrue( Hibernate.isPropertyInitialized( managedChild, "parent" ) );
|
||||
assertThat( managedChild.getParent(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( managedChild.getParent() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( managedChild.getParent() ) );
|
||||
|
||||
s.delete( managedChild );
|
||||
|
@ -100,8 +91,7 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
);
|
||||
|
||||
// Explicitly check that both got deleted
|
||||
doInHibernate(
|
||||
this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
|
||||
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
|
||||
}
|
||||
|
@ -109,18 +99,18 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedWithInitializedAssociation() {
|
||||
sqlInterceptor.clear();
|
||||
|
||||
final Child detachedChild = fromTransaction(
|
||||
public void testDetachedWithInitializedAssociation(SessionFactoryScope scope) {
|
||||
final Child detachedChild = scope.fromTransaction(
|
||||
(s) -> {
|
||||
final SQLStatementInspector statementInspector = extractFromSession( s );
|
||||
statementInspector.clear();
|
||||
Child child = s.get( Child.class, originalChild.getId() );
|
||||
|
||||
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
// parent should be an uninitialized enhanced-proxy
|
||||
assertTrue( Hibernate.isPropertyInitialized( child, "parent" ) );
|
||||
assertThat( child.getParent(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( child.getParent() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( child.getParent() ) );
|
||||
|
||||
return child;
|
||||
|
@ -129,15 +119,15 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedChild, "parent" ) );
|
||||
|
||||
checkInterceptor( detachedChild, false );
|
||||
checkInterceptor( scope, detachedChild, false );
|
||||
|
||||
// Delete the detached Child with initialized parent
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(s) -> s.delete( detachedChild )
|
||||
);
|
||||
|
||||
// Explicitly check that both got deleted
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
|
||||
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
|
||||
|
@ -146,30 +136,28 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetachedOriginal() {
|
||||
public void testDetachedOriginal(SessionFactoryScope scope) {
|
||||
|
||||
// originalChild#parent should be initialized
|
||||
assertTrue( Hibernate.isPropertyInitialized( originalChild, "parent" ) );
|
||||
|
||||
checkInterceptor( originalChild, true );
|
||||
checkInterceptor( scope, originalChild, true );
|
||||
|
||||
// Delete the Child
|
||||
doInHibernate(
|
||||
this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.delete( originalChild );
|
||||
}
|
||||
);
|
||||
// Explicitly check that both got deleted
|
||||
doInHibernate(
|
||||
this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
assertNull( s.createQuery( "FROM Child c" ).uniqueResult() );
|
||||
assertNull( s.createQuery( "FROM Parent p" ).uniqueResult() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void checkInterceptor(Child child, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = sessionFactory()
|
||||
private void checkInterceptor(SessionFactoryScope scope, Child child, boolean isNullExpected) {
|
||||
final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = scope.getSessionFactory()
|
||||
.getRuntimeMetamodels()
|
||||
.getMappingMetamodel()
|
||||
.getEntityDescriptor( Child.class )
|
||||
|
@ -206,7 +194,7 @@ public class CascadeDeleteManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Child")
|
||||
@Table(name = "CHILD")
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.Test;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.CascadeType;
|
||||
|
@ -26,32 +27,31 @@ import jakarta.persistence.Table;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10254" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class CascadeDetachedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{Author.class, Book.class};
|
||||
}
|
||||
@JiraKey( "HHH-10254" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeDetachedTest.Author.class, CascadeDetachedTest.Book.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CascadeDetachedTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
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( "Peter", "Galvin", new char[] { 'c', 'd' } ) );
|
||||
book.addAuthor( new Author( "Greg", "Gagne", new char[] { 'e', 'f' } ) );
|
||||
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
em.persist( book );
|
||||
} );
|
||||
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
em.merge( book );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.cascade;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -20,120 +19,133 @@ import org.hibernate.annotations.LazyToOneOption;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
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 junit.framework.TestCase.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Bolek Ziobrowski
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
private SQLStatementInterceptor sqlInterceptor;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Person.class, Address.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map<String,Object> settings) {
|
||||
super.addSettings( settings );
|
||||
settings.put( AvailableSettings.FORMAT_SQL, "true" );
|
||||
sqlInterceptor = new SQLStatementInterceptor( settings );
|
||||
}
|
||||
@JiraKey("HHH-13129")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeOnUninitializedTest.Person.class, CascadeOnUninitializedTest.Address.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.FORMAT_SQL, value = "true" ),
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CascadeOnUninitializedTest {
|
||||
|
||||
@Test
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne() {
|
||||
final Person person = persistPersonWithManyToOne();
|
||||
|
||||
sqlInterceptor.clear();
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
|
||||
final Person person = persistPersonWithManyToOne(scope);
|
||||
|
||||
// get a detached Person
|
||||
final Person detachedPerson = fromTransaction(
|
||||
session -> session.get( Person.class, person.getId() )
|
||||
final Person detachedPerson = scope.fromTransaction(
|
||||
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
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
// alter the detached reference
|
||||
detachedPerson.setName( "newName" );
|
||||
|
||||
final Person mergedPerson = fromTransaction(
|
||||
session -> (Person) session.merge( detachedPerson )
|
||||
final Person mergedPerson = scope.fromTransaction(
|
||||
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
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
assertEquals( "newName", mergedPerson.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteEnhancedEntityWithUninitializedManyToOne() {
|
||||
Person person = persistPersonWithManyToOne();
|
||||
|
||||
sqlInterceptor.clear();
|
||||
public void testDeleteEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
|
||||
Person person = persistPersonWithManyToOne(scope);
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = fromTransaction(
|
||||
session -> session.get( Person.class, person.getId() )
|
||||
);
|
||||
Person detachedPerson = scope.fromTransaction(
|
||||
session -> {
|
||||
final SQLStatementInspector statementInspector = extractFromSession( session );
|
||||
statementInspector.clear();
|
||||
|
||||
// loading Person should lead to one SQL
|
||||
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
|
||||
Person p = session.get( Person.class, person.getId() );
|
||||
|
||||
// loading Person should lead to one SQL
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
// primaryAddress should be initialized as an enhance-proxy
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson, not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
sqlInterceptor.clear();
|
||||
|
||||
// deleting detachedPerson should result in detachedPerson.primaryAddress being initialized,
|
||||
// so that the DELETE operation can be cascaded to it.
|
||||
inTransaction(
|
||||
session -> session.delete( detachedPerson )
|
||||
scope.inTransaction(
|
||||
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
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
assertNull( session.get( Person.class, person.getId() ) );
|
||||
assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) );
|
||||
|
@ -142,26 +154,18 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany() {
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
|
||||
|
||||
Person person = persistPersonWithOneToMany();
|
||||
Person person = persistPersonWithOneToMany( scope );
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
return session.get( Person.class, person.getId() );
|
||||
}
|
||||
);
|
||||
Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
|
||||
|
||||
// address should not be initialized in order to reproduce the problem
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
|
||||
detachedPerson.setName( "newName" );
|
||||
|
||||
Person mergedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
return (Person) session.merge( detachedPerson );
|
||||
}
|
||||
);
|
||||
Person mergedPerson = scope.fromTransaction( session -> session.merge( detachedPerson ) );
|
||||
|
||||
// address still shouldn't be initialized: there's no reason for it to be initialized by a merge.
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
|
||||
|
@ -169,37 +173,28 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteEnhancedEntityWithUninitializedOneToMany() {
|
||||
Person person = persistPersonWithOneToMany();
|
||||
public void testDeleteEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
|
||||
Person person = persistPersonWithOneToMany( scope );
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
return session.get( Person.class, person.getId() );
|
||||
}
|
||||
);
|
||||
Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
|
||||
|
||||
// address should not be initialized in order to reproduce the problem
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getAddresses() ) );
|
||||
|
||||
// deleting detachedPerson should result in detachedPerson.address being initialized,
|
||||
// so that the DELETE operation can be cascaded to it.
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.delete( detachedPerson );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.delete( detachedPerson ) );
|
||||
|
||||
// both the Person and its Address should be deleted
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
assertNull( session.get( Person.class, person.getId() ) );
|
||||
assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public Person persistPersonWithManyToOne() {
|
||||
public Person persistPersonWithManyToOne(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
address.setDescription( "ABC" );
|
||||
|
||||
|
@ -207,16 +202,12 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
|
|||
person.setName( "John Doe" );
|
||||
person.setPrimaryAddress( address );
|
||||
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.persist( person ) );
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
public Person persistPersonWithOneToMany() {
|
||||
public Person persistPersonWithOneToMany(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
address.setDescription( "ABC" );
|
||||
|
||||
|
@ -224,11 +215,7 @@ public class CascadeOnUninitializedTest extends BaseNonConfigCoreFunctionalTestC
|
|||
person.setName( "John Doe" );
|
||||
person.getAddresses().add( address );
|
||||
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.persist( person ) );
|
||||
|
||||
return person;
|
||||
}
|
||||
|
|
|
@ -1,35 +1,31 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.cascade;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.jdbc.SQLStatementInspector.extractFromSession;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.annotations.LazyToOne;
|
||||
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.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInspector;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
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 jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -51,116 +47,117 @@ import jakarta.persistence.Table;
|
|||
* @author Bolek Ziobrowski
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-13129")
|
||||
public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
private SQLStatementInterceptor sqlInterceptor;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Person.class, Address.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map<String,Object> settings) {
|
||||
super.addSettings( settings );
|
||||
settings.put( AvailableSettings.FORMAT_SQL, "true" );
|
||||
sqlInterceptor = new SQLStatementInterceptor( settings );
|
||||
}
|
||||
|
||||
@Override
|
||||
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 );
|
||||
}
|
||||
);
|
||||
}
|
||||
@JiraKey("HHH-13129")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest.Person.class, CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest.Address.class
|
||||
}
|
||||
)
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.FORMAT_SQL, value = "true" ),
|
||||
}
|
||||
)
|
||||
@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 CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest {
|
||||
|
||||
@Test
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne() {
|
||||
final Person person = persistPersonWithManyToOne();
|
||||
|
||||
sqlInterceptor.clear();
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
|
||||
final Person person = persistPersonWithManyToOne(scope);
|
||||
|
||||
// get a detached Person
|
||||
final Person detachedPerson = fromTransaction(
|
||||
session -> session.get( Person.class, person.getId() )
|
||||
);
|
||||
final Person detachedPerson = scope.fromTransaction(
|
||||
session -> {
|
||||
final SQLStatementInspector statementInspector = extractFromSession( session );
|
||||
statementInspector.clear();
|
||||
|
||||
// loading Person should lead to one SQL
|
||||
assertThat( sqlInterceptor.getQueryCount(), is( 1 ) );
|
||||
Person p = session.get( Person.class, person.getId() );
|
||||
|
||||
// loading Person should lead to one SQL
|
||||
statementInspector.assertExecutedCount( 1 );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
// primaryAddress should be "initialized" as an enhanced-proxy
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
// alter the detached reference
|
||||
detachedPerson.setName( "newName" );
|
||||
|
||||
final Person mergedPerson = fromTransaction(
|
||||
session -> (Person) session.merge( detachedPerson )
|
||||
final Person mergedPerson = scope.fromTransaction(
|
||||
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
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress(), not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson.getPrimaryAddress() ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
assertEquals( "newName", mergedPerson.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteEnhancedEntityWithUninitializedManyToOne() {
|
||||
Person person = persistPersonWithManyToOne();
|
||||
|
||||
sqlInterceptor.clear();
|
||||
public void testDeleteEnhancedEntityWithUninitializedManyToOne(SessionFactoryScope scope) {
|
||||
Person person = persistPersonWithManyToOne(scope);
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = fromTransaction(
|
||||
session -> session.get( Person.class, person.getId() )
|
||||
);
|
||||
Person detachedPerson = scope.fromTransaction(
|
||||
session -> {
|
||||
final SQLStatementInspector statementInspector = extractFromSession( session );
|
||||
statementInspector.clear();
|
||||
Person p = session.get( Person.class, person.getId() );
|
||||
|
||||
// loading Person should lead to one SQL
|
||||
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
|
||||
assertTrue( Hibernate.isPropertyInitialized( detachedPerson, "primaryAddress" ) );
|
||||
assertThat( detachedPerson, not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( detachedPerson ).isNotInstanceOf( HibernateProxy.class );
|
||||
assertFalse( Hibernate.isInitialized( detachedPerson.getPrimaryAddress() ) );
|
||||
|
||||
sqlInterceptor.clear();
|
||||
|
||||
// deleting detachedPerson should result in detachedPerson.primaryAddress being initialized,
|
||||
// so that the DELETE operation can be cascaded to it.
|
||||
inTransaction(
|
||||
session -> session.delete( detachedPerson )
|
||||
scope.inTransaction(
|
||||
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
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
assertNull( session.get( Person.class, person.getId() ) );
|
||||
assertNull( session.get( Person.class, person.getPrimaryAddress().getId() ) );
|
||||
|
@ -169,26 +166,18 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany() {
|
||||
public void testMergeDetachedEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
|
||||
|
||||
Person person = persistPersonWithOneToMany();
|
||||
Person person = persistPersonWithOneToMany(scope);
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
return session.get( Person.class, person.getId() );
|
||||
}
|
||||
);
|
||||
Person detachedPerson = scope.fromTransaction( session -> session.get( Person.class, person.getId() ) );
|
||||
|
||||
// address should not be initialized
|
||||
assertFalse( Hibernate.isPropertyInitialized( detachedPerson, "addresses" ) );
|
||||
detachedPerson.setName( "newName" );
|
||||
|
||||
Person mergedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
return (Person) session.merge( detachedPerson );
|
||||
}
|
||||
);
|
||||
Person mergedPerson = scope.fromTransaction( session -> session.merge( detachedPerson ) );
|
||||
|
||||
// address should be initialized
|
||||
assertTrue( Hibernate.isPropertyInitialized( mergedPerson, "addresses" ) );
|
||||
|
@ -196,12 +185,11 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteEnhancedEntityWithUninitializedOneToMany() {
|
||||
Person person = persistPersonWithOneToMany();
|
||||
public void testDeleteEnhancedEntityWithUninitializedOneToMany(SessionFactoryScope scope) {
|
||||
Person person = persistPersonWithOneToMany(scope);
|
||||
|
||||
// get a detached Person
|
||||
Person detachedPerson = TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
Person detachedPerson = scope.fromTransaction( session -> {
|
||||
return session.get( Person.class, person.getId() );
|
||||
}
|
||||
);
|
||||
|
@ -211,22 +199,17 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
|
|||
|
||||
// deleting detachedPerson should result in detachedPerson.address being initialized,
|
||||
// so that the DELETE operation can be cascaded to it.
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.delete( detachedPerson );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.delete( detachedPerson ) );
|
||||
|
||||
// both the Person and its Address should be deleted
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
assertNull( session.get( Person.class, person.getId() ) );
|
||||
assertNull( session.get( Person.class, person.getAddresses().iterator().next().getId() ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public Person persistPersonWithManyToOne() {
|
||||
public Person persistPersonWithManyToOne(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
address.setDescription( "ABC" );
|
||||
|
||||
|
@ -234,16 +217,12 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
|
|||
person.setName( "John Doe" );
|
||||
person.setPrimaryAddress( address );
|
||||
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.persist( person ) );
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
public Person persistPersonWithOneToMany() {
|
||||
public Person persistPersonWithOneToMany(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
address.setDescription( "ABC" );
|
||||
|
||||
|
@ -251,11 +230,7 @@ public class CascadeOnUninitializedWithCollectionInDefaultFetchGroupFalseTest ex
|
|||
person.setName( "John Doe" );
|
||||
person.getAddresses().add( address );
|
||||
|
||||
TransactionUtil.doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
scope.inTransaction( session -> session.persist( person ) );
|
||||
|
||||
return person;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
@ -22,28 +22,31 @@ import jakarta.persistence.Table;
|
|||
import java.util.HashSet;
|
||||
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 static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10252" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10252" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CascadeWithFkConstraintTest.Garage.class, CascadeWithFkConstraintTest.Car.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class CascadeWithFkConstraintTest {
|
||||
|
||||
private String garageId, car1Id, car2Id;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Garage.class, Car.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
// Create garage, add 2 cars to garage
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
|
||||
Garage garage = new Garage();
|
||||
Car car1 = new Car();
|
||||
|
@ -62,23 +65,23 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
// Remove garage
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
Garage toRemoveGarage = em.find( Garage.class, garageId );
|
||||
em.remove( toRemoveGarage );
|
||||
} );
|
||||
|
||||
// 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 );
|
||||
Assert.assertNull( foundGarage );
|
||||
assertNull( foundGarage );
|
||||
|
||||
Car foundCar1 = em.find( Car.class, car1Id );
|
||||
Assert.assertEquals( car1Id, foundCar1.id );
|
||||
assertEquals( car1Id, foundCar1.id );
|
||||
|
||||
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
|
||||
@Table( name = "GARAGE" )
|
||||
private static class Garage {
|
||||
static class Garage {
|
||||
|
||||
@Id
|
||||
String id;
|
||||
|
|
|
@ -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.Transport;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.PersistenceException;
|
||||
|
||||
|
@ -33,7 +34,7 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctionalTestCase {
|
||||
public abstract class AbstractMultiPathCircleCascadeTest {
|
||||
private interface EntityOperation {
|
||||
boolean isLegacy();
|
||||
|
||||
|
@ -80,23 +81,23 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
};
|
||||
|
||||
@Test
|
||||
public void testMergeEntityWithNonNullableTransientEntity() {
|
||||
testEntityWithNonNullableTransientEntity( MERGE_OPERATION );
|
||||
public void testMergeEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullableTransientEntity( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveEntityWithNonNullableTransientEntity() {
|
||||
testEntityWithNonNullableTransientEntity( SAVE_OPERATION );
|
||||
public void testSaveEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullableTransientEntity( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateEntityWithNonNullableTransientEntity() {
|
||||
testEntityWithNonNullableTransientEntity( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateEntityWithNonNullableTransientEntity(SessionFactoryScope scope) {
|
||||
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();
|
||||
route.getNodes().remove( node );
|
||||
|
@ -106,7 +107,7 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
routeNew.getNodes().add( node );
|
||||
node.setRoute( routeNew );
|
||||
|
||||
inSession(
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
try {
|
||||
|
@ -131,28 +132,28 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeEntityWithNonNullableEntityNull() {
|
||||
testEntityWithNonNullableEntityNull( MERGE_OPERATION );
|
||||
public void testMergeEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullableEntityNull( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveEntityWithNonNullableEntityNull() {
|
||||
testEntityWithNonNullableEntityNull( SAVE_OPERATION );
|
||||
public void testSaveEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullableEntityNull( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateEntityWithNonNullableEntityNull() {
|
||||
testEntityWithNonNullableEntityNull( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateEntityWithNonNullableEntityNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullableEntityNull( scope, SAVE_UPDATE_OPERATION );
|
||||
}
|
||||
|
||||
private void testEntityWithNonNullableEntityNull( EntityOperation operation) {
|
||||
Route route = getUpdatedDetachedEntity();
|
||||
private void testEntityWithNonNullableEntityNull(SessionFactoryScope scope, EntityOperation operation) {
|
||||
Route route = getUpdatedDetachedEntity( scope );
|
||||
|
||||
Node node = (Node) route.getNodes().iterator().next();
|
||||
route.getNodes().remove( node );
|
||||
node.setRoute( null );
|
||||
|
||||
inSession(
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
try {
|
||||
|
@ -176,26 +177,26 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeEntityWithNonNullablePropSetToNull() {
|
||||
testEntityWithNonNullablePropSetToNull( MERGE_OPERATION );
|
||||
public void testMergeEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullablePropSetToNull( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveEntityWithNonNullablePropSetToNull() {
|
||||
testEntityWithNonNullablePropSetToNull( SAVE_OPERATION );
|
||||
public void testSaveEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullablePropSetToNull( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateEntityWithNonNullablePropSetToNull() {
|
||||
testEntityWithNonNullablePropSetToNull( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateEntityWithNonNullablePropSetToNull(SessionFactoryScope scope) {
|
||||
testEntityWithNonNullablePropSetToNull( scope, SAVE_UPDATE_OPERATION );
|
||||
}
|
||||
|
||||
private void testEntityWithNonNullablePropSetToNull( EntityOperation operation) {
|
||||
Route route = getUpdatedDetachedEntity();
|
||||
private void testEntityWithNonNullablePropSetToNull(SessionFactoryScope scope, EntityOperation operation) {
|
||||
Route route = getUpdatedDetachedEntity( scope );
|
||||
Node node = (Node) route.getNodes().iterator().next();
|
||||
node.setName( null );
|
||||
|
||||
inSession(
|
||||
scope.inSession(
|
||||
session -> {
|
||||
session.beginTransaction();
|
||||
|
||||
|
@ -221,31 +222,31 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeRoute() {
|
||||
testRoute( MERGE_OPERATION );
|
||||
public void testMergeRoute(SessionFactoryScope scope) {
|
||||
testRoute( MERGE_OPERATION, scope );
|
||||
}
|
||||
|
||||
// skip SAVE_OPERATION since Route is not transient
|
||||
@Test
|
||||
public void testSaveUpdateRoute() {
|
||||
testRoute( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateRoute(SessionFactoryScope scope) {
|
||||
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 ->
|
||||
operation.doEntityOperation( r, session )
|
||||
);
|
||||
|
||||
assertInsertCount( 4 );
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( scope, 4 );
|
||||
assertUpdateCount( scope, 1 );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
checkResults( route, true );
|
||||
|
@ -254,27 +255,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergePickupNode() {
|
||||
testPickupNode( MERGE_OPERATION );
|
||||
public void testMergePickupNode(SessionFactoryScope scope) {
|
||||
testPickupNode( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavePickupNode() {
|
||||
testPickupNode( SAVE_OPERATION );
|
||||
public void testSavePickupNode(SessionFactoryScope scope) {
|
||||
testPickupNode( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdatePickupNode() {
|
||||
testPickupNode( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdatePickupNode(SessionFactoryScope scope) {
|
||||
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 -> {
|
||||
Iterator it = r.getNodes().iterator();
|
||||
Node node = (Node) it.next();
|
||||
|
@ -292,10 +293,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
);
|
||||
|
||||
assertInsertCount( 4 );
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( scope, 4 );
|
||||
assertUpdateCount( scope, 0 );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
checkResults( route, false );
|
||||
|
@ -304,27 +305,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeDeliveryNode() {
|
||||
testDeliveryNode( MERGE_OPERATION );
|
||||
public void testMergeDeliveryNode(SessionFactoryScope scope) {
|
||||
testDeliveryNode( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDeliveryNode() {
|
||||
testDeliveryNode( SAVE_OPERATION );
|
||||
public void testSaveDeliveryNode(SessionFactoryScope scope) {
|
||||
testDeliveryNode( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateDeliveryNode() {
|
||||
testDeliveryNode( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateDeliveryNode(SessionFactoryScope scope) {
|
||||
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 -> {
|
||||
Iterator it = r.getNodes().iterator();
|
||||
Node node = (Node) it.next();
|
||||
|
@ -343,10 +344,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
);
|
||||
|
||||
|
||||
assertInsertCount( 4 );
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( scope, 4 );
|
||||
assertUpdateCount( scope, 0 );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
checkResults( route, false );
|
||||
|
@ -355,35 +356,35 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeTour() {
|
||||
testTour( MERGE_OPERATION );
|
||||
public void testMergeTour(SessionFactoryScope scope) {
|
||||
testTour( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveTour() {
|
||||
testTour( SAVE_OPERATION );
|
||||
public void testSaveTour(SessionFactoryScope scope) {
|
||||
testTour( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateTour() {
|
||||
testTour( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateTour(SessionFactoryScope scope) {
|
||||
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 ->
|
||||
operation.doEntityOperation( ( (Node) r.getNodes().toArray()[0] ).getTour(), session )
|
||||
);
|
||||
|
||||
assertInsertCount( 4 );
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( scope, 4 );
|
||||
assertUpdateCount( scope, 0 );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
checkResults( route, false );
|
||||
|
@ -392,27 +393,27 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeTransport() {
|
||||
testTransport( MERGE_OPERATION );
|
||||
public void testMergeTransport(SessionFactoryScope scope) {
|
||||
testTransport( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveTransport() {
|
||||
testTransport( SAVE_OPERATION );
|
||||
public void testSaveTransport(SessionFactoryScope scope) {
|
||||
testTransport( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateTransport() {
|
||||
testTransport( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateTransport(SessionFactoryScope scope) {
|
||||
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 -> {
|
||||
Transport transport;
|
||||
Node node = ( (Node) r.getNodes().toArray()[0] );
|
||||
|
@ -427,10 +428,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
);
|
||||
|
||||
assertInsertCount( 4 );
|
||||
assertUpdateCount( 0 );
|
||||
assertInsertCount( scope, 4 );
|
||||
assertUpdateCount( scope, 0 );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
checkResults( route, false );
|
||||
|
@ -445,10 +446,10 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
return deliveryNode;
|
||||
}
|
||||
|
||||
private Route getUpdatedDetachedEntity() {
|
||||
private Route getUpdatedDetachedEntity(SessionFactoryScope scope) {
|
||||
|
||||
Route route = new Route();
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
route.setName( "routeA" );
|
||||
|
||||
|
@ -494,9 +495,9 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
return route;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void cleanup(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Transport" );
|
||||
session.createQuery( "delete from Tour" );
|
||||
|
@ -563,24 +564,24 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMergeData3Nodes() {
|
||||
testData3Nodes( MERGE_OPERATION );
|
||||
public void testMergeData3Nodes(SessionFactoryScope scope) {
|
||||
testData3Nodes( scope, MERGE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveData3Nodes() {
|
||||
testData3Nodes( SAVE_OPERATION );
|
||||
public void testSaveData3Nodes(SessionFactoryScope scope) {
|
||||
testData3Nodes( scope, SAVE_OPERATION );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveUpdateData3Nodes() {
|
||||
testData3Nodes( SAVE_UPDATE_OPERATION );
|
||||
public void testSaveUpdateData3Nodes(SessionFactoryScope scope) {
|
||||
testData3Nodes( scope, SAVE_UPDATE_OPERATION );
|
||||
}
|
||||
|
||||
private void testData3Nodes( EntityOperation operation) {
|
||||
private void testData3Nodes(SessionFactoryScope scope, EntityOperation operation) {
|
||||
|
||||
Route r = new Route();
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
r.setName( "routeA" );
|
||||
|
||||
|
@ -588,9 +589,9 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
);
|
||||
|
||||
clearCounts();
|
||||
clearCounts( scope );
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Route route = session.get( Route.class, r.getRouteID() );
|
||||
route.setName( "new routA" );
|
||||
|
@ -651,8 +652,8 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
);
|
||||
|
||||
assertInsertCount( 6 );
|
||||
assertUpdateCount( 1 );
|
||||
assertInsertCount( scope, 6 );
|
||||
assertUpdateCount( scope, 1 );
|
||||
}
|
||||
|
||||
protected void checkExceptionFromNullValueForNonNullable(
|
||||
|
@ -668,7 +669,7 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
}
|
||||
else {
|
||||
assertTrue( ( ex instanceof JDBCException ) || ( ex.getCause() instanceof JDBCException ) );
|
||||
Assertions.assertTrue( ( ex instanceof JDBCException ) || ( ex.getCause() instanceof JDBCException ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -681,22 +682,22 @@ public abstract class AbstractMultiPathCircleCascadeTest extends BaseCoreFunctio
|
|||
}
|
||||
}
|
||||
|
||||
protected void clearCounts() {
|
||||
sessionFactory().getStatistics().clear();
|
||||
protected void clearCounts(SessionFactoryScope scope) {
|
||||
scope.getSessionFactory().getStatistics().clear();
|
||||
}
|
||||
|
||||
protected void assertInsertCount(int expected) {
|
||||
int inserts = (int) sessionFactory().getStatistics().getEntityInsertCount();
|
||||
assertEquals( "unexpected insert count", expected, inserts );
|
||||
protected void assertInsertCount(SessionFactoryScope scope, int expected) {
|
||||
int inserts = (int) scope.getSessionFactory().getStatistics().getEntityInsertCount();
|
||||
Assertions.assertEquals( expected, inserts, "unexpected insert count" );
|
||||
}
|
||||
|
||||
protected void assertUpdateCount(int expected) {
|
||||
int updates = (int) sessionFactory().getStatistics().getEntityUpdateCount();
|
||||
assertEquals( "unexpected update counts", expected, updates );
|
||||
protected void assertUpdateCount(SessionFactoryScope scope, int expected) {
|
||||
int updates = (int) scope.getSessionFactory().getStatistics().getEntityUpdateCount();
|
||||
Assertions.assertEquals( expected, updates, "unexpected update counts" );
|
||||
}
|
||||
|
||||
protected void assertDeleteCount(int expected) {
|
||||
int deletes = (int) sessionFactory().getStatistics().getEntityDeleteCount();
|
||||
assertEquals( "unexpected delete counts", expected, deletes );
|
||||
protected void assertDeleteCount(SessionFactoryScope scope, int expected) {
|
||||
int deletes = (int) scope.getSessionFactory().getStatistics().getEntityDeleteCount();
|
||||
Assertions.assertEquals( expected, deletes, "unexpected delete counts" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,32 +6,34 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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
|
||||
*/
|
||||
@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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,32 +6,35 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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
|
||||
*/
|
||||
@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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,33 +6,35 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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
|
||||
*/
|
||||
@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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,32 +6,35 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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
|
||||
*/
|
||||
@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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,31 +6,34 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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
|
||||
*/
|
||||
@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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,16 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.cascade.circle;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.bytecode.enhancement.lazy.NoDirtyCheckingContext;
|
||||
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.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:
|
||||
|
@ -37,19 +39,20 @@ import org.junit.runner.RunWith;
|
|||
*
|
||||
* @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 })
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package org.hibernate.orm.test.bytecode.enhancement.collectionelement.flush;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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 jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -16,24 +16,26 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-16337")
|
||||
public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
ElementCollectionFlushAfterQueryTest.MyEntity.class,
|
||||
ElementCollectionFlushAfterQueryTest.MyOtherEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@JiraKey("HHH-16337")
|
||||
public class ElementCollectionFlushAfterQueryTest {
|
||||
private static final Long MY_ENTITY_ID = 1l;
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyEntity.class,
|
||||
MyOtherEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoFlush() {
|
||||
inTransaction(
|
||||
public void testAutoFlush(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" );
|
||||
myEntity.addRedirectUris( "1" );
|
||||
|
@ -41,7 +43,7 @@ public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTest
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
|
||||
|
||||
|
@ -53,7 +55,7 @@ public class ElementCollectionFlushAfterQueryTest extends BaseCoreFunctionalTest
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
|
||||
Set<String> redirectUris = myEntity.getRedirectUris();
|
||||
|
|
|
@ -6,82 +6,74 @@
|
|||
*/
|
||||
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.Arrays;
|
||||
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.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OrderColumn;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MyEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced(testEnhancedClasses = MyEntity.class)
|
||||
@EnhancementOptions(lazyLoading = true)
|
||||
@TestForIssue(jiraKey = "HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest
|
||||
extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGroupTest {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( true );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void check() {
|
||||
inSession(
|
||||
@BeforeEach
|
||||
public void check(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session ->
|
||||
assertTrue( session.getSessionFactory().getSessionFactoryOptions()
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from myentity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -89,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -111,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -132,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -153,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
@ -174,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateCollectionsInDefaultGro
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
|
|
@ -6,80 +6,74 @@
|
|||
*/
|
||||
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.Arrays;
|
||||
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.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OrderColumn;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
MyEntity.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(lazyLoading = true)
|
||||
@TestForIssue(jiraKey = "HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-14387")
|
||||
public class BytecodeEnhancementElementCollectionRecreateTest {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
MyEntity.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( false );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void check() {
|
||||
inSession(
|
||||
@BeforeEach
|
||||
public void check(SessionFactoryScope scope) {
|
||||
scope.inSession(
|
||||
session ->
|
||||
assertFalse( session.getSessionFactory().getSessionFactoryOptions()
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
.isCollectionsInDefaultFetchGroupEnabled() )
|
||||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from myentity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -87,21 +81,21 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRecreateCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testRecreateCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( Arrays.asList( "two", "three" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "two", "three" );
|
||||
|
@ -109,20 +103,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -130,20 +124,20 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
entity.setElements( new ArrayList<>() );
|
||||
} );
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.isEmpty();
|
||||
|
@ -151,19 +145,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollection(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.get( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.get( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
@ -172,19 +166,19 @@ public class BytecodeEnhancementElementCollectionRecreateTest extends BaseNonCon
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind() {
|
||||
inTransaction( session -> {
|
||||
public void testLoadAndCommitTransactionDoesNotDeleteCollectionFind(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.setId( 1 );
|
||||
entity.setElements( Arrays.asList( "one", "two", "four" ) );
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
scope.inTransaction( session ->
|
||||
session.find( MyEntity.class, 1 )
|
||||
);
|
||||
|
||||
inTransaction( session -> {
|
||||
scope.inTransaction( session -> {
|
||||
MyEntity entity = session.find( MyEntity.class, 1 );
|
||||
assertThat( entity.getElements() )
|
||||
.containsExactlyInAnyOrder( "one", "two", "four" );
|
||||
|
|
|
@ -13,39 +13,37 @@ import org.hibernate.orm.test.deletetransient.Note;
|
|||
import org.hibernate.orm.test.deletetransient.Person;
|
||||
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.junit4.BaseCoreFunctionalTestCase;
|
||||
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.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
|
||||
*/
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
xmlMappings = {
|
||||
"org/hibernate/orm/test/deletetransient/Person.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
|
||||
public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
||||
public class DeleteTransientEntityTest {
|
||||
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "org/hibernate/orm/test/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "deletetransient/Person.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
@AfterEach
|
||||
void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> session.createQuery( "from java.lang.Object", Object.class ).list().forEach( session::remove ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientEntityDeletionNoCascades() {
|
||||
inTransaction(
|
||||
public void testTransientEntityDeletionNoCascades(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.remove( new Address() );
|
||||
}
|
||||
|
@ -53,8 +51,8 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTransientEntityDeletionCascadingToTransientAssociation() {
|
||||
inTransaction(
|
||||
public void testTransientEntityDeletionCascadingToTransientAssociation(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person p = new Person();
|
||||
p.getAddresses().add( new Address() );
|
||||
|
@ -64,8 +62,8 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTransientEntityDeleteCascadingToCircularity() {
|
||||
inTransaction(
|
||||
public void testTransientEntityDeleteCascadingToCircularity(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person p1 = new Person();
|
||||
Person p2 = new Person();
|
||||
|
@ -77,16 +75,16 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTransientEntityDeletionCascadingToDetachedAssociation() {
|
||||
public void testTransientEntityDeletionCascadingToDetachedAssociation(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
address.setInfo( "123 Main St." );
|
||||
session.persist( address );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person p = new Person();
|
||||
p.getAddresses().add( address );
|
||||
|
@ -94,18 +92,18 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
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
|
||||
public void testTransientEntityDeletionCascadingToPersistentAssociation() {
|
||||
Long id = fromTransaction(
|
||||
public void testTransientEntityDeletionCascadingToPersistentAssociation(SessionFactoryScope scope) {
|
||||
Long id = scope.fromTransaction(
|
||||
session -> {
|
||||
Address address = new Address();
|
||||
address.setInfo( "123 Main St." );
|
||||
|
@ -114,7 +112,7 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Address address = session.get( Address.class, id );
|
||||
Person p = new Person();
|
||||
|
@ -123,20 +121,20 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
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
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testCascadeAllFromClearedPersistentAssnToTransientEntity() {
|
||||
public void testCascadeAllFromClearedPersistentAssnToTransientEntity(SessionFactoryScope scope) {
|
||||
final Person p = new Person();
|
||||
Address address = new Address();
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
address.setInfo( "123 Main St." );
|
||||
p.getAddresses().add( address );
|
||||
|
@ -144,7 +142,7 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Suite suite = new Suite();
|
||||
address.getSuites().add( suite );
|
||||
|
@ -153,10 +151,10 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
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 );
|
||||
assertEquals( 1, count.longValue() );
|
||||
count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 );
|
||||
|
@ -167,19 +165,19 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() {
|
||||
public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity(SessionFactoryScope scope) {
|
||||
Address address = new Address();
|
||||
address.setInfo( "123 Main St." );
|
||||
Suite suite = new Suite();
|
||||
address.getSuites().add( suite );
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
|
||||
session.save( address );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Note note = new Note();
|
||||
note.setDescription( "a description" );
|
||||
|
@ -190,13 +188,13 @@ public class DeleteTransientEntityTest extends BaseCoreFunctionalTestCase {
|
|||
);
|
||||
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Long count = (Long) session.createQuery( "select count(*) from Suite" ).list().get( 0 );
|
||||
assertEquals(
|
||||
"all-delete-orphan not cascaded properly to cleared persistent collection entities",
|
||||
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 );
|
||||
assertEquals( 0, count.longValue() );
|
||||
|
|
|
@ -1,45 +1,48 @@
|
|||
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.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
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.SessionFactoryScope;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11426" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DetachedGetIdentifierTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{SimpleEntity.class};
|
||||
}
|
||||
@JiraKey( "HHH-11426" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DetachedGetIdentifierTest.SimpleEntity.class
|
||||
}
|
||||
)
|
||||
@org.hibernate.testing.orm.junit.SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class DetachedGetIdentifierTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
SimpleEntity[] entities = new SimpleEntity[2];
|
||||
entities[0] = new SimpleEntity();
|
||||
entities[0].name = "test";
|
||||
|
||||
TransactionUtil.doInJPA( this::sessionFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
entities[1] = em.merge( entities[0] );
|
||||
assertNotNull( em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier( entities[1] ) );
|
||||
} );
|
||||
|
||||
// Call as detached entity
|
||||
try ( SessionFactory sessionFactory = sessionFactory() ) {
|
||||
try ( SessionFactory sessionFactory = scope.getSessionFactory() ) {
|
||||
assertNotNull( sessionFactory.getPersistenceUnitUtil().getIdentifier( entities[1] ) );
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +51,7 @@ public class DetachedGetIdentifierTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "SimpleEntity")
|
||||
@Table( name = "SIMPLE_ENTITY" )
|
||||
private static class SimpleEntity {
|
||||
static class SimpleEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -12,14 +12,14 @@ import java.util.List;
|
|||
import org.hibernate.Hibernate;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.SessionFactory;
|
||||
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.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -34,27 +34,25 @@ import jakarta.persistence.OneToMany;
|
|||
* @author Christian Beikov
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14387")
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
RemoveUninitializedLazyCollectionTest.Parent.class,
|
||||
RemoveUninitializedLazyCollectionTest.Child1.class,
|
||||
RemoveUninitializedLazyCollectionTest.Child2.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(
|
||||
lazyLoading = true,
|
||||
inlineDirtyChecking = true,
|
||||
biDirectionalAssociationManagement = true
|
||||
)
|
||||
public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTestCase {
|
||||
public class RemoveUninitializedLazyCollectionTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{
|
||||
Parent.class,
|
||||
Child1.class,
|
||||
Child2.class
|
||||
};
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
TransactionUtil.doInJPA(
|
||||
this::sessionFactory,
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Child1" ).executeUpdate();
|
||||
session.createQuery( "delete from Child2" ).executeUpdate();
|
||||
|
@ -63,11 +61,10 @@ public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTes
|
|||
);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
public void setup(SessionFactoryScope scope) {
|
||||
Parent parent = new Parent( 1L, "test" );
|
||||
TransactionUtil.doInJPA(
|
||||
this::sessionFactory,
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.persist( parent );
|
||||
entityManager.persist( new Child2( 1L, "child2", parent ) );
|
||||
|
@ -76,8 +73,8 @@ public class RemoveUninitializedLazyCollectionTest extends BaseCoreFunctionalTes
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef() {
|
||||
EntityManager em = sessionFactory().createEntityManager();
|
||||
public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef(SessionFactoryScope scope) {
|
||||
EntityManager em = scope.getSessionFactory().createEntityManager();
|
||||
try {
|
||||
// Lazily initialize the child1 collection
|
||||
List<Child1> child1 = em.find( Parent.class, 1L ).getChild1();
|
||||
|
|
|
@ -6,34 +6,32 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.dirty;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
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.engine.spi.PersistentAttributeInterceptable;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.CascadeType;
|
||||
import jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
@ -46,35 +44,23 @@ import jakarta.persistence.Table;
|
|||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-14348" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-14348" )
|
||||
@DomainModel(
|
||||
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
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{StringsEntity.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() {
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
StringsEntity entity = new StringsEntity();
|
||||
entity.id = 1L;
|
||||
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
|
||||
|
@ -83,8 +69,8 @@ public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCor
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
entityManager.flush();
|
||||
BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity )
|
||||
|
@ -98,13 +84,14 @@ public class DirtyTrackingCollectionInDefaultFetchGroupFalseTest extends BaseCor
|
|||
// --- //
|
||||
|
||||
@Entity
|
||||
@Table( name = "STRINGS_ENTITY" )
|
||||
private static class StringsEntity {
|
||||
@Table(name = "STRINGS_ENTITY")
|
||||
static class StringsEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
|
||||
List<String> someStrings;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
|
|
@ -11,53 +11,48 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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 static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-14348" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-14348" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingCollectionInDefaultFetchGroupTest.StringsEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingCollectionInDefaultFetchGroupTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{StringsEntity.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( true );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
assertTrue( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
assertTrue( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
scope.inTransaction( em -> {
|
||||
StringsEntity entity = new StringsEntity();
|
||||
entity.id = 1L;
|
||||
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
|
||||
|
@ -66,8 +61,8 @@ public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfi
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
entityManager.flush();
|
||||
|
@ -88,12 +83,13 @@ public class DirtyTrackingCollectionInDefaultFetchGroupTest extends BaseNonConfi
|
|||
|
||||
@Entity
|
||||
@Table( name = "STRINGS_ENTITY" )
|
||||
private static class StringsEntity {
|
||||
static class StringsEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
|
||||
List<String> someStrings;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
|
|
@ -11,53 +11,50 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.CascadeType;
|
||||
import jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-14348" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-14348" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingCollectionNotInDefaultFetchGroupTest.StringsEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory(
|
||||
applyCollectionsInDefaultFetchGroup = false
|
||||
)
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingCollectionNotInDefaultFetchGroupTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{StringsEntity.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( false );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
assertFalse( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
assertFalse( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
scope.inTransaction( em -> {
|
||||
StringsEntity entity = new StringsEntity();
|
||||
entity.id = 1L;
|
||||
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
|
||||
|
@ -66,8 +63,8 @@ public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonCo
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
entityManager.flush();
|
||||
BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) ( (PersistentAttributeInterceptable) entity )
|
||||
|
@ -82,12 +79,13 @@ public class DirtyTrackingCollectionNotInDefaultFetchGroupTest extends BaseNonCo
|
|||
|
||||
@Entity
|
||||
@Table( name = "STRINGS_ENTITY" )
|
||||
private static class StringsEntity {
|
||||
static class StringsEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "STRINGS_ENTITY_SOME", joinColumns = @JoinColumn(name = "SOME_ID"))
|
||||
List<String> someStrings;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.dirty;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -21,24 +22,24 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11293" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-11293" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingCollectionTest.StringsEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingCollectionTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{StringsEntity.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInJPA( this::sessionFactory, em -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
StringsEntity entity = new StringsEntity();
|
||||
entity.id = 1L;
|
||||
entity.someStrings = new ArrayList<>( Arrays.asList( "a", "b", "c" ) );
|
||||
|
@ -47,25 +48,25 @@ public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
entity.someStrings.clear();
|
||||
} );
|
||||
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
assertEquals( 0, entity.someStrings.size() );
|
||||
entity.someStrings.add( "d" );
|
||||
} );
|
||||
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
assertEquals( 1, entity.someStrings.size() );
|
||||
entity.someStrings = new ArrayList<>();
|
||||
} );
|
||||
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
StringsEntity entity = entityManager.find( StringsEntity.class, 1L );
|
||||
assertEquals( 0, entity.someStrings.size() );
|
||||
} );
|
||||
|
@ -75,7 +76,7 @@ public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity
|
||||
@Table( name = "STRINGS_ENTITY" )
|
||||
private static class StringsEntity {
|
||||
static class StringsEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
|
|
@ -4,12 +4,13 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Test;
|
||||
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.DiscriminatorColumn;
|
||||
|
@ -23,26 +24,29 @@ import jakarta.persistence.Table;
|
|||
|
||||
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)
|
||||
public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFunctionalTestCase {
|
||||
public class DirtyTrackingDynamicUpdateAndInheritanceTest {
|
||||
|
||||
public static final int ID = 1;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
SuperEntity.class,
|
||||
ChildEntity.class,
|
||||
AbstractVersion.class,
|
||||
FileVersion.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@JiraKey("HHH-16688")
|
||||
public void testDynamicUpdateWithInheritance() {
|
||||
inTransaction(
|
||||
public void testDynamicUpdateWithInheritance(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
ChildEntity entity = new ChildEntity( ID );
|
||||
entity.setaSuper( "aSuper before" );
|
||||
|
@ -58,7 +62,7 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
|
|||
String aChildNewValue = "aChild after";
|
||||
String bChildNewValue = "bChild after";
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
ChildEntity entity = session.find( ChildEntity.class, ID );
|
||||
entity.setaSuper( aSuperNewValue );
|
||||
|
@ -69,7 +73,7 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
ChildEntity entity = session.find( ChildEntity.class, ID );
|
||||
assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue );
|
||||
|
@ -82,9 +86,8 @@ public class DirtyTrackingDynamicUpdateAndInheritanceTest extends BaseCoreFuncti
|
|||
|
||||
@Test
|
||||
@JiraKey("HHH-16379")
|
||||
public void testWithDynamicUpdate() {
|
||||
|
||||
inTransaction(
|
||||
public void testWithDynamicUpdate(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
FileVersion version = new FileVersion();
|
||||
version.setId( "1" );
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
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.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.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingDynamicUpdateTest.TestEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(inlineDirtyChecking = true)
|
||||
@JiraKey("HHH-16688")
|
||||
public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
||||
public class DirtyTrackingDynamicUpdateTest {
|
||||
|
||||
public static final int ID = 1;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { TestEntity.class };
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
|
||||
TestEntity testEntity = new TestEntity( ID );
|
||||
|
@ -41,14 +43,14 @@ public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDynamicUpdate() {
|
||||
public void testDynamicUpdate(SessionFactoryScope scope) {
|
||||
|
||||
String aSuperNewValue = "aSuper after";
|
||||
String bSuperNewValue = "bSuper after";
|
||||
String aChildNewValue = "aChild after";
|
||||
String bChildNewValue = "bChild after";
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
TestEntity entity = session.find( TestEntity.class, ID );
|
||||
entity.setaSuper( aSuperNewValue );
|
||||
|
@ -59,7 +61,7 @@ public class DirtyTrackingDynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
TestEntity entity = session.find( TestEntity.class, ID );
|
||||
assertThat( entity.getaSuper() ).isEqualTo( aSuperNewValue );
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
*/
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.Embedded;
|
||||
|
@ -19,7 +18,7 @@ import jakarta.persistence.Id;
|
|||
|
||||
@JiraKey( "HHH-16774" )
|
||||
@JiraKey( "HHH-16952" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingEmbeddableTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
*/
|
||||
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.EnhancerTestUtils;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.Jira;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -24,7 +22,7 @@ import jakarta.persistence.MappedSuperclass;
|
|||
* @author Yoann Rodière
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions( inlineDirtyChecking = true )
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-16459" )
|
||||
public class DirtyTrackingInheritanceTest {
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
*/
|
||||
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.EnhancerTestUtils;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.Jira;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -23,7 +22,7 @@ import jakarta.persistence.MappedSuperclass;
|
|||
* @author Yoann Rodière
|
||||
* @author Marco Belladelli
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions( inlineDirtyChecking = true )
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-16459" )
|
||||
public class DirtyTrackingInheritanceWithGenericsTest {
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.dirty;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.Test;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -20,23 +21,22 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Version;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-12051" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class DirtyTrackingNonUpdateableTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Thing.class};
|
||||
}
|
||||
@JiraKey( "HHH-12051" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingNonUpdateableTest.Thing.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingNonUpdateableTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::sessionFactory, entityManager -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Thing thing = new Thing();
|
||||
entityManager.persist( thing );
|
||||
|
||||
|
|
|
@ -11,15 +11,13 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
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 jakarta.persistence.Basic;
|
||||
import jakarta.persistence.CascadeType;
|
||||
|
@ -36,40 +34,37 @@ import jakarta.persistence.OrderColumn;
|
|||
import jakarta.persistence.Temporal;
|
||||
import jakarta.persistence.TemporalType;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14360")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-14360")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingNotInDefaultFetchGroupPersistTest.HotherEntity.class,
|
||||
DirtyTrackingNotInDefaultFetchGroupPersistTest.Hentity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
|
||||
@BytecodeEnhanced
|
||||
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
|
||||
public class DirtyTrackingNotInDefaultFetchGroupPersistTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { HotherEntity.class, Hentity.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( false );
|
||||
}
|
||||
public class DirtyTrackingNotInDefaultFetchGroupPersistTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertFalse( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
public void test(SessionFactoryScope scope) {
|
||||
assertFalse( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
|
||||
Hentity hentity = new Hentity();
|
||||
HotherEntity hotherEntity = new HotherEntity();
|
||||
hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) );
|
||||
hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) );
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( hentity );
|
||||
} );
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
hentity.bumpNumber();
|
||||
session.saveOrUpdate( hentity );
|
||||
} );
|
||||
|
|
|
@ -25,50 +25,46 @@ import jakarta.persistence.OrderColumn;
|
|||
import jakarta.persistence.Temporal;
|
||||
import jakarta.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
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 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
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14360")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-14360")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
DirtyTrackingPersistTest.HotherEntity.class, DirtyTrackingPersistTest.Hentity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
|
||||
public class DirtyTrackingPersistTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { HotherEntity.class, Hentity.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) {
|
||||
super.configureSessionFactoryBuilder( sfb );
|
||||
sfb.applyCollectionsInDefaultFetchGroup( true );
|
||||
}
|
||||
public class DirtyTrackingPersistTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertTrue( sessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
public void test(SessionFactoryScope scope) {
|
||||
assertTrue( scope.getSessionFactory().getSessionFactoryOptions().isCollectionsInDefaultFetchGroupEnabled() );
|
||||
|
||||
Hentity hentity = new Hentity();
|
||||
HotherEntity hotherEntity = new HotherEntity();
|
||||
hentity.setLineItems( new ArrayList<>( Collections.singletonList( hotherEntity ) ) );
|
||||
hentity.setNextRevUNs( new ArrayList<>( Collections.singletonList( "something" ) ) );
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( hentity );
|
||||
} );
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
hentity.bumpNumber();
|
||||
session.saveOrUpdate( hentity );
|
||||
} );
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.dirty;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.Embedded;
|
||||
|
@ -24,7 +23,7 @@ import java.util.Set;
|
|||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
@BytecodeEnhanced
|
||||
public class DirtyTrackingTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -5,12 +5,13 @@ import java.time.LocalDate;
|
|||
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -20,23 +21,22 @@ import jakarta.persistence.OneToOne;
|
|||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class DynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
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 PAYMENT_ID = 2l;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Payment.class,
|
||||
StuffToPay.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Payment payment = new Payment(PAYMENT_ID);
|
||||
payment.setFee( new BigDecimal( 42 ) );
|
||||
|
@ -51,8 +51,8 @@ public class DynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@JiraKey("HHH-16577")
|
||||
public void testSetAttribute() {
|
||||
inTransaction(
|
||||
public void testSetAttribute(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
StuffToPay stuffToPay = session.find( StuffToPay.class, STUFF_TO_PAY_ID );
|
||||
stuffToPay.confirmPayment();
|
||||
|
@ -61,7 +61,7 @@ public class DynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
|||
assertThat( payment.getPaidAt() ).isNotNull(); }
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Payment payment = session.find( Payment.class, PAYMENT_ID );
|
||||
assertThat(payment).isNotNull();
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.eviction;
|
||||
|
||||
import org.hibernate.engine.spi.ManagedEntity;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.SessionFactory;
|
||||
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.GeneratedValue;
|
||||
|
@ -20,27 +22,27 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
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;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class EvictionTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
EvictionTest.Parent.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class EvictionTest {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Parent.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
// Create a Parent
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Parent p = new Parent();
|
||||
p.name = "PARENT";
|
||||
s.persist( p );
|
||||
|
@ -48,8 +50,8 @@ public class EvictionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
|
||||
// Delete the Parent
|
||||
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" )
|
||||
@Table( name = "PARENT" )
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
|
|
|
@ -4,37 +4,37 @@ import java.util.HashSet;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@TestForIssue(jiraKey = "HHH-16337")
|
||||
public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private static final Long MY_ENTITY_ID = 1l;
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CollectionFlushAfterQueryTest.MyEntity.class,
|
||||
CollectionFlushAfterQueryTest.MyOtherEntity.class,
|
||||
CollectionFlushAfterQueryTest.MyAnotherEntity.class
|
||||
};
|
||||
}
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@JiraKey("HHH-16337")
|
||||
public class CollectionFlushAfterQueryTest {
|
||||
|
||||
private static final Long MY_ENTITY_ID = 1l;
|
||||
|
||||
@Test
|
||||
public void testAutoFlush() {
|
||||
inTransaction(
|
||||
public void testAutoFlush(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = new MyEntity( MY_ENTITY_ID, "my entity" );
|
||||
MyOtherEntity otherEntity = new MyOtherEntity( 2l, "my other entity" );
|
||||
|
@ -44,7 +44,7 @@ public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class CollectionFlushAfterQueryTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
MyEntity myEntity = session.find( MyEntity.class, MY_ENTITY_ID );
|
||||
Set<MyOtherEntity> redirectUris = myEntity.getOtherEntities();
|
||||
|
|
|
@ -12,14 +12,14 @@ import org.hibernate.Session;
|
|||
import org.hibernate.annotations.LazyToOne;
|
||||
import org.hibernate.annotations.LazyToOneOption;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
|
@ -33,29 +33,32 @@ import jakarta.persistence.criteria.JoinType;
|
|||
|
||||
import static org.hibernate.Hibernate.isInitialized;
|
||||
import static org.hibernate.Hibernate.isPropertyInitialized;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-3949" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Person.class, Vehicle.class};
|
||||
}
|
||||
@JiraKey( "HHH-3949" )
|
||||
@DomainModel(
|
||||
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
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, false );
|
||||
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, true );
|
||||
// see HHH-3949 for further details ^^^^^
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
|
||||
// it is important that the data associations remain as follows:
|
||||
// * Johnny <-> Volkswagen Golf
|
||||
|
@ -87,19 +90,19 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
performQueryAndVerifyPersonResults( "from Person p left join fetch p.vehicle" );
|
||||
public void test1(SessionFactoryScope scope) {
|
||||
performQueryAndVerifyPersonResults( scope, "from Person p left join fetch p.vehicle" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
performQueryAndVerifyVehicleResults( "from Vehicle v left join fetch v.driver" );
|
||||
public void test2(SessionFactoryScope scope) {
|
||||
performQueryAndVerifyVehicleResults( scope, "from Vehicle v left join fetch v.driver" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public void test3() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test3(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<Person> criteria = criteriaBuilder.createQuery( Person.class );
|
||||
criteria.from( Person.class ).fetch( "vehicle", JoinType.LEFT );
|
||||
|
@ -116,10 +119,10 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public void test4() {
|
||||
public void test4(SessionFactoryScope scope) {
|
||||
List<Vehicle> vehicles;
|
||||
|
||||
try ( Session s = openSession() ) {
|
||||
try ( Session s = scope.getSessionFactory().openSession() ) {
|
||||
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<Vehicle> criteria = criteriaBuilder.createQuery( Vehicle.class );
|
||||
criteria.from( Vehicle.class ).fetch( "driver", JoinType.LEFT );
|
||||
|
@ -138,9 +141,9 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
// --- //
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
private void performQueryAndVerifyPersonResults(String query) {
|
||||
private void performQueryAndVerifyPersonResults(SessionFactoryScope scope, String query) {
|
||||
List<Person> persons;
|
||||
try ( Session s = openSession() ) {
|
||||
try ( Session s = scope.getSessionFactory().openSession() ) {
|
||||
persons = (List<Person>) s.createQuery( query ).list();
|
||||
}
|
||||
for ( Person person : persons ) {
|
||||
|
@ -159,9 +162,9 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
private void performQueryAndVerifyVehicleResults(String query) {
|
||||
private void performQueryAndVerifyVehicleResults(SessionFactoryScope scope, String query) {
|
||||
List<Vehicle> vehicles;
|
||||
try ( Session s = openSession() ) {
|
||||
try ( Session s = scope.getSessionFactory().openSession() ) {
|
||||
vehicles = (List<Vehicle>) s.createQuery( query ).list();
|
||||
}
|
||||
for ( Vehicle vehicle : vehicles ) {
|
||||
|
@ -189,7 +192,7 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "Person" )
|
||||
@Table( name = "PERSON" )
|
||||
private static class Person {
|
||||
static class Person {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -219,7 +222,7 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "Vehicle" )
|
||||
@Table( name = "VEHICLE" )
|
||||
private static class Vehicle {
|
||||
static class Vehicle {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -23,28 +23,27 @@ import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
|
|||
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
|
||||
import org.hibernate.bytecode.enhance.spi.UnloadedField;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
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.EnhancerTestContext;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.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.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests removing non-owning side of the bidirectional association,
|
||||
|
@ -52,31 +51,32 @@ import static org.junit.Assert.assertTrue;
|
|||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-13241")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-13241")
|
||||
@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({
|
||||
EnhancerTestContext.class, // supports laziness and 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
|
||||
// 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
|
||||
public void testRemoveWithDeletedAssociatedEntity() {
|
||||
public void testRemoveWithDeletedAssociatedEntity(SessionFactoryScope scope) {
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
|
||||
Employer employer = new Employer( "RedHat" );
|
||||
|
@ -90,7 +90,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Employer employer = session.get( Employer.class, "RedHat" );
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
assertNull( session.find( Employer.class, "RedHat" ) );
|
||||
assertTrue( session.createQuery( "from Employee e", Employee.class ).getResultList().isEmpty() );
|
||||
|
@ -118,9 +118,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWithNonAssociatedRemovedEntity() {
|
||||
public void testRemoveWithNonAssociatedRemovedEntity(SessionFactoryScope scope) {
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Employer employer = new Employer( "RedHat" );
|
||||
session.persist( employer );
|
||||
|
@ -131,7 +131,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
// Delete an entity that is not associated with Employee
|
||||
session.remove( session.get( Unrelated.class, 1 ) );
|
||||
|
@ -145,7 +145,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
assertNull( session.find( Unrelated.class, 1 ) );
|
||||
assertNull( session.find( Employee.class, "Jack" ) );
|
||||
|
@ -155,9 +155,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWithNoRemovedEntities() {
|
||||
public void testRemoveWithNoRemovedEntities(SessionFactoryScope scope) {
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Employer employer = new Employer( "RedHat" );
|
||||
session.persist( employer );
|
||||
|
@ -167,7 +167,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
// Don't delete any entities before deleting the Employee
|
||||
final Employee employee = session.get( Employee.class, "Jack" );
|
||||
|
@ -178,13 +178,13 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
Employer employer = session.get( Employer.class, "RedHat" );
|
||||
verifyBaseState( employer );
|
||||
|
||||
assertThat( employee.getEmployer(), sameInstance( employer ) );
|
||||
assertThat( employee.getEmployer() ).isInstanceOf( employer.getClass() );
|
||||
|
||||
checkEntityEntryState( session, employee, employer, false );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
assertNull( session.find( Employee.class, "Jack" ) );
|
||||
session.remove( session.find( Employer.class, "RedHat" ) );
|
||||
|
@ -193,9 +193,9 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveEntityWithNullLazyManyToOne() {
|
||||
public void testRemoveEntityWithNullLazyManyToOne(SessionFactoryScope scope) {
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Employer employer = new Employer( "RedHat" );
|
||||
session.persist( employer );
|
||||
|
@ -204,7 +204,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Employee employee = session.get( Employee.class, "Jack" );
|
||||
verifyBaseState( employee );
|
||||
|
@ -224,8 +224,8 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
* deleting the Employer linked to the loaded Employee
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveEntityWithLinkedLazyManyToOne() {
|
||||
inTransaction(
|
||||
public void testRemoveEntityWithLinkedLazyManyToOne(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Employer employer = new Employer( "RedHat" );
|
||||
session.persist( employer );
|
||||
|
@ -235,7 +235,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Employee employee = session.get( Employee.class, "Jack" );
|
||||
verifyBaseState( employee );
|
||||
|
@ -244,7 +244,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
Employer employer = session.get( Employer.class, "RedHat" );
|
||||
verifyBaseState( employer );
|
||||
|
||||
assertThat( employee.getEmployer(), sameInstance( employer ) );
|
||||
assertThat( employee.getEmployer() ).isInstanceOf( employer.getClass() );
|
||||
|
||||
session.remove( employer );
|
||||
session.remove( employee );
|
||||
|
@ -265,7 +265,7 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase {
|
|||
final Employer employer = employee.getEmployer();
|
||||
if ( employer != null ) {
|
||||
assertFalse( Hibernate.isInitialized( employer ) );
|
||||
assertThat(employer, not( instanceOf( HibernateProxy.class ) ) );
|
||||
assertThat( employer ).isNotInstanceOf( HibernateProxy.class );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,15 @@ import java.util.List;
|
|||
import org.hibernate.annotations.DynamicUpdate;
|
||||
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.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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -22,25 +23,24 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@JiraKey("HHH-17049")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
ConstructorInitializationAndDynamicUpdateTest.Person.class,
|
||||
ConstructorInitializationAndDynamicUpdateTest.LoginAccount.class,
|
||||
ConstructorInitializationAndDynamicUpdateTest.AccountPreferences.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
|
||||
public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunctionalTestCase {
|
||||
public class ConstructorInitializationAndDynamicUpdateTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Person.class,
|
||||
LoginAccount.class,
|
||||
AccountPreferences.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = new Person( 1l, "Henry" );
|
||||
LoginAccount loginAccount = new LoginAccount();
|
||||
|
@ -50,7 +50,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -67,9 +67,9 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery( "delete from Person" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from LoginAccount" ).executeUpdate();
|
||||
|
@ -79,15 +79,15 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
inTransaction(
|
||||
public void findTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -105,15 +105,15 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest() {
|
||||
inTransaction(
|
||||
public void getReferenceTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -131,8 +131,8 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest2() {
|
||||
inTransaction(
|
||||
public void findTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
|
@ -142,7 +142,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
@ -167,8 +167,8 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest2() {
|
||||
inTransaction(
|
||||
public void getReferenceTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
|
@ -178,7 +178,7 @@ public class ConstructorInitializationAndDynamicUpdateTest extends BaseCoreFunct
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
|
|
@ -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.NoDirtyCheckEnhancementContext;
|
||||
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -22,25 +23,24 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@JiraKey("HHH-17049")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
ConstructorInitializationTest.Person.class,
|
||||
ConstructorInitializationTest.LoginAccount.class,
|
||||
ConstructorInitializationTest.AccountPreferences.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext({ DirtyCheckEnhancementContext.class, NoDirtyCheckEnhancementContext.class })
|
||||
public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
||||
public class ConstructorInitializationTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Person.class,
|
||||
LoginAccount.class,
|
||||
AccountPreferences.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = new Person( 1l, "Henry" );
|
||||
LoginAccount loginAccount = new LoginAccount();
|
||||
|
@ -50,7 +50,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -67,9 +67,9 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(){
|
||||
inTransaction(
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope){
|
||||
scope.inTransaction(
|
||||
session-> {
|
||||
session.createMutationQuery( "delete from Person" ).executeUpdate();
|
||||
session.createMutationQuery( "delete from LoginAccount" ).executeUpdate();
|
||||
|
@ -79,15 +79,15 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
inTransaction(
|
||||
public void findTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -105,15 +105,15 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest() {
|
||||
inTransaction(
|
||||
public void getReferenceTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<LoginAccount> accounts = session.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
|
@ -131,8 +131,8 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest2() {
|
||||
inTransaction(
|
||||
public void findTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
|
@ -142,7 +142,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
@ -167,8 +167,8 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest2() {
|
||||
inTransaction(
|
||||
public void getReferenceTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
|
@ -178,7 +178,7 @@ public class ConstructorInitializationTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
);
|
||||
|
||||
inTransaction(
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = session.find( Person.class, 1L );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
|
|
@ -10,12 +10,14 @@ import org.hibernate.annotations.Cache;
|
|||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -26,22 +28,21 @@ import jakarta.persistence.Table;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-10708" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10708" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
UnexpectedDeleteTest1.Foo.class, UnexpectedDeleteTest1.Bar.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class UnexpectedDeleteTest1 {
|
||||
|
||||
private long fooId;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{Foo.class, Bar.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Bar bar1 = new Bar();
|
||||
Bar bar2 = new Bar();
|
||||
Foo foo = new Foo();
|
||||
|
@ -55,8 +56,8 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Foo foo = s.get( Foo.class, fooId );
|
||||
|
||||
// accessing the collection results in an exception
|
||||
|
@ -68,7 +69,7 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Bar")
|
||||
@Table( name = "BAR" )
|
||||
private static class Bar {
|
||||
static class Bar {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -81,7 +82,7 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Foo")
|
||||
@Table( name = "FOO" )
|
||||
private static class Foo {
|
||||
static class Foo {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -6,13 +6,15 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
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.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
|
@ -23,22 +25,21 @@ import jakarta.persistence.Table;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-10708" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10708" )
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
UnexpectedDeleteTest2.Foo.class, UnexpectedDeleteTest2.Bar.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class UnexpectedDeleteTest2 {
|
||||
|
||||
private Bar myBar;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{Foo.class, Bar.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Bar bar = new Bar();
|
||||
Foo foo1 = new Foo();
|
||||
Foo foo2 = new Foo();
|
||||
|
@ -54,17 +55,17 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
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
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
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")
|
||||
@Table( name = "BAR" )
|
||||
private static class Bar {
|
||||
static class Bar {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -84,7 +85,7 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Foo")
|
||||
@Table( name = "FOO" )
|
||||
private static class Foo {
|
||||
static class Foo {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.lazy.HHH_10708;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.Column;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
|
@ -25,20 +25,21 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-10708" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-10708")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
UnexpectedDeleteTest3.Parent.class, UnexpectedDeleteTest3.Child.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class UnexpectedDeleteTest3 {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{Parent.class, Child.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Child child = new Child();
|
||||
child.setId( 2L );
|
||||
s.save( child );
|
||||
|
@ -53,8 +54,8 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.get( Parent.class, 1L );
|
||||
|
||||
Child child = new Child();
|
||||
|
@ -67,9 +68,9 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
|
|||
s.save( parent );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
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
|
||||
@Table( name = "CHILD" )
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
Long id;
|
||||
|
||||
|
@ -94,7 +95,7 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity
|
||||
@Table( name = "PARENT" )
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
|
||||
Long id;
|
||||
Set<String> names;
|
||||
|
|
|
@ -11,34 +11,34 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14571")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-14571")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
IdInUninitializedProxyTest.AnEntity.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@EnhancementOptions(lazyLoading = true, extendedEnhancement = true)
|
||||
public class IdInUninitializedProxyTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] { AnEntity.class };
|
||||
}
|
||||
public class IdInUninitializedProxyTest {
|
||||
|
||||
@Test
|
||||
public void testIdIsAlwaysConsideredInitialized() {
|
||||
inTransaction( session -> {
|
||||
public void testIdIsAlwaysConsideredInitialized(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
final AnEntity e = session.byId( AnEntity.class ).getReference( 1 );
|
||||
assertFalse( Hibernate.isInitialized( e ) );
|
||||
// This is the gist of the problem
|
||||
|
@ -52,9 +52,9 @@ public class IdInUninitializedProxyTest extends BaseNonConfigCoreFunctionalTestC
|
|||
} );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareTestData() {
|
||||
inTransaction( session -> {
|
||||
@BeforeEach
|
||||
public void prepareTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
AnEntity anEntity = new AnEntity();
|
||||
anEntity.id = 1;
|
||||
anEntity.name = "George";
|
||||
|
|
|
@ -4,15 +4,16 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -22,26 +23,24 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@JiraKey("HHH-17049")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
JpaConstructorInitializationAndDynamicUpdateTest.Person.class,
|
||||
JpaConstructorInitializationAndDynamicUpdateTest.LoginAccount.class,
|
||||
JpaConstructorInitializationAndDynamicUpdateTest.AccountPreferences.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
|
||||
public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class JpaConstructorInitializationAndDynamicUpdateTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Person.class,
|
||||
LoginAccount.class,
|
||||
AccountPreferences.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
Person person = new Person( 1l, "Henry" );
|
||||
LoginAccount loginAccount = new LoginAccount();
|
||||
loginAccount.setOwner( person );
|
||||
|
@ -50,7 +49,7 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -66,9 +65,9 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.createQuery( "delete from Person" ).executeUpdate();
|
||||
em.createQuery( "delete from LoginAccount" ).executeUpdate();
|
||||
em.createQuery( "delete from AccountPreferences" ).executeUpdate();
|
||||
|
@ -77,15 +76,15 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void findTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -102,15 +101,15 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void getReferenceTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -127,8 +126,8 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest2() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void findTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.find( Person.class, 1L );
|
||||
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 );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
||||
|
@ -162,8 +161,8 @@ public class JpaConstructorInitializationAndDynamicUpdateTest extends BaseEntity
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest2() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void getReferenceTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.getReference( Person.class, 1L );
|
||||
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 );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
||||
|
|
|
@ -3,15 +3,16 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
|||
import java.util.List;
|
||||
|
||||
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.extension.BytecodeEnhanced;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
|
@ -21,26 +22,24 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@JiraKey("HHH-17049")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
JpaConstructorInitializationTest.Person.class,
|
||||
JpaConstructorInitializationTest.LoginAccount.class,
|
||||
JpaConstructorInitializationTest.AccountPreferences.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
|
||||
public class JpaConstructorInitializationTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class JpaConstructorInitializationTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Person.class,
|
||||
LoginAccount.class,
|
||||
AccountPreferences.class
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
Person person = new Person( 1l, "Henry" );
|
||||
LoginAccount loginAccount = new LoginAccount();
|
||||
loginAccount.setOwner( person );
|
||||
|
@ -49,7 +48,7 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -65,9 +64,9 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.createQuery( "delete from Person" ).executeUpdate();
|
||||
em.createQuery( "delete from LoginAccount" ).executeUpdate();
|
||||
em.createQuery( "delete from AccountPreferences" ).executeUpdate();
|
||||
|
@ -76,15 +75,15 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void findTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.find( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -101,15 +100,15 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void getReferenceTest(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.getReference( Person.class, 1L );
|
||||
person.setFirstName( "Liza" );
|
||||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
scope.inTransaction( em -> {
|
||||
List<LoginAccount> accounts = em.createQuery(
|
||||
"select la from LoginAccount la",
|
||||
LoginAccount.class
|
||||
|
@ -126,8 +125,8 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void findTest2() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void findTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.find( Person.class, 1L );
|
||||
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 );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
||||
|
@ -161,8 +160,8 @@ public class JpaConstructorInitializationTest extends BaseEntityManagerFunctiona
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getReferenceTest2() {
|
||||
doInJPA( this::entityManagerFactory, em -> {
|
||||
public void getReferenceTest2(SessionFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.clear();
|
||||
Person person = em.getReference( Person.class, 1L );
|
||||
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 );
|
||||
assertThat( person.getFirstName() ).isEqualTo( "Liza" );
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
||||
|
||||
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.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 jakarta.persistence.DiscriminatorColumn;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
|
@ -22,38 +22,31 @@ import jakarta.persistence.JoinColumn;
|
|||
import jakarta.persistence.ManyToOne;
|
||||
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")
|
||||
public class LazyAbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase {
|
||||
public class LazyAbstractManyToOneNoProxyTest {
|
||||
|
||||
private static final String USER_1_NAME = "Andrea";
|
||||
private static final String USER_2_NAME = "Fab";
|
||||
private static final String USER_GROUP_1_NAME = "group1";
|
||||
private static final String USER_GROUP_2_NAME = "group2";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
User.class,
|
||||
UserGroup.class,
|
||||
};
|
||||
SQLStatementInspector statementInspector(SessionFactoryScope scope) {
|
||||
return (SQLStatementInspector) scope.getSessionFactory().getSessionFactoryOptions().getStatementInspector();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterConfigurationBuilt(Configuration configuration) {
|
||||
super.afterConfigurationBuilt( configuration );
|
||||
configuration.setStatementInspector( new SQLStatementInspector() );
|
||||
}
|
||||
|
||||
SQLStatementInspector statementInspector() {
|
||||
return (SQLStatementInspector) sessionFactory().getSessionFactoryOptions().getStatementInspector();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inTransaction(
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
UserGroup group1 = new UserGroup( 1l, USER_GROUP_1_NAME );
|
||||
UserGroup group2 = new UserGroup( 2l, USER_GROUP_2_NAME );
|
||||
|
@ -70,10 +63,10 @@ public class LazyAbstractManyToOneNoProxyTest extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
inTransaction(
|
||||
public void testSelect(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
SQLStatementInspector statementInspector = statementInspector();
|
||||
SQLStatementInspector statementInspector = statementInspector( scope );
|
||||
statementInspector.clear();
|
||||
|
||||
User user = session.getReference( User.class, 1 );
|
||||
|
|
|
@ -17,43 +17,34 @@ import jakarta.persistence.Lob;
|
|||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.tuple.NonIdentifierAttribute;
|
||||
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.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
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.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11117")
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class LazyBasicFieldMergeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Company.class,
|
||||
Manager.class,
|
||||
};
|
||||
}
|
||||
@JiraKey("HHH-11117")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
LazyBasicFieldMergeTest.Company.class,
|
||||
LazyBasicFieldMergeTest.Manager.class,
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class LazyBasicFieldMergeTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
Manager manager = new Manager();
|
||||
manager.setName("John Doe");
|
||||
manager.setResume(new byte[] {1, 2, 3});
|
||||
|
|
|
@ -8,19 +8,21 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.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.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -30,33 +32,34 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-9937")
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-9937")
|
||||
@DomainModel(
|
||||
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;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{TestEntity.class};
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
TestEntity entity = new TestEntity();
|
||||
entity.description = "desc";
|
||||
s.persist( entity );
|
||||
|
@ -65,18 +68,18 @@ public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
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()
|
||||
.getEntityDescriptor( TestEntity.class );
|
||||
|
||||
boolean[] propertyLaziness = entityPersister.getPropertyLaziness();
|
||||
assertEquals( 1, propertyLaziness.length );
|
||||
assertTrue( propertyLaziness[0] );
|
||||
Assertions.assertTrue( propertyLaziness[0] );
|
||||
|
||||
// Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551)
|
||||
final AttributeMapping theBytesAttr = entityPersister.findAttributeMapping( "description" );
|
||||
|
@ -89,7 +92,7 @@ public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Entity(name = "TestEntity")
|
||||
@Table( name = "TEST_ENTITY" )
|
||||
private static class TestEntity {
|
||||
static class TestEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
|
|
@ -7,14 +7,16 @@
|
|||
package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -29,32 +31,34 @@ import jakarta.persistence.Table;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-11576" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-11576")
|
||||
@DomainModel(
|
||||
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;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Post.class, Tag.class, AdditionalDetails.class};
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Post post = new Post();
|
||||
|
||||
Tag tag1 = new Tag( "tag1" );
|
||||
|
@ -75,8 +79,8 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Query query = s.createQuery( "from AdditionalDetails where id=" + postId );
|
||||
AdditionalDetails additionalDetails = (AdditionalDetails) query.getSingleResult();
|
||||
additionalDetails.details = "New data";
|
||||
|
@ -85,11 +89,11 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
|||
// additionalDetails.post.tags get deleted on commit
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
Query query = s.createQuery( "from Post where id=" + postId );
|
||||
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 ) );
|
||||
} );
|
||||
}
|
||||
|
@ -98,7 +102,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "Tag" )
|
||||
@Table( name = "TAG" )
|
||||
private static class Tag {
|
||||
static class Tag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -116,7 +120,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "Post" )
|
||||
@Table( name = "POST" )
|
||||
private static class Post {
|
||||
static class Post {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
@ -131,7 +135,7 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity( name = "AdditionalDetails" )
|
||||
@Table( name = "ADDITIONAL_DETAILS" )
|
||||
private static class AdditionalDetails {
|
||||
static class AdditionalDetails {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
|
|
@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.notNullValue;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hibernate.Hibernate.isInitialized;
|
||||
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -29,28 +28,32 @@ import jakarta.persistence.OneToMany;
|
|||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-12260")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-12260")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
LazyCollectionDetachTest.Parent.class, LazyCollectionDetachTest.Child.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class LazyCollectionDetachTest {
|
||||
|
||||
private static final int CHILDREN_SIZE = 10;
|
||||
private Long parentID;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{ Parent.class, Child.class };
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = new Parent();
|
||||
parent.setChildren( new ArrayList<>() );
|
||||
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
|
||||
public void testDetach() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testDetach(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.find( Parent.class, parentID );
|
||||
|
||||
assertThat( parent, notNullValue() );
|
||||
|
@ -80,8 +88,8 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetachProxy() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testDetachProxy(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.getReference( Parent.class, parentID );
|
||||
|
||||
checkDirtyTracking( parent );
|
||||
|
@ -93,8 +101,8 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRefresh() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testRefresh(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.find( Parent.class, parentID );
|
||||
|
||||
assertThat( parent, notNullValue() );
|
||||
|
@ -111,7 +119,7 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Parent")
|
||||
@Table(name = "PARENT")
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
@ -127,7 +135,7 @@ public class LazyCollectionDetachTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity(name = "Child")
|
||||
@Table(name = "CHILD")
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
|
|
@ -12,24 +12,20 @@ import static org.hamcrest.CoreMatchers.notNullValue;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hibernate.Hibernate.isPropertyInitialized;
|
||||
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.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -47,38 +43,23 @@ import jakarta.persistence.Table;
|
|||
* <p>
|
||||
* Kept here for <a href="https://github.com/hibernate/hibernate-orm/pull/5252#pullrequestreview-1095843220">historical reasons</a>.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12260")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey("HHH-12260")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest.Parent.class,
|
||||
LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest.Child.class
|
||||
}
|
||||
)
|
||||
@SessionFactory(applyCollectionsInDefaultFetchGroup = false)
|
||||
@BytecodeEnhanced
|
||||
public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest {
|
||||
|
||||
private static final int CHILDREN_SIZE = 10;
|
||||
private Long parentID;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
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() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = new Parent();
|
||||
parent.setChildren( new ArrayList<>() );
|
||||
for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
|
||||
|
@ -92,8 +73,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetach() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testDetach(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.find( Parent.class, parentID );
|
||||
|
||||
assertThat( parent, notNullValue() );
|
||||
|
@ -108,8 +89,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetachProxy() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testDetachProxy(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.getReference( Parent.class, parentID );
|
||||
|
||||
checkDirtyTracking( parent );
|
||||
|
@ -121,8 +102,8 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRefresh() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testRefresh(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.find( Parent.class, parentID );
|
||||
|
||||
assertThat( parent, notNullValue() );
|
||||
|
@ -139,7 +120,7 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
|
|||
|
||||
@Entity(name = "Parent")
|
||||
@Table(name = "PARENT")
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
@ -155,7 +136,7 @@ public class LazyCollectionDetachWithCollectionInDefaultFetchGroupFalseTest exte
|
|||
|
||||
@Entity(name = "Child")
|
||||
@Table(name = "CHILD")
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -18,28 +16,26 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@TestForIssue(jiraKey = "")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
public class LazyCollectionHandlingTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
LazyCollectionHandlingTest.JafSid.class, LazyCollectionHandlingTest.UserGroup.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
public class LazyCollectionHandlingTest {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
JafSid.class, UserGroup.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
JafSid sid = new JafSid();
|
||||
s.save( sid );
|
||||
|
||||
|
@ -49,7 +45,7 @@ public class LazyCollectionHandlingTest extends BaseCoreFunctionalTestCase {
|
|||
this.id = sid.getId();
|
||||
});
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
s.get( JafSid.class, this.id );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -9,14 +9,16 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
|||
import org.hibernate.annotations.LazyToOne;
|
||||
import org.hibernate.annotations.LazyToOneOption;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
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.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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
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.isPropertyInitialized;
|
||||
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.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Simple test for lazy collection handling in the new bytecode support.
|
||||
|
@ -52,27 +53,28 @@ import static org.junit.Assert.assertTrue;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-10055" )
|
||||
@RunWith( BytecodeEnhancerRunner.class )
|
||||
public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
||||
@JiraKey( "HHH-10055" )
|
||||
@DomainModel(
|
||||
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 Long parentID;
|
||||
private Parent parent;
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{Parent.class, Child.class};
|
||||
}
|
||||
|
||||
@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 -> {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = new Parent();
|
||||
parent.setChildren( new ArrayList<>() );
|
||||
for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
|
||||
|
@ -86,8 +88,8 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTransaction() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testTransaction(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
Parent parent = s.load( Parent.class, parentID );
|
||||
assertThat( parent, notNullValue() );
|
||||
assertThat( parent, not( instanceOf( HibernateProxy.class ) ) );
|
||||
|
@ -109,9 +111,9 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-14620" )
|
||||
public void testTransaction_noProxy() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
@JiraKey( "HHH-14620" )
|
||||
public void testTransaction_noProxy(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
// find will not return a proxy, which is exactly what we want here.
|
||||
Parent parent = s.find( Parent.class, parentID );
|
||||
assertThat( parent, notNullValue() );
|
||||
|
@ -136,8 +138,8 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNoTransaction() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void testNoTransaction(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
parent = s.load( Parent.class, parentID );
|
||||
assertThat( parent, notNullValue() );
|
||||
assertThat( parent, not( instanceOf( HibernateProxy.class ) ) );
|
||||
|
@ -161,7 +163,7 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity
|
||||
@Table( name = "PARENT" )
|
||||
private static class Parent {
|
||||
static class Parent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
|
@ -177,7 +179,7 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Entity
|
||||
@Table( name = "CHILD" )
|
||||
private static class Child {
|
||||
static class Child {
|
||||
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.orm.test.bytecode.enhancement.lazy;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
|
@ -17,30 +15,33 @@ import jakarta.persistence.Lob;
|
|||
import jakarta.persistence.Table;
|
||||
|
||||
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.EnhancerTestContext;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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.Test;
|
||||
|
||||
/**
|
||||
* @author Guillaume Smet
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12633")
|
||||
@RunWith(BytecodeEnhancerRunner.class)
|
||||
@JiraKey("HHH-12633")
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
LazyInitializationWithoutInlineDirtyTrackingTest.File.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@BytecodeEnhanced
|
||||
@CustomEnhancementContext( {EnhancerTestContext.class, LazyInitializationWithoutInlineDirtyTrackingTest.NoInlineDirtyTrackingContext.class} )
|
||||
public class LazyInitializationWithoutInlineDirtyTrackingTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{ File.class };
|
||||
}
|
||||
public class LazyInitializationWithoutInlineDirtyTrackingTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
File file = new File();
|
||||
file.setId( 1L );
|
||||
file.setName( "file" );
|
||||
|
@ -49,7 +50,7 @@ public class LazyInitializationWithoutInlineDirtyTrackingTest extends BaseCoreFu
|
|||
s.persist( file );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
scope.inTransaction( s -> {
|
||||
File file = s.find( File.class, 1L );
|
||||
file.setBytes( new byte[]{ 1 } );
|
||||
s.persist( file );
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue