Re-enabled additional tests
This commit is contained in:
parent
96be013089
commit
3022371d3e
|
@ -6,73 +6,85 @@
|
|||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test of collection reattachment semantics
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CollectionReattachmentTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "reattachment/Mappings.hbm.xml" };
|
||||
@DomainModel(
|
||||
xmlMappings = " org/hibernate/test/reattachment/Mappings.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class CollectionReattachmentTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Child" ).executeUpdate();
|
||||
session.createQuery( "delete from Parent" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateOwnerAfterClear() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = new Parent( "p" );
|
||||
p.getChildren().add( new Child( "c" ) );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
public void testUpdateOwnerAfterClear(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
p.getChildren().add( new Child( "c" ) );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
p = ( Parent ) s.get( Parent.class, "p" );
|
||||
// clear...
|
||||
s.clear();
|
||||
// now try to reattach...
|
||||
s.update( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.get( Parent.class, "p" );
|
||||
// clear...
|
||||
session.clear();
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateOwnerAfterEvict() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = new Parent( "p" );
|
||||
p.getChildren().add( new Child( "c" ) );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
public void testUpdateOwnerAfterEvict(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
p.getChildren().add( new Child( "c" ) );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
p = ( Parent ) s.get( Parent.class, "p" );
|
||||
// evict...
|
||||
s.evict( p );
|
||||
// now try to reattach...
|
||||
s.update( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.get( Parent.class, "p" );
|
||||
// evict...
|
||||
session.evict( p );
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,253 +6,265 @@
|
|||
*/
|
||||
package org.hibernate.test.reattachment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test of proxy reattachment semantics
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "reattachment/Mappings.hbm.xml" };
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/test/reattachment/Mappings.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class ProxyReattachmentTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Parent" );
|
||||
session.createQuery( "delete from Child" );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterEvict() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = new Parent( "p" );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
public void testUpdateAfterEvict(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
p = ( Parent ) s.load( Parent.class, "p" );
|
||||
// evict...
|
||||
s.evict( p );
|
||||
// now try to reattach...
|
||||
s.update( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// evict...
|
||||
session.evict( p );
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAfterClear() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = new Parent( "p" );
|
||||
s.save( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
public void testUpdateAfterClear(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent p = new Parent( "p" );
|
||||
session.save( p );
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
p = ( Parent ) s.load( Parent.class, "p" );
|
||||
// clear...
|
||||
s.clear();
|
||||
// now try to reattach...
|
||||
s.update( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
Parent parent = scope.fromTransaction(
|
||||
session -> {
|
||||
Parent p = session.load( Parent.class, "p" );
|
||||
// clear...
|
||||
session.clear();
|
||||
// now try to reattach...
|
||||
session.update( p );
|
||||
return p;
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.delete( parent )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithClearTopOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithClearTopOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
int i = 0;
|
||||
List<Parent> fromParent = s.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
i++;
|
||||
if (i % 2 == 0) {
|
||||
s.flush();
|
||||
s.clear();
|
||||
}
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int i = 0;
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
i++;
|
||||
if ( i % 2 == 0 ) {
|
||||
session.flush();
|
||||
session.clear();
|
||||
}
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithClearBottomOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithClearBottomOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
int i = 0;
|
||||
List<Parent> fromParent = s.createQuery( "from Parent" ).list();
|
||||
for (Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
i++;
|
||||
if (i % 2 == 0) {
|
||||
s.flush();
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
int i = 0;
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
i++;
|
||||
if ( i % 2 == 0 ) {
|
||||
session.flush();
|
||||
session.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithEvictTopOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithEvictTopOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
List<Parent> fromParent = s.createQuery( "from Parent" ).list();
|
||||
for (Parent p : fromParent ) {
|
||||
if ( p != null) { s.evict(p); }
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
if ( p != null ) {
|
||||
session.evict( p );
|
||||
}
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public void testIterateWithEvictBottomOfLoop() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testIterateWithEvictBottomOfLoop(SessionFactoryScope scope) {
|
||||
Set parents = new HashSet();
|
||||
for (int i=0; i<5; i++) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
s.save( p );
|
||||
parents.add(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
Parent p = new Parent( String.valueOf( i + 100 ) );
|
||||
Child child = new Child( "child" + i );
|
||||
child.setParent( p );
|
||||
p.getChildren().add( child );
|
||||
session.save( p );
|
||||
parents.add( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
List<Parent> fromParent = s.createQuery( "from Parent" ).list();
|
||||
for (Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
s.evict(p);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Parent> fromParent = session.createQuery( "from Parent" ).list();
|
||||
for ( Parent p : fromParent ) {
|
||||
assertEquals( 1, p.getChildren().size() );
|
||||
session.evict( p );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( Object parent : parents ) {
|
||||
s.delete( parent );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
for ( Object parent : parents ) {
|
||||
session.delete( parent );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8374")
|
||||
public void testRemoveAndReattachProxyEntity() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Parent p = new Parent("foo");
|
||||
s.persist( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
public void testRemoveAndReattachProxyEntity(SessionFactoryScope scope) {
|
||||
Parent p = new Parent( "foo" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( p );
|
||||
}
|
||||
);
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
p = (Parent) s.load( Parent.class, p.getName() );
|
||||
s.delete( p );
|
||||
// re-attach
|
||||
s.persist( p );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Parent parent = session.load( Parent.class, p.getName() );
|
||||
session.delete( parent );
|
||||
// re-attach
|
||||
session.persist( parent );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue