mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 20:24:46 +00:00
Re-enabled additional tests
This commit is contained in:
parent
d46db44082
commit
75ff2500c7
@ -1,4 +1,4 @@
|
|||||||
package org.hibernate.test.notfound;
|
package org.hibernate.orm.test.notfound;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -20,56 +20,55 @@
|
|||||||
import org.hibernate.annotations.NotFound;
|
import org.hibernate.annotations.NotFound;
|
||||||
import org.hibernate.annotations.NotFoundAction;
|
import org.hibernate.annotations.NotFoundAction;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
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.doInHibernate;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
@TestForIssue( jiraKey = "HHH-12436")
|
@TestForIssue(jiraKey = "HHH-12436")
|
||||||
public class OptionalLazyNotFoundTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
@Override
|
OptionalLazyNotFoundTest.PersonManyToOneSelectException.class,
|
||||||
protected Class[] getAnnotatedClasses() {
|
OptionalLazyNotFoundTest.PersonManyToOneSelectIgnore.class,
|
||||||
return new Class[] {
|
OptionalLazyNotFoundTest.PersonOneToOneSelectException.class,
|
||||||
PersonManyToOneSelectException.class,
|
OptionalLazyNotFoundTest.PersonOneToOneSelectIgnore.class,
|
||||||
PersonManyToOneSelectIgnore.class,
|
OptionalLazyNotFoundTest.PersonMapsIdSelectException.class,
|
||||||
PersonOneToOneSelectException.class,
|
OptionalLazyNotFoundTest.PersonMapsIdSelectIgnore.class,
|
||||||
PersonOneToOneSelectIgnore.class,
|
OptionalLazyNotFoundTest.PersonPkjcSelectException.class,
|
||||||
PersonMapsIdSelectException.class,
|
OptionalLazyNotFoundTest.PersonPkjcSelectIgnore.class,
|
||||||
PersonMapsIdSelectIgnore.class,
|
OptionalLazyNotFoundTest.PersonMapsIdColumnSelectIgnore.class,
|
||||||
PersonPkjcSelectException.class,
|
OptionalLazyNotFoundTest.PersonMapsIdColumnSelectException.class,
|
||||||
PersonPkjcSelectIgnore.class,
|
OptionalLazyNotFoundTest.City.class
|
||||||
PersonMapsIdColumnSelectIgnore.class,
|
}
|
||||||
PersonMapsIdColumnSelectException.class,
|
)
|
||||||
City.class
|
@SessionFactory
|
||||||
};
|
@ServiceRegistry(
|
||||||
}
|
settings = {
|
||||||
|
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
|
||||||
@Override
|
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true")
|
||||||
protected void configure(Configuration configuration) {
|
}
|
||||||
super.configure( configuration );
|
)
|
||||||
|
public class OptionalLazyNotFoundTest {
|
||||||
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
|
|
||||||
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneToOneSelectException() {
|
public void testOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonOneToOneSelectException.class, 1L, false );
|
setupTest( PersonOneToOneSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonOneToOneSelectException.class, 1L );
|
Person pCheck = session.find( PersonOneToOneSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -85,10 +84,10 @@ public void testOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneToOneSelectIgnore() {
|
public void testOneToOneSelectIgnore(SessionFactoryScope scope) {
|
||||||
setupTest( PersonOneToOneSelectIgnore.class, 1L, false );
|
setupTest( PersonOneToOneSelectIgnore.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonOneToOneSelectIgnore.class, 1L );
|
Person pCheck = session.find( PersonOneToOneSelectIgnore.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertNull( pCheck.getCity() );
|
assertNull( pCheck.getCity() );
|
||||||
@ -97,10 +96,10 @@ public void testOneToOneSelectIgnore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneSelectException() {
|
public void testManyToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonManyToOneSelectException.class, 1L, false );
|
setupTest( PersonManyToOneSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonManyToOneSelectException.class, 1L );
|
Person pCheck = session.find( PersonManyToOneSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -116,10 +115,10 @@ public void testManyToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneSelectIgnore() {
|
public void testManyToOneSelectIgnore(SessionFactoryScope scope) {
|
||||||
setupTest( PersonManyToOneSelectIgnore.class, 1L, false );
|
setupTest( PersonManyToOneSelectIgnore.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonManyToOneSelectIgnore.class, 1L );
|
Person pCheck = session.find( PersonManyToOneSelectIgnore.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertNull( pCheck.getCity() );
|
assertNull( pCheck.getCity() );
|
||||||
@ -128,10 +127,10 @@ public void testManyToOneSelectIgnore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPkjcOneToOneSelectException() {
|
public void testPkjcOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonPkjcSelectException.class, 1L, false );
|
setupTest( PersonPkjcSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonPkjcSelectException.class, 1L );
|
Person pCheck = session.find( PersonPkjcSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
// eagerly loaded because @PKJC assumes ignoreNotFound
|
// eagerly loaded because @PKJC assumes ignoreNotFound
|
||||||
@ -152,10 +151,10 @@ public void testPkjcOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPkjcOneToOneSelectIgnore() {
|
public void testPkjcOneToOneSelectIgnore(SessionFactoryScope scope) {
|
||||||
setupTest( PersonPkjcSelectIgnore.class, 1L, false );
|
setupTest( PersonPkjcSelectIgnore.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonPkjcSelectIgnore.class, 1L );
|
Person pCheck = session.find( PersonPkjcSelectIgnore.class, 1L );
|
||||||
// Person is non-null and association is null.
|
// Person is non-null and association is null.
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
@ -165,10 +164,10 @@ public void testPkjcOneToOneSelectIgnore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdOneToOneSelectException() {
|
public void testMapsIdOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdSelectException.class, 1L, true );
|
setupTest( PersonMapsIdSelectException.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdSelectException.class, 1L );
|
Person pCheck = session.find( PersonMapsIdSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -184,10 +183,10 @@ public void testMapsIdOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdOneToOneSelectIgnore() {
|
public void testMapsIdOneToOneSelectIgnore(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdSelectIgnore.class, 1L, true );
|
setupTest( PersonMapsIdSelectIgnore.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdSelectIgnore.class, 1L );
|
Person pCheck = session.find( PersonMapsIdSelectIgnore.class, 1L );
|
||||||
// Person is non-null association is null.
|
// Person is non-null association is null.
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
@ -197,10 +196,10 @@ public void testMapsIdOneToOneSelectIgnore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdJoinColumnOneToOneSelectException() {
|
public void testMapsIdJoinColumnOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdColumnSelectException.class, 1L, true );
|
setupTest( PersonMapsIdColumnSelectException.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L );
|
Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -216,10 +215,10 @@ public void testMapsIdJoinColumnOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdJoinColumnOneToOneSelectIgnore() {
|
public void testMapsIdJoinColumnOneToOneSelectIgnore(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdColumnSelectIgnore.class, 1L, true );
|
setupTest( PersonMapsIdColumnSelectIgnore.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdColumnSelectIgnore.class, 1L );
|
Person pCheck = session.find( PersonMapsIdColumnSelectIgnore.class, 1L );
|
||||||
// Person should be non-null;association should be null.
|
// Person should be non-null;association should be null.
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
@ -228,24 +227,23 @@ public void testMapsIdJoinColumnOneToOneSelectIgnore() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Person> void setupTest(Class<T> clazz, long id, boolean isMapsId ) {
|
private <T extends Person> void setupTest(Class<T> clazz, long id, boolean isMapsId, SessionFactoryScope scope) {
|
||||||
persistData( clazz, id, isMapsId );
|
persistData( clazz, id, isMapsId, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person p = session.find( clazz, id );
|
Person p = session.find( clazz, id );
|
||||||
assertEquals( "New York", p.getCity().getName() );
|
assertEquals( "New York", p.getCity().getName() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session ->
|
||||||
session.createNativeQuery( "delete from City where id = " + id )
|
session.createNativeQuery( "delete from City where id = " + id )
|
||||||
.executeUpdate();
|
.executeUpdate()
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Person> void persistData(Class<T> clazz, long id, boolean isMapsId) {
|
private <T extends Person> void persistData(Class<T> clazz, long id, boolean isMapsId, SessionFactoryScope scope) {
|
||||||
final Person person;
|
final Person person;
|
||||||
try {
|
try {
|
||||||
person = clazz.newInstance();
|
person = clazz.newInstance();
|
||||||
@ -254,8 +252,8 @@ private <T extends Person> void persistData(Class<T> clazz, long id, boolean isM
|
|||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
}
|
}
|
||||||
|
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
City city = new City();
|
City city = new City();
|
||||||
city.setId( id );
|
city.setId( id );
|
||||||
city.setName( "New York" );
|
city.setName( "New York" );
|
||||||
@ -277,17 +275,20 @@ public abstract static class Person {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void setId(Long id);
|
public abstract void setId(Long id);
|
||||||
|
|
||||||
public abstract City getCity();
|
public abstract City getCity();
|
||||||
|
|
||||||
public abstract void setCity(City city);
|
public abstract void setCity(City city);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonOneToOneSelectException" )
|
@Table(name = "PersonOneToOneSelectException")
|
||||||
public static class PersonOneToOneSelectException extends Person {
|
public static class PersonOneToOneSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -315,13 +316,13 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonOneToOneSelectIgnore" )
|
@Table(name = "PersonOneToOneSelectIgnore")
|
||||||
public static class PersonOneToOneSelectIgnore extends Person {
|
public static class PersonOneToOneSelectIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
|
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
|
||||||
@NotFound( action = NotFoundAction.IGNORE )
|
@NotFound(action = NotFoundAction.IGNORE)
|
||||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
private City city;
|
private City city;
|
||||||
|
|
||||||
@ -344,7 +345,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonManyToOneSelectException" )
|
@Table(name = "PersonManyToOneSelectException")
|
||||||
public static class PersonManyToOneSelectException extends Person {
|
public static class PersonManyToOneSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -372,13 +373,13 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonManyToOneSelectIgnore" )
|
@Table(name = "PersonManyToOneSelectIgnore")
|
||||||
public static class PersonManyToOneSelectIgnore extends Person {
|
public static class PersonManyToOneSelectIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
|
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
|
||||||
@NotFound( action = NotFoundAction.IGNORE )
|
@NotFound(action = NotFoundAction.IGNORE)
|
||||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
private City city;
|
private City city;
|
||||||
|
|
||||||
@ -401,7 +402,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonPkjcSelectException" )
|
@Table(name = "PersonPkjcSelectException")
|
||||||
public static class PersonPkjcSelectException extends Person {
|
public static class PersonPkjcSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -430,7 +431,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonPkjcSelectIgnore" )
|
@Table(name = "PersonPkjcSelectIgnore")
|
||||||
public static class PersonPkjcSelectIgnore extends Person {
|
public static class PersonPkjcSelectIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -460,7 +461,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdJoinException" )
|
@Table(name = "PersonMapsIdJoinException")
|
||||||
public static class PersonMapsIdJoinException extends Person {
|
public static class PersonMapsIdJoinException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -489,7 +490,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdJoinIgnore" )
|
@Table(name = "PersonMapsIdJoinIgnore")
|
||||||
public static class PersonMapsIdJoinIgnore extends Person {
|
public static class PersonMapsIdJoinIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -519,7 +520,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdSelectException" )
|
@Table(name = "PersonMapsIdSelectException")
|
||||||
public static class PersonMapsIdSelectException extends Person {
|
public static class PersonMapsIdSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -548,7 +549,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdSelectIgnore" )
|
@Table(name = "PersonMapsIdSelectIgnore")
|
||||||
public static class PersonMapsIdSelectIgnore extends Person {
|
public static class PersonMapsIdSelectIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -578,7 +579,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnJoinException" )
|
@Table(name = "PersonMapsIdColumnJoinException")
|
||||||
public static class PersonMapsIdColumnJoinException extends Person {
|
public static class PersonMapsIdColumnJoinException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -607,7 +608,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnJoinIgnore" )
|
@Table(name = "PersonMapsIdColumnJoinIgnore")
|
||||||
public static class PersonMapsIdColumnJoinIgnore extends Person {
|
public static class PersonMapsIdColumnJoinIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -637,7 +638,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnSelectExcept" )
|
@Table(name = "PersonMapsIdColumnSelectExcept")
|
||||||
public static class PersonMapsIdColumnSelectException extends Person {
|
public static class PersonMapsIdColumnSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -666,7 +667,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnSelectIgnore" )
|
@Table(name = "PersonMapsIdColumnSelectIgnore")
|
||||||
public static class PersonMapsIdColumnSelectIgnore extends Person {
|
public static class PersonMapsIdColumnSelectIgnore extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -696,7 +697,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "City" )
|
@Table(name = "City")
|
||||||
public static class City implements Serializable {
|
public static class City implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
@ -1,4 +1,4 @@
|
|||||||
package org.hibernate.test.notfound;
|
package org.hibernate.orm.test.notfound;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -17,54 +17,49 @@
|
|||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.ObjectNotFoundException;
|
import org.hibernate.ObjectNotFoundException;
|
||||||
import org.hibernate.annotations.NotFound;
|
|
||||||
import org.hibernate.annotations.NotFoundAction;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
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.doInHibernate;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
@TestForIssue( jiraKey = "HHH-12436")
|
@TestForIssue(jiraKey = "HHH-12436")
|
||||||
public class RequiredLazyNotFoundTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
@Override
|
RequiredLazyNotFoundTest.PersonManyToOneSelectException.class,
|
||||||
protected Class[] getAnnotatedClasses() {
|
RequiredLazyNotFoundTest.PersonOneToOneSelectException.class,
|
||||||
return new Class[] {
|
RequiredLazyNotFoundTest.PersonMapsIdSelectException.class,
|
||||||
PersonManyToOneSelectException.class,
|
RequiredLazyNotFoundTest.PersonPkjcSelectException.class,
|
||||||
PersonOneToOneSelectException.class,
|
RequiredLazyNotFoundTest.PersonMapsIdColumnSelectException.class,
|
||||||
PersonMapsIdSelectException.class,
|
RequiredLazyNotFoundTest.City.class
|
||||||
PersonPkjcSelectException.class,
|
}
|
||||||
PersonMapsIdColumnSelectException.class,
|
)
|
||||||
City.class
|
@SessionFactory
|
||||||
};
|
@ServiceRegistry(
|
||||||
}
|
settings = {
|
||||||
|
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
|
||||||
@Override
|
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true")
|
||||||
protected void configure(Configuration configuration) {
|
}
|
||||||
super.configure( configuration );
|
)
|
||||||
|
public class RequiredLazyNotFoundTest {
|
||||||
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
|
|
||||||
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneToOneSelectException() {
|
public void testOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonOneToOneSelectException.class, 1L, false );
|
setupTest( PersonOneToOneSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonOneToOneSelectException.class, 1L );
|
Person pCheck = session.find( PersonOneToOneSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -80,10 +75,10 @@ public void testOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneSelectException() {
|
public void testManyToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonManyToOneSelectException.class, 1L, false );
|
setupTest( PersonManyToOneSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonManyToOneSelectException.class, 1L );
|
Person pCheck = session.find( PersonManyToOneSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -99,10 +94,10 @@ public void testManyToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPkjcOneToOneSelectException() {
|
public void testPkjcOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonPkjcSelectException.class, 1L, false );
|
setupTest( PersonPkjcSelectException.class, 1L, false, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonPkjcSelectException.class, 1L );
|
Person pCheck = session.find( PersonPkjcSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -118,10 +113,10 @@ public void testPkjcOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdOneToOneSelectException() {
|
public void testMapsIdOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdSelectException.class, 1L, true );
|
setupTest( PersonMapsIdSelectException.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdSelectException.class, 1L );
|
Person pCheck = session.find( PersonMapsIdSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -137,10 +132,10 @@ public void testMapsIdOneToOneSelectException() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIdJoinColumnOneToOneSelectException() {
|
public void testMapsIdJoinColumnOneToOneSelectException(SessionFactoryScope scope) {
|
||||||
setupTest( PersonMapsIdColumnSelectException.class, 1L, true );
|
setupTest( PersonMapsIdColumnSelectException.class, 1L, true, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L );
|
Person pCheck = session.find( PersonMapsIdColumnSelectException.class, 1L );
|
||||||
assertNotNull( pCheck );
|
assertNotNull( pCheck );
|
||||||
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
assertFalse( Hibernate.isInitialized( pCheck.getCity() ) );
|
||||||
@ -155,24 +150,23 @@ public void testMapsIdJoinColumnOneToOneSelectException() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Person> void setupTest(Class<T> clazz, long id, boolean isMapsId ) {
|
private <T extends Person> void setupTest(Class<T> clazz, long id, boolean isMapsId, SessionFactoryScope scope) {
|
||||||
persistData( clazz, id, isMapsId );
|
persistData( clazz, id, isMapsId, scope );
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
Person p = session.find( clazz, id );
|
Person p = session.find( clazz, id );
|
||||||
assertEquals( "New York", p.getCity().getName() );
|
assertEquals( "New York", p.getCity().getName() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session ->
|
||||||
session.createNativeQuery( "delete from City where id = " + id )
|
session.createNativeQuery( "delete from City where id = " + id )
|
||||||
.executeUpdate();
|
.executeUpdate()
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Person> void persistData(Class<T> clazz, long id, boolean isMapsId) {
|
private <T extends Person> void persistData(Class<T> clazz, long id, boolean isMapsId, SessionFactoryScope scope) {
|
||||||
final Person person;
|
final Person person;
|
||||||
try {
|
try {
|
||||||
person = clazz.newInstance();
|
person = clazz.newInstance();
|
||||||
@ -181,8 +175,8 @@ private <T extends Person> void persistData(Class<T> clazz, long id, boolean isM
|
|||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
}
|
}
|
||||||
|
|
||||||
doInHibernate(
|
scope.inTransaction(
|
||||||
this::sessionFactory, session -> {
|
session -> {
|
||||||
City city = new City();
|
City city = new City();
|
||||||
city.setId( id );
|
city.setId( id );
|
||||||
city.setName( "New York" );
|
city.setName( "New York" );
|
||||||
@ -204,17 +198,20 @@ public abstract static class Person {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void setId(Long id);
|
public abstract void setId(Long id);
|
||||||
|
|
||||||
public abstract City getCity();
|
public abstract City getCity();
|
||||||
|
|
||||||
public abstract void setCity(City city);
|
public abstract void setCity(City city);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonOneToOneSelectException" )
|
@Table(name = "PersonOneToOneSelectException")
|
||||||
public static class PersonOneToOneSelectException extends Person {
|
public static class PersonOneToOneSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -242,7 +239,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonManyToOneSelectException" )
|
@Table(name = "PersonManyToOneSelectException")
|
||||||
public static class PersonManyToOneSelectException extends Person {
|
public static class PersonManyToOneSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -270,7 +267,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonPkjcSelectException" )
|
@Table(name = "PersonPkjcSelectException")
|
||||||
public static class PersonPkjcSelectException extends Person {
|
public static class PersonPkjcSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -299,7 +296,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdJoinException" )
|
@Table(name = "PersonMapsIdJoinException")
|
||||||
public static class PersonMapsIdJoinException extends Person {
|
public static class PersonMapsIdJoinException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -328,7 +325,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdSelectException" )
|
@Table(name = "PersonMapsIdSelectException")
|
||||||
public static class PersonMapsIdSelectException extends Person {
|
public static class PersonMapsIdSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -357,7 +354,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnJoinException" )
|
@Table(name = "PersonMapsIdColumnJoinException")
|
||||||
public static class PersonMapsIdColumnJoinException extends Person {
|
public static class PersonMapsIdColumnJoinException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -386,7 +383,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "PersonMapsIdColumnSelectExcept" )
|
@Table(name = "PersonMapsIdColumnSelectExcept")
|
||||||
public static class PersonMapsIdColumnSelectException extends Person {
|
public static class PersonMapsIdColumnSelectException extends Person {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -415,7 +412,7 @@ public void setCity(City city) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table( name = "City" )
|
@Table(name = "City")
|
||||||
public static class City implements Serializable {
|
public static class City implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
Loading…
x
Reference in New Issue
Block a user