Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2020-06-17 11:26:18 +01:00
parent 2d0aad36b8
commit 567b6cc076
33 changed files with 1027 additions and 1051 deletions

View File

@ -0,0 +1,54 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.annotations.array;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.orm.test.annotations.array.Contest.Month;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Emmanuel Bernard
*/
@DomainModel(annotatedClasses = { Competitor.class, Contest.class})
@SessionFactory
public class ArrayTest {
@Test
public void testOneToMany(SessionFactoryScope scope) {
Competitor c1 = new Competitor();
c1.setName( "Renault" );
Competitor c2 = new Competitor();
c2.setName( "Ferrari" );
Contest c = new Contest();
c.setResults( new Competitor[]{c1, c2} );
c.setHeldIn(new Month[]{Month.January, Month.December});
scope.inTransaction(
session -> {
session.persist( c );
}
);
scope.inTransaction(
session -> {
Contest contest = session.get( Contest.class, c.getId() );
assertNotNull( contest );
assertNotNull( contest.getResults() );
assertEquals( 2, contest.getResults().length );
assertEquals( c2.getName(), contest.getResults()[1].getName() );
assertEquals( 2, contest.getHeldIn().length );
assertEquals( Month.January, contest.getHeldIn()[0] );
}
);
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.array;
package org.hibernate.orm.test.annotations.array;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.array;
package org.hibernate.orm.test.annotations.array;
import javax.persistence.CascadeType;
import javax.persistence.ElementCollection;

View File

@ -0,0 +1,115 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id$
package org.hibernate.orm.test.annotations.backquotes;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.jboss.logging.Logger;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Testcase for ANN-718 - @JoinTable / @JoinColumn fail when using backquotes in PK field name.
*
* @author Hardy Ferentschik
*/
public class BackquoteTest {
private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory;
private final Logger log = Logger.getLogger( getClass() );
@BeforeEach
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
@AfterEach
public void tearDown() {
if ( sessionFactory != null ) {
sessionFactory.close();
}
if ( serviceRegistry != null ) {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@Test
@TestForIssue(jiraKey = "ANN-718")
public void testBackquotes() {
try {
Configuration config = new Configuration();
config.addAnnotatedClass( Bug.class );
config.addAnnotatedClass( Category.class );
sessionFactory = config.buildSessionFactory( serviceRegistry );
}
catch (Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace( new PrintWriter( writer ) );
log.debug( writer.toString() );
fail( e.getMessage() );
}
finally {
if ( sessionFactory != null ) {
sessionFactory.close();
sessionFactory = null;
}
}
}
/**
* HHH-4647 : Problems with @JoinColumn referencedColumnName and quoted column and table names
* <p>
* An invalid referencedColumnName to an entity having a quoted table name results in an
* infinite loop in o.h.c.Configuration$MappingsImpl#getPhysicalColumnName().
* The same issue exists with getLogicalColumnName()
*/
@Test
@TestForIssue(jiraKey = "HHH-4647")
public void testInvalidReferenceToQuotedTableName() {
try {
Configuration config = new Configuration();
config.addAnnotatedClass( Printer.class );
config.addAnnotatedClass( PrinterCable.class );
sessionFactory = config.buildSessionFactory( serviceRegistry );
fail( "expected MappingException to be thrown" );
}
//we WANT MappingException to be thrown
catch (MappingException e) {
assertTrue( true, "MappingException was thrown");
}
catch (Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace( new PrintWriter( writer ) );
log.debug( writer.toString() );
fail( e.getMessage() );
}
finally {
if ( sessionFactory != null ) {
sessionFactory.close();
sessionFactory = null;
}
}
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.backquotes;
package org.hibernate.orm.test.annotations.backquotes;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -6,7 +6,7 @@
*/
//$Id$
package org.hibernate.test.annotations.backquotes;
package org.hibernate.orm.test.annotations.backquotes;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -5,7 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.backquotes;
package org.hibernate.orm.test.annotations.backquotes;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

View File

@ -5,7 +5,7 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.backquotes;
package org.hibernate.orm.test.annotations.backquotes;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.basic;
package org.hibernate.orm.test.annotations.basic;
import java.util.HashSet;
import java.util.Set;
@ -26,13 +26,12 @@ import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
import org.hibernate.type.descriptor.java.MutableMutabilityPlan;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Steve Ebersole
*/
public class CollectionAsBasicTest extends BaseUnitTestCase {
public class CollectionAsBasicTest {
@Test
public void testCollectionAsBasic() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();

View File

@ -1,4 +1,3 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@ -9,156 +8,147 @@ package org.hibernate.orm.test.annotations.cascade;
import java.util.ArrayList;
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.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Check some of the individual cascade styles
*
* <p>
* TODO: do something for refresh
*
* @author Emmanuel Bernard
*/
public class CascadeTest extends BaseCoreFunctionalTestCase {
@Test
public void testPersist() {
Session s;
Transaction tx;
s = openSession();
Tooth tooth = new Tooth();
Tooth leftTooth = new Tooth();
tooth.leftNeighbour = leftTooth;
s.persist( tooth );
tx = s.beginTransaction();
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
leftTooth = (Tooth) s.get( Tooth.class, leftTooth.id );
assertNotNull( leftTooth );
tx.commit();
s.close();
}
@Test
public void testMerge() {
Session s;
Transaction tx;
s = openSession();
Tooth tooth = new Tooth();
Tooth rightTooth = new Tooth();
tooth.type = "canine";
tooth.rightNeighbour = rightTooth;
rightTooth.type = "incisive";
s.persist( rightTooth );
s.persist( tooth );
tx = s.beginTransaction();
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
tooth = (Tooth) s.get( Tooth.class, tooth.id );
assertEquals( "incisive", tooth.rightNeighbour.type );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
tooth.rightNeighbour.type = "premolars";
s.merge( tooth );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
rightTooth = (Tooth) s.get( Tooth.class, rightTooth.id );
assertEquals( "premolars", rightTooth.type );
tx.commit();
s.close();
}
@Test
public void testRemove() {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Tooth tooth = new Tooth();
Mouth mouth = new Mouth();
s.persist( mouth );
s.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<Tooth>();
mouth.teeth.add( tooth );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
tooth = (Tooth) s.get( Tooth.class, tooth.id );
assertNotNull( tooth );
s.delete( tooth.mouth );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
tooth = (Tooth) s.get( Tooth.class, tooth.id );
assertNull( tooth );
tx.commit();
s.close();
}
@Test
public void testDetach() {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Tooth tooth = new Tooth();
Mouth mouth = new Mouth();
s.persist( mouth );
s.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<Tooth>();
mouth.teeth.add( tooth );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
mouth = (Mouth) s.get( Mouth.class, mouth.id );
assertNotNull( mouth );
assertEquals( 1, mouth.teeth.size() );
tooth = mouth.teeth.iterator().next();
s.evict( mouth );
assertFalse( s.contains( tooth ) );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
s.delete( s.get( Mouth.class, mouth.id ) );
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
@DomainModel(
annotatedClasses = {
Mouth.class,
Tooth.class
};
}
)
@SessionFactory
public class CascadeTest {
@Test
public void testPersist(SessionFactoryScope scope) {
Tooth leftTooth = new Tooth();
scope.inTransaction(
session -> {
Tooth tooth = new Tooth();
tooth.leftNeighbour = leftTooth;
session.persist( tooth );
}
);
scope.inTransaction(
session -> {
Tooth tooth = ( session.get( Tooth.class, leftTooth.id ) );
assertNotNull( tooth );
}
);
}
@Test
public void testMerge(SessionFactoryScope scope) {
Tooth t = new Tooth();
Tooth rightTooth = new Tooth();
scope.inTransaction(
session -> {
t.type = "canine";
t.rightNeighbour = rightTooth;
rightTooth.type = "incisive";
session.persist( rightTooth );
session.persist( t );
}
);
Tooth tooth = scope.fromTransaction(
session -> {
Tooth result = session.get( Tooth.class, t.id );
assertEquals( "incisive", t.rightNeighbour.type );
return result;
}
);
scope.inTransaction(
session -> {
tooth.rightNeighbour.type = "premolars";
session.merge( tooth );
}
);
scope.inTransaction(
session -> {
Tooth result = session.get( Tooth.class, rightTooth.id );
assertEquals( "premolars", result.type );
}
);
}
@Test
public void testRemove(SessionFactoryScope scope) {
Tooth tooth = new Tooth();
scope.inTransaction(
session -> {
Mouth mouth = new Mouth();
session.persist( mouth );
session.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<>();
mouth.teeth.add( tooth );
}
);
scope.inTransaction(
session -> {
Tooth t = session.get( Tooth.class, tooth.id );
assertNotNull( t );
session.delete( t.mouth );
}
);
scope.inTransaction(
session -> {
Tooth t = session.get( Tooth.class, tooth.id );
assertNull( t );
}
);
}
@Test
public void testDetach(SessionFactoryScope scope) {
Mouth mouth = new Mouth();
scope.inTransaction(
session -> {
Tooth tooth = new Tooth();
session.persist( mouth );
session.persist( tooth );
tooth.mouth = mouth;
mouth.teeth = new ArrayList<>();
mouth.teeth.add( tooth );
}
);
scope.inTransaction(
session -> {
Mouth m = session.get( Mouth.class, mouth.id );
assertNotNull( m );
assertEquals( 1, m.teeth.size() );
Tooth tooth = m.teeth.iterator().next();
session.evict( m );
assertFalse( session.contains( tooth ) );
}
);
scope.inTransaction(
session ->
session.delete( session.get( Mouth.class, mouth.id ) )
);
}
}

View File

@ -7,59 +7,67 @@
package org.hibernate.orm.test.annotations.cascade;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.Transaction;
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;
public class CascadeToEmbeddedManyToOneTest extends BaseCoreFunctionalTestCase {
@Test
public void testPersistCascadeToSetOfEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
sess.persist( new CodedPairSetHolder( "CODE", setOfPairs ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Test
public void testPersistCascadeToEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"));
sess.persist( new CodedPairHolder( "CODE", personPair ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
@DomainModel(
annotatedClasses = {
CodedPairSetHolder.class,
CodedPairHolder.class,
Person.class,
PersonPair.class
};
}
)
@SessionFactory
public class CascadeToEmbeddedManyToOneTest {
@AfterEach
public void teaDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List<CodedPairHolder> pairHolders = session.createQuery( "select p from CodedPairHolder p" ).list();
pairHolders.forEach(
pairHolder -> {
PersonPair pair = pairHolder.getPair();
session.delete( pairHolder );
session.delete(pair.getLeft());
session.delete(pair.getRight());
}
);
}
);
}
@Test
public void testPersistCascadeToSetOfEmbedded(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
final Set<PersonPair> setOfPairs = new HashSet<>();
setOfPairs.add( new PersonPair( new Person( "PERSON NAME 1" ), new Person( "PERSON NAME 2" ) ) );
session.persist( new CodedPairSetHolder( "CODE", setOfPairs ) );
session.flush();
}
);
}
@Test
public void testPersistCascadeToEmbedded(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
PersonPair personPair = new PersonPair(
new Person( "PERSON NAME 1" ),
new Person( "PERSON NAME 2" )
);
session.persist( new CodedPairHolder( "CODE", personPair ) );
session.flush();
}
);
}
}

View File

@ -8,53 +8,51 @@ package org.hibernate.orm.test.annotations.cascade;
import java.util.HashSet;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.TransientPropertyValueException;
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.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Jeff Schnitzer
* @author Gail Badner
*/
@SuppressWarnings("unchecked")
public class NonNullableCircularDependencyCascadeTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = {
Child.class,
Parent.class
}
)
@SessionFactory
public class NonNullableCircularDependencyCascadeTest {
@Test
public void testIdClassInSuperclass() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
public void testIdClassInSuperclass(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Parent p = new Parent();
p.setChildren( new HashSet<Child>() );
Child ch = new Child(p);
p.getChildren().add(ch);
p.setDefaultChild(ch);
Child ch = new Child( p );
p.getChildren().add( ch );
p.setDefaultChild( ch );
try {
s.persist(p);
s.flush();
session.persist( p );
session.flush();
fail( "should have failed because of transient entities have non-nullable, circular dependency." );
}
catch (IllegalStateException ex) {
// expected
assertThat( ex.getCause(), instanceOf( TransientPropertyValueException.class ) );
}
tx.rollback();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
Child.class,
Parent.class
};
);
}
}

View File

@ -6,19 +6,33 @@
*/
package org.hibernate.orm.test.annotations.cascade.circle.identity;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@DomainModel(
annotatedClasses = {
A.class,
B.class,
C.class,
D.class,
E.class,
F.class,
G.class,
H.class
}
)
@SessionFactory
public class CascadeCircleIdentityIdTest {
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class CascadeCircleIdentityIdTest extends BaseCoreFunctionalTestCase {
@Test
@TestForIssue( jiraKey = "HHH-5472" )
public void testCascade() {
@TestForIssue(jiraKey = "HHH-5472")
public void testCascade(SessionFactoryScope scope) {
A a = new A();
B b = new B();
C c = new C();
@ -28,55 +42,37 @@ public class CascadeCircleIdentityIdTest extends BaseCoreFunctionalTestCase {
G g = new G();
H h = new H();
a.getBCollection().add(b);
b.setA(a);
a.getBCollection().add( b );
b.setA( a );
a.getCCollection().add(c);
c.setA(a);
a.getCCollection().add( c );
c.setA( a );
b.getCCollection().add(c);
c.setB(b);
b.getCCollection().add( c );
c.setB( b );
a.getDCollection().add(d);
d.getACollection().add(a);
a.getDCollection().add( d );
d.getACollection().add( a );
d.getECollection().add(e);
e.setF(f);
d.getECollection().add( e );
e.setF( f );
f.getBCollection().add(b);
b.setF(f);
f.getBCollection().add( b );
b.setF( f );
c.setG(g);
g.getCCollection().add(c);
c.setG( g );
g.getCCollection().add( c );
f.setH(h);
h.setG(g);
f.setH( h );
h.setG( g );
Session s;
s = openSession();
s.getTransaction().begin();
try {
scope.inTransaction(
session -> {
// Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h instead of a
s.persist(a);
s.flush();
} finally {
s.getTransaction().rollback();
s.close();
session.persist( a );
session.flush();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
A.class,
B.class,
C.class,
D.class,
E.class,
F.class,
G.class,
H.class
};
);
}
}

View File

@ -6,19 +6,33 @@
*/
package org.hibernate.orm.test.annotations.cascade.circle.sequence;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
@DomainModel(
annotatedClasses = {
A.class,
B.class,
C.class,
D.class,
E.class,
F.class,
G.class,
H.class
}
)
@SessionFactory
public class CascadeCircleSequenceIdTest {
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class CascadeCircleSequenceIdTest extends BaseCoreFunctionalTestCase {
@Test
@TestForIssue( jiraKey = "HHH-5472" )
public void testCascade() {
@TestForIssue(jiraKey = "HHH-5472")
public void testCascade(SessionFactoryScope scope) {
A a = new A();
B b = new B();
C c = new C();
@ -28,55 +42,37 @@ public class CascadeCircleSequenceIdTest extends BaseCoreFunctionalTestCase {
G g = new G();
H h = new H();
a.getBCollection().add(b);
b.setA(a);
a.getBCollection().add( b );
b.setA( a );
a.getCCollection().add(c);
c.setA(a);
a.getCCollection().add( c );
c.setA( a );
b.getCCollection().add(c);
c.setB(b);
b.getCCollection().add( c );
c.setB( b );
a.getDCollection().add(d);
d.getACollection().add(a);
a.getDCollection().add( d );
d.getACollection().add( a );
d.getECollection().add(e);
e.setF(f);
d.getECollection().add( e );
e.setF( f );
f.getBCollection().add(b);
b.setF(f);
f.getBCollection().add( b );
b.setF( f );
c.setG(g);
g.getCCollection().add(c);
c.setG( g );
g.getCCollection().add( c );
f.setH(h);
h.setG(g);
f.setH( h );
h.setG( g );
Session s;
s = openSession();
s.getTransaction().begin();
try {
scope.inTransaction(
session -> {
// Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h instead of a
s.persist(a);
s.flush();
} finally {
s.getTransaction().rollback();
s.close();
session.persist( a );
session.flush();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
A.class,
B.class,
C.class,
D.class,
E.class,
F.class,
G.class,
H.class
};
);
}
}

View File

@ -6,24 +6,26 @@
*/
package org.hibernate.orm.test.annotations.cascade.multicircle.jpa.identity;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
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 org.hibernate.Session;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
*
* <p>
* All IDs are generated from an identity column.
*
* <p>
* JPA cascade types are used (javax.persistence.CascadeType)..
*
* <p>
* This test uses the following model:
*
* <code>
@ -49,23 +51,33 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
* 1 |
* |
* C * 1-----
*</code>
*
* </code>
* <p>
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
*
* <p>
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
*
* <p>
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
*
* <p>
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class MultiCircleJpaCascadeIdentityTest extends BaseCoreFunctionalTestCase {
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@DomainModel(
annotatedClasses = {
EntityB.class,
EntityC.class,
EntityD.class,
EntityE.class,
EntityF.class,
EntityG.class
})
@SessionFactory
public class MultiCircleJpaCascadeIdentityTest {
private EntityB b;
private EntityC c;
private EntityD d;
@ -73,8 +85,8 @@ public class MultiCircleJpaCascadeIdentityTest extends BaseCoreFunctionalTestCas
private EntityF f;
private EntityG g;
@Before
public void setup() {
@BeforeEach
public void setup(SessionFactoryScope scope) {
b = new EntityB();
c = new EntityC();
d = new EntityD();
@ -105,8 +117,8 @@ public class MultiCircleJpaCascadeIdentityTest extends BaseCoreFunctionalTestCas
g.getFCollection().add( f );
}
@After
public void cleanup() {
@AfterEach
public void cleanup(SessionFactoryScope scope) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
@ -129,97 +141,82 @@ public class MultiCircleJpaCascadeIdentityTest extends BaseCoreFunctionalTestCas
g.setB( null );
g.getFCollection().remove( f );
Session s = openSession();
s.getTransaction().begin();
b = (EntityB) s.merge( b );
c = (EntityC) s.merge( c );
d = (EntityD) s.merge( d );
e = (EntityE) s.merge( e );
f = (EntityF) s.merge( f );
g = (EntityG) s.merge( g );
s.delete( f );
s.delete( g );
s.delete( b );
s.delete( d );
s.delete( e );
s.delete( c );
s.getTransaction().commit();
s.close();
scope.inTransaction(
session -> {
b = (EntityB) session.merge( b );
c = (EntityC) session.merge( c );
d = (EntityD) session.merge( d );
e = (EntityE) session.merge( e );
f = (EntityF) session.merge( f );
g = (EntityG) session.merge( g );
session.delete( f );
session.delete( g );
session.delete( b );
session.delete( d );
session.delete( e );
session.delete( c );
}
@Test
public void testPersist() {
Session s = openSession();
s.getTransaction().begin();
s.persist( b );
s.getTransaction().commit();
s.close();
check();
);
}
@Test
public void testMerge() {
Session s = openSession();
s.getTransaction().begin();
b = (EntityB) s.merge( b );
public void testPersist(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.persist( b )
);
check( scope );
}
@Test
public void testMerge(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
b = (EntityB) session.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
s.getTransaction().commit();
s.close();
check();
}
);
check( scope );
}
private void check() {
Session s = openSession();
s.getTransaction().begin();
EntityB bRead = (EntityB) s.get( EntityB.class, b.getId() );
Assert.assertEquals( b, bRead );
private void check(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
EntityB bRead = session.get( EntityB.class, b.getId() );
assertEquals( b, bRead );
EntityG gRead = bRead.getGCollection().iterator().next();
Assert.assertEquals( g, gRead );
assertEquals( g, gRead );
EntityC cRead = bRead.getC();
Assert.assertEquals( c, cRead );
assertEquals( c, cRead );
EntityD dRead = bRead.getD();
Assert.assertEquals( d, dRead );
assertEquals( d, dRead );
Assert.assertSame( bRead, cRead.getBCollection().iterator().next() );
Assert.assertSame( dRead, cRead.getDCollection().iterator().next() );
assertSame( bRead, cRead.getBCollection().iterator().next() );
assertSame( dRead, cRead.getDCollection().iterator().next() );
Assert.assertSame( bRead, dRead.getBCollection().iterator().next() );
Assert.assertEquals( cRead, dRead.getC() );
assertSame( bRead, dRead.getBCollection().iterator().next() );
assertEquals( cRead, dRead.getC() );
EntityE eRead = dRead.getE();
Assert.assertEquals( e, eRead );
assertEquals( e, eRead );
EntityF fRead = dRead.getFCollection().iterator().next();
Assert.assertEquals( f, fRead );
assertEquals( f, fRead );
Assert.assertSame( dRead, eRead.getDCollection().iterator().next() );
Assert.assertSame( fRead, eRead.getF() );
assertSame( dRead, eRead.getDCollection().iterator().next() );
assertSame( fRead, eRead.getF() );
Assert.assertSame( eRead, fRead.getECollection().iterator().next() );
Assert.assertSame( dRead, fRead.getD() );
Assert.assertSame( gRead, fRead.getG());
assertSame( eRead, fRead.getECollection().iterator().next() );
assertSame( dRead, fRead.getD() );
assertSame( gRead, fRead.getG() );
Assert.assertSame( bRead, gRead.getB() );
Assert.assertSame( fRead, gRead.getFCollection().iterator().next() );
s.getTransaction().commit();
s.close();
assertSame( bRead, gRead.getB() );
assertSame( fRead, gRead.getFCollection().iterator().next() );
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
EntityB.class,
EntityC.class,
EntityD.class,
EntityE.class,
EntityF.class,
EntityG.class
};
);
}
}

View File

@ -6,22 +6,24 @@
*/
package org.hibernate.orm.test.annotations.cascade.multicircle.jpa.sequence;
import org.hibernate.Session;
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 org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.Assert;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
*
* <p>
* All IDs are generated from a sequence.
*
* <p>
* JPA cascade types are used (javax.persistence.CascadeType)..
*
* <p>
* This test uses the following model:
*
* <code>
@ -47,22 +49,33 @@ import junit.framework.Assert;
* 1 |
* |
* C * 1-----
*</code>
*
* </code>
* <p>
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
*
* <p>
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
*
* <p>
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
*
* <p>
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
public class MultiCircleJpaCascadeSequenceTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = {
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
}
)
@SessionFactory
public class MultiCircleJpaCascadeSequenceTest {
private B b;
private C c;
private D d;
@ -70,8 +83,8 @@ public class MultiCircleJpaCascadeSequenceTest extends BaseCoreFunctionalTestCas
private F f;
private G g;
@Before
public void setup() {
@BeforeEach
public void setup(SessionFactoryScope scope) {
b = new B();
c = new C();
d = new D();
@ -102,8 +115,8 @@ public class MultiCircleJpaCascadeSequenceTest extends BaseCoreFunctionalTestCas
g.getFCollection().add( f );
}
@After
public void cleanup() {
@AfterEach
public void cleanup(SessionFactoryScope scope) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
@ -126,98 +139,83 @@ public class MultiCircleJpaCascadeSequenceTest extends BaseCoreFunctionalTestCas
g.setB( null );
g.getFCollection().remove( f );
Session s = openSession();
s.getTransaction().begin();
b = ( B ) s.merge( b );
c = ( C ) s.merge( c );
d = ( D ) s.merge( d );
e = ( E ) s.merge( e );
f = ( F ) s.merge( f );
g = ( G ) s.merge( g );
s.delete( f );
s.delete( g );
s.delete( b );
s.delete( d );
s.delete( e );
s.delete( c );
s.getTransaction().commit();
s.close();
scope.inTransaction(
session -> {
b = (B) session.merge( b );
c = (C) session.merge( c );
d = (D) session.merge( d );
e = (E) session.merge( e );
f = (F) session.merge( f );
g = (G) session.merge( g );
session.delete( f );
session.delete( g );
session.delete( b );
session.delete( d );
session.delete( e );
session.delete( c );
}
);
}
@Test
public void testPersist() {
Session s = openSession();
s.getTransaction().begin();
s.persist( b );
s.getTransaction().commit();
s.close();
public void testPersist(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.persist( b )
);
check();
check( scope );
}
@Test
public void testMerge() {
Session s = openSession();
s.getTransaction().begin();
b = ( B ) s.merge( b );
public void testMerge(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
b = (B) session.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
s.getTransaction().commit();
s.close();
}
);
check();
check( scope );
}
private void check() {
Session s = openSession();
s.getTransaction().begin();
B bRead = ( B ) s.get( B.class, b.getId() );
Assert.assertEquals( b, bRead );
private void check(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
B bRead = session.get( B.class, b.getId() );
assertEquals( b, bRead );
G gRead = bRead.getGCollection().iterator().next();
Assert.assertEquals( g, gRead );
assertEquals( g, gRead );
C cRead = bRead.getC();
Assert.assertEquals( c, cRead );
assertEquals( c, cRead );
D dRead = bRead.getD();
Assert.assertEquals( d, dRead );
assertEquals( d, dRead );
Assert.assertSame( bRead, cRead.getBCollection().iterator().next() );
Assert.assertSame( dRead, cRead.getDCollection().iterator().next() );
assertSame( bRead, cRead.getBCollection().iterator().next() );
assertSame( dRead, cRead.getDCollection().iterator().next() );
Assert.assertSame( bRead, dRead.getBCollection().iterator().next() );
Assert.assertEquals( cRead, dRead.getC() );
assertSame( bRead, dRead.getBCollection().iterator().next() );
assertEquals( cRead, dRead.getC() );
E eRead = dRead.getE();
Assert.assertEquals( e, eRead );
assertEquals( e, eRead );
F fRead = dRead.getFCollection().iterator().next();
Assert.assertEquals( f, fRead );
assertEquals( f, fRead );
Assert.assertSame( dRead, eRead.getDCollection().iterator().next() );
Assert.assertSame( fRead, eRead.getF() );
assertSame( dRead, eRead.getDCollection().iterator().next() );
assertSame( fRead, eRead.getF() );
Assert.assertSame( eRead, fRead.getECollection().iterator().next() );
Assert.assertSame( dRead, fRead.getD() );
Assert.assertSame( gRead, fRead.getG());
assertSame( eRead, fRead.getECollection().iterator().next() );
assertSame( dRead, fRead.getD() );
assertSame( gRead, fRead.getG() );
Assert.assertSame( bRead, gRead.getB() );
Assert.assertSame( fRead, gRead.getFCollection().iterator().next() );
s.getTransaction().commit();
s.close();
assertSame( bRead, gRead.getB() );
assertSame( fRead, gRead.getFCollection().iterator().next() );
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
};
);
}
}

View File

@ -6,24 +6,27 @@
*/
package org.hibernate.orm.test.annotations.cascade.multicircle.nonjpa.identity;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
*
* <p>
* All IDs are generated from identity columns.
*
* <p>
* Hibernate cascade types are used (org.hibernate.annotations.CascadeType)..
*
* <p>
* This test uses the following model:
*
* <code>
@ -49,23 +52,34 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
* 1 |
* |
* C * 1-----
*</code>
*
* </code>
* <p>
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
*
* <p>
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
*
* <p>
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
*
* <p>
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public class MultiCircleNonJpaCascadeIdentityTest extends BaseCoreFunctionalTestCase {
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
@DomainModel(
annotatedClasses = {
EntityB.class,
EntityC.class,
EntityD.class,
EntityE.class,
EntityF.class,
EntityG.class
}
)
@SessionFactory
public class MultiCircleNonJpaCascadeIdentityTest {
private EntityB b;
private EntityC c;
private EntityD d;
@ -73,8 +87,8 @@ public class MultiCircleNonJpaCascadeIdentityTest extends BaseCoreFunctionalTest
private EntityF f;
private EntityG g;
@Before
public void setup() {
@BeforeEach
public void setup(SessionFactoryScope scope) {
b = new EntityB();
c = new EntityC();
d = new EntityD();
@ -105,8 +119,8 @@ public class MultiCircleNonJpaCascadeIdentityTest extends BaseCoreFunctionalTest
g.getFCollection().add( f );
}
@After
public void cleanup() {
@AfterEach
public void cleanup(SessionFactoryScope scope) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
@ -129,120 +143,101 @@ public class MultiCircleNonJpaCascadeIdentityTest extends BaseCoreFunctionalTest
g.setB( null );
g.getFCollection().remove( f );
Session s = openSession();
s.getTransaction().begin();
b = (EntityB) s.merge( b );
c = (EntityC) s.merge( c );
d = (EntityD) s.merge( d );
e = (EntityE) s.merge( e );
f = (EntityF) s.merge( f );
g = (EntityG) s.merge( g );
s.delete( f );
s.delete( g );
s.delete( b );
s.delete( d );
s.delete( e );
s.delete( c );
s.getTransaction().commit();
s.close();
scope.inTransaction(
session -> {
b = (EntityB) session.merge( b );
c = (EntityC) session.merge( c );
d = (EntityD) session.merge( d );
e = (EntityE) session.merge( e );
f = (EntityF) session.merge( f );
g = (EntityG) session.merge( g );
session.delete( f );
session.delete( g );
session.delete( b );
session.delete( d );
session.delete( e );
session.delete( c );
}
);
}
@Test
public void testPersist() {
Session s = openSession();
s.getTransaction().begin();
s.persist( b );
s.getTransaction().commit();
s.close();
public void testPersist(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.persist( b )
);
check();
check( scope );
}
@Test
public void testSave() {
Session s = openSession();
s.getTransaction().begin();
s.save( b );
s.getTransaction().commit();
s.close();
public void testSave(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.save( b )
);
check();
check( scope );
}
@Test
public void testSaveOrUpdate() {
Session s = openSession();
s.getTransaction().begin();
s.saveOrUpdate( b );
s.getTransaction().commit();
s.close();
public void testSaveOrUpdate(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.saveOrUpdate( b )
);
check();
check( scope );
}
@Test
public void testMerge() {
Session s = openSession();
s.getTransaction().begin();
b = ( EntityB ) s.merge( b );
public void testMerge(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
b = (EntityB) session.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
s.getTransaction().commit();
s.close();
}
);
check();
check( scope );
}
private void check() {
Session s = openSession();
s.getTransaction().begin();
EntityB bRead = (EntityB) s.get( EntityB.class, b.getId() );
Assert.assertEquals( b, bRead );
private void check(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
EntityB bRead = session.get( EntityB.class, b.getId() );
assertEquals( b, bRead );
EntityG gRead = bRead.getGCollection().iterator().next();
Assert.assertEquals( g, gRead );
assertEquals( g, gRead );
EntityC cRead = bRead.getC();
Assert.assertEquals( c, cRead );
assertEquals( c, cRead );
EntityD dRead = bRead.getD();
Assert.assertEquals( d, dRead );
assertEquals( d, dRead );
Assert.assertSame( bRead, cRead.getBCollection().iterator().next() );
Assert.assertSame( dRead, cRead.getDCollection().iterator().next() );
assertSame( bRead, cRead.getBCollection().iterator().next() );
assertSame( dRead, cRead.getDCollection().iterator().next() );
Assert.assertSame( bRead, dRead.getBCollection().iterator().next() );
Assert.assertEquals( cRead, dRead.getC() );
assertSame( bRead, dRead.getBCollection().iterator().next() );
assertEquals( cRead, dRead.getC() );
EntityE eRead = dRead.getE();
Assert.assertEquals( e, eRead );
assertEquals( e, eRead );
EntityF fRead = dRead.getFCollection().iterator().next();
Assert.assertEquals( f, fRead );
assertEquals( f, fRead );
Assert.assertSame( dRead, eRead.getDCollection().iterator().next() );
Assert.assertSame( fRead, eRead.getF() );
assertSame( dRead, eRead.getDCollection().iterator().next() );
assertSame( fRead, eRead.getF() );
Assert.assertSame( eRead, fRead.getECollection().iterator().next() );
Assert.assertSame( dRead, fRead.getD() );
Assert.assertSame( gRead, fRead.getG());
assertSame( eRead, fRead.getECollection().iterator().next() );
assertSame( dRead, fRead.getD() );
assertSame( gRead, fRead.getG() );
Assert.assertSame( bRead, gRead.getB() );
Assert.assertSame( fRead, gRead.getFCollection().iterator().next() );
assertSame( bRead, gRead.getB() );
assertSame( fRead, gRead.getFCollection().iterator().next() );
s.getTransaction().commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
EntityB.class,
EntityC.class,
EntityD.class,
EntityE.class,
EntityF.class,
EntityG.class
};
);
}
}

View File

@ -6,22 +6,24 @@
*/
package org.hibernate.orm.test.annotations.cascade.multicircle.nonjpa.sequence;
import org.hibernate.Session;
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 org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.Assert;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* This test uses a complicated model that requires Hibernate to delay
* inserts until non-nullable transient entity dependencies are resolved.
*
* <p>
* All IDs are generated from a sequence.
*
* <p>
* Hibernate cascade types are used (org.hibernate.annotations.CascadeType)..
*
* <p>
* This test uses the following model:
*
* <code>
@ -47,22 +49,33 @@ import junit.framework.Assert;
* 1 |
* |
* C * 1-----
*</code>
*
* </code>
* <p>
* In the diagram, all associations are bidirectional;
* assocations marked with '*' cascade persist, save, merge operations to the
* associated entities (e.g., B cascades persist to D, but D does not cascade
* persist to B);
*
* <p>
* b, c, d, e, f, and g are all transient unsaved that are associated with each other.
*
* <p>
* When saving b, the entities are added to the ActionQueue in the following order:
* c, d (depends on e), f (depends on d, g), e, b, g.
*
* <p>
* Entities are inserted in the following order:
* c, e, d, b, g, f.
*/
public class MultiCircleNonJpaCascadeSequenceTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = {
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
}
)
@SessionFactory
public class MultiCircleNonJpaCascadeSequenceTest {
private B b;
private C c;
private D d;
@ -70,8 +83,8 @@ public class MultiCircleNonJpaCascadeSequenceTest extends BaseCoreFunctionalTest
private F f;
private G g;
@Before
public void setup() {
@BeforeEach
public void setup(SessionFactoryScope scope) {
b = new B();
c = new C();
d = new D();
@ -102,8 +115,8 @@ public class MultiCircleNonJpaCascadeSequenceTest extends BaseCoreFunctionalTest
g.getFCollection().add( f );
}
@After
public void cleanup() {
@AfterEach
public void cleanup(SessionFactoryScope scope) {
b.setC( null );
b.setD( null );
b.getGCollection().remove( g );
@ -126,120 +139,101 @@ public class MultiCircleNonJpaCascadeSequenceTest extends BaseCoreFunctionalTest
g.setB( null );
g.getFCollection().remove( f );
Session s = openSession();
s.getTransaction().begin();
b = ( B ) s.merge( b );
c = ( C ) s.merge( c );
d = ( D ) s.merge( d );
e = ( E ) s.merge( e );
f = ( F ) s.merge( f );
g = ( G ) s.merge( g );
s.delete( f );
s.delete( g );
s.delete( b );
s.delete( d );
s.delete( e );
s.delete( c );
s.getTransaction().commit();
s.close();
scope.inTransaction(
session -> {
b = (B) session.merge( b );
c = (C) session.merge( c );
d = (D) session.merge( d );
e = (E) session.merge( e );
f = (F) session.merge( f );
g = (G) session.merge( g );
session.delete( f );
session.delete( g );
session.delete( b );
session.delete( d );
session.delete( e );
session.delete( c );
}
);
}
@Test
public void testPersist() {
Session s = openSession();
s.getTransaction().begin();
s.persist( b );
s.getTransaction().commit();
s.close();
public void testPersist(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.persist( b )
);
check();
check( scope );
}
@Test
public void testSave() {
Session s = openSession();
s.getTransaction().begin();
s.save( b );
s.getTransaction().commit();
s.close();
public void testSave(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.save( b )
);
check();
check( scope );
}
@Test
public void testSaveOrUpdate() {
Session s = openSession();
s.getTransaction().begin();
s.saveOrUpdate( b );
s.getTransaction().commit();
s.close();
public void testSaveOrUpdate(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.saveOrUpdate( b )
);
check();
check( scope );
}
@Test
public void testMerge() {
Session s = openSession();
s.getTransaction().begin();
b = (B) s.merge( b );
public void testMerge(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
b = (B) session.merge( b );
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
s.getTransaction().commit();
s.close();
}
);
check();
check( scope );
}
private void check() {
Session s = openSession();
s.getTransaction().begin();
B bRead = (B) s.get( B.class, b.getId() );
Assert.assertEquals( b, bRead );
private void check(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
B bRead = session.get( B.class, b.getId() );
assertEquals( b, bRead );
G gRead = bRead.getGCollection().iterator().next();
Assert.assertEquals( g, gRead );
assertEquals( g, gRead );
C cRead = bRead.getC();
Assert.assertEquals( c, cRead );
assertEquals( c, cRead );
D dRead = bRead.getD();
Assert.assertEquals( d, dRead );
assertEquals( d, dRead );
Assert.assertSame( bRead, cRead.getBCollection().iterator().next() );
Assert.assertSame( dRead, cRead.getDCollection().iterator().next() );
assertSame( bRead, cRead.getBCollection().iterator().next() );
assertSame( dRead, cRead.getDCollection().iterator().next() );
Assert.assertSame( bRead, dRead.getBCollection().iterator().next() );
Assert.assertEquals( cRead, dRead.getC() );
assertSame( bRead, dRead.getBCollection().iterator().next() );
assertEquals( cRead, dRead.getC() );
E eRead = dRead.getE();
Assert.assertEquals( e, eRead );
assertEquals( e, eRead );
F fRead = dRead.getFCollection().iterator().next();
Assert.assertEquals( f, fRead );
assertEquals( f, fRead );
Assert.assertSame( dRead, eRead.getDCollection().iterator().next() );
Assert.assertSame( fRead, eRead.getF() );
assertSame( dRead, eRead.getDCollection().iterator().next() );
assertSame( fRead, eRead.getF() );
Assert.assertSame( eRead, fRead.getECollection().iterator().next() );
Assert.assertSame( dRead, fRead.getD() );
Assert.assertSame( gRead, fRead.getG());
assertSame( eRead, fRead.getECollection().iterator().next() );
assertSame( dRead, fRead.getD() );
assertSame( gRead, fRead.getG() );
Assert.assertSame( bRead, gRead.getB() );
Assert.assertSame( fRead, gRead.getFCollection().iterator().next() );
assertSame( bRead, gRead.getB() );
assertSame( fRead, gRead.getFCollection().iterator().next() );
s.getTransaction().commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
B.class,
C.class,
D.class,
E.class,
F.class,
G.class
};
);
}
}

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import java.io.Serializable;
import javax.persistence.ManyToOne;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Entity;
/**

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;

View File

@ -6,7 +6,7 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import java.io.Serializable;
import javax.persistence.ManyToOne;

View File

@ -6,22 +6,21 @@
*/
// $Id$
package org.hibernate.test.annotations.fkcircularity;
package org.hibernate.orm.test.annotations.fkcircularity;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Test case for ANN-722 and ANN-730.
*
* @author Hardy Ferentschik
*/
public class FkCircularityTest extends BaseUnitTestCase {
public class FkCircularityTest {
@Test
public void testJoinedSublcassesInPK() {

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.list;
package org.hibernate.orm.test.annotations.list;
import java.util.ArrayList;
import java.util.List;
@ -26,15 +26,17 @@ import org.hibernate.mapping.Column;
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
import org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Originally developed to help diagnose HHH-10099 which reports a problem with @OrderColumn
@ -42,17 +44,17 @@ import static org.junit.Assert.assertTrue;
*
* @author Steve Ebersole
*/
public class ListMappingTest extends BaseUnitTestCase {
public class ListMappingTest {
private StandardServiceRegistry ssr;
@Before
@BeforeEach
public void before() {
ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.FORMAT_SQL, false )
.build();
}
@After
@AfterEach
public void after() {
if ( ssr != null ) {
StandardServiceRegistryBuilder.destroy( ssr );

View File

@ -1,57 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.array;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.array.Contest.Month;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Emmanuel Bernard
*/
public class ArrayTest extends BaseCoreFunctionalTestCase {
@Test
public void testOneToMany() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Competitor c1 = new Competitor();
c1.setName( "Renault" );
Competitor c2 = new Competitor();
c2.setName( "Ferrari" );
Contest contest = new Contest();
contest.setResults( new Competitor[]{c1, c2} );
contest.setHeldIn(new Month[]{Month.January, Month.December});
s.persist( contest );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
contest = (Contest) s.get( Contest.class, contest.getId() );
assertNotNull( contest );
assertNotNull( contest.getResults() );
assertEquals( 2, contest.getResults().length );
assertEquals( c2.getName(), contest.getResults()[1].getName() );
assertEquals( 2, contest.getHeldIn().length );
assertEquals( Month.January, contest.getHeldIn()[0] );
tx.commit();
s.close();
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { Competitor.class, Contest.class };
}
}

View File

@ -1,109 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
//$Id$
package org.hibernate.test.annotations.backquotes;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.jboss.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Testcase for ANN-718 - @JoinTable / @JoinColumn fail when using backquotes in PK field name.
*
* @author Hardy Ferentschik
*
*/
public class BackquoteTest extends BaseUnitTestCase {
private ServiceRegistry serviceRegistry;
private SessionFactory sessionFactory;
@Before
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
}
@After
public void tearDown() {
if(sessionFactory !=null) sessionFactory.close();
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
}
@Test
@TestForIssue( jiraKey = "ANN-718" )
public void testBackquotes() {
try {
Configuration config = new Configuration();
config.addAnnotatedClass(Bug.class);
config.addAnnotatedClass(Category.class);
sessionFactory = config.buildSessionFactory( serviceRegistry );
}
catch( Exception e ) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
log.debug(writer.toString());
fail(e.getMessage());
}
finally {
if ( sessionFactory != null ) {
sessionFactory.close();
sessionFactory = null;
}
}
}
/**
* HHH-4647 : Problems with @JoinColumn referencedColumnName and quoted column and table names
*
* An invalid referencedColumnName to an entity having a quoted table name results in an
* infinite loop in o.h.c.Configuration$MappingsImpl#getPhysicalColumnName().
* The same issue exists with getLogicalColumnName()
*/
@Test
@TestForIssue( jiraKey = "HHH-4647" )
public void testInvalidReferenceToQuotedTableName() {
try {
Configuration config = new Configuration();
config.addAnnotatedClass(Printer.class);
config.addAnnotatedClass(PrinterCable.class);
sessionFactory = config.buildSessionFactory( serviceRegistry );
fail("expected MappingException to be thrown");
}
//we WANT MappingException to be thrown
catch( MappingException e ) {
assertTrue("MappingException was thrown", true);
}
catch(Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
log.debug(writer.toString());
fail(e.getMessage());
} finally {
if(sessionFactory!=null){
sessionFactory.close();
sessionFactory = null;
}
}
}
}

View File

@ -18,8 +18,9 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.test.annotations.basic.CollectionAsBasicTest.DelimitedStringsType;
import org.hibernate.testing.TestForIssue;
import org.hibernate.orm.test.annotations.basic.CollectionAsBasicTest;
import org.hibernate.type.ComponentType;
import org.junit.Test;
@ -61,7 +62,7 @@ public class ComponentBasicProxyTest extends BaseEntityManagerFunctionalTestCase
try {
Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( Person.class )
.getMetadataBuilder().applyBasicType( new DelimitedStringsType() )
.getMetadataBuilder().applyBasicType( new CollectionAsBasicTest.DelimitedStringsType() )
.build();
PersistentClass persistentClass = metadata.getEntityBinding( Person.class.getName() );