Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-04-22 14:24:46 +02:00
parent a7ed354af9
commit d6a6c29bd4
39 changed files with 659 additions and 642 deletions

View File

@ -4,12 +4,10 @@
* 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.onetoone.basic;
package org.hibernate.orm.test.onetoone.basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

View File

@ -5,7 +5,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>.
-->
<hibernate-mapping package="org.hibernate.test.onetoone.basic" default-access="field">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.basic" default-access="field">
<class name="Parent">
<id name="id"/>

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.onetoone.basic;
package org.hibernate.orm.test.onetoone.basic;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
@ -13,18 +13,19 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.mapping.Table;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author Steve Ebersole
*/
public class OneToOneSchemaTest extends BaseUnitTestCase {
@BaseUnitTest
public class OneToOneSchemaTest {
@Test
public void testUniqueKeyNotGeneratedViaAnnotations() throws Exception {
public void testUniqueKeyNotGeneratedViaAnnotations() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources( ssr )
@ -32,8 +33,9 @@ public class OneToOneSchemaTest extends BaseUnitTestCase {
.addAnnotatedClass( Child.class )
.buildMetadata();
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable( Identifier.toIdentifier( "CHILD" ) );
assertFalse( "UniqueKey was generated when it should not", childTable.getUniqueKeyIterator().hasNext() );
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable( Identifier.toIdentifier(
"CHILD" ) );
assertFalse( childTable.getUniqueKeyIterator().hasNext(), "UniqueKey was generated when it should not" );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );

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.onetoone.basic;
package org.hibernate.orm.test.onetoone.basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

View File

@ -10,7 +10,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.onetoone.cache">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.cache">
<class name="DetailsByFK">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">

View File

@ -4,7 +4,8 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
import java.io.Serializable;
public abstract class Details implements Serializable {

View File

@ -4,6 +4,6 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
public class DetailsByFK extends Details {}

View File

@ -4,6 +4,6 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
public class DetailsByRef extends Details {}

View File

@ -0,0 +1,131 @@
package org.hibernate.orm.test.onetoone.cache;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@DomainModel(
xmlMappings = {
"org/hibernate/orm/test/onetoone/cache/Details.hbm.xml",
"org/hibernate/orm/test/onetoone/cache/Person.hbm.xml",
}
)
@SessionFactory(
generateStatistics = true
)
@ServiceRegistry(
settings = {
@Setting(name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true"),
}
)
public class OneToOneCacheTest {
private <TPerson extends Person, TDetails extends Details> void OneToOneTest(
Class<TPerson> personClass,
Class<TDetails> detailsClass,
SessionFactoryScope scope) throws Exception {
// Initialize the database with data.
List<Object> ids = createPersonsAndDetails( personClass, detailsClass, scope );
// Clear the second level cache and the statistics.
SessionFactoryImplementor sfi = scope.getSessionFactory();
CacheImplementor cache = sfi.getCache();
StatisticsImplementor statistics = sfi.getStatistics();
cache.evictEntityData( personClass );
cache.evictEntityData( detailsClass );
cache.evictQueryRegions();
statistics.clear();
// Fill the empty caches with data.
this.getPersons( personClass, ids, scope );
// Verify that no data was retrieved from the cache.
assertEquals( 0, statistics.getSecondLevelCacheHitCount(), "Second level cache hit count" );
statistics.clear();
this.getPersons( personClass, ids, scope );
// Verify that all data was retrieved from the cache.
assertEquals( 0, statistics.getSecondLevelCacheMissCount(), "Second level cache miss count" );
}
private <TPerson extends Person, TDetails extends Details> List<Object> createPersonsAndDetails(
Class<TPerson> personClass,
Class<TDetails> detailsClass,
SessionFactoryScope scope) throws Exception {
Constructor<TPerson> ctorPerson = personClass.getConstructor();
Constructor<TDetails> ctorDetails = detailsClass.getConstructor();
List<Object> ids = new ArrayList<>();
return scope.fromTransaction(
session -> {
for ( int i = 0; i < 6; i++ ) {
Person person;
try {
person = ctorPerson.newInstance();
if ( i % 2 == 0 ) {
Details details = ctorDetails.newInstance();
details.setData( String.format( "%s%d", detailsClass.getName(), i ) );
person.setDetails( details );
}
person.setName( String.format( "%s%d", personClass.getName(), i ) );
ids.add( session.save( person ) );
}
catch (Exception e) {
throw new RuntimeException( e );
}
}
return ids;
}
);
}
private <TPerson extends Person> List<TPerson> getPersons(
Class<TPerson> personClass,
List<Object> ids, SessionFactoryScope scope) {
return scope.fromTransaction(
session -> {
List<TPerson> people = new ArrayList<>();
for ( Object id : ids ) {
people.add( session.get( personClass, id ) );
}
return people;
}
);
}
@Test
public void OneToOneCacheByForeignKey(SessionFactoryScope scope) throws Exception {
OneToOneTest( PersonByFK.class, DetailsByFK.class, scope );
}
@Test
public void OneToOneCacheByRef(SessionFactoryScope scope) throws Exception {
OneToOneTest( PersonByRef.class, DetailsByRef.class, scope );
}
}

View File

@ -9,7 +9,7 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.onetoone.cache">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.cache">
<class name="PersonByFK" batch-size="3">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">

View File

@ -4,7 +4,8 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
import java.io.Serializable;
public abstract class Person implements Serializable {

View File

@ -4,6 +4,6 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
public class PersonByFK extends Person {}

View File

@ -4,6 +4,6 @@
* 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.onetoone.cache;
package org.hibernate.orm.test.onetoone.cache;
public class PersonByRef extends Person {}

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.onetoone.jointable;
package org.hibernate.orm.test.onetoone.jointable;
import java.util.Set;
import javax.persistence.CascadeType;

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.onetoone.jointable;
package org.hibernate.orm.test.onetoone.jointable;
import javax.persistence.Column;
import javax.persistence.Entity;

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.onetoone.jointable;
package org.hibernate.orm.test.onetoone.jointable;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -4,45 +4,36 @@
* 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.onetoone.jointable;
package org.hibernate.orm.test.onetoone.jointable;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Christian Beikov
*/
public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
@DomainModel(
annotatedClasses = {
Event.class,
Message.class,
ABlockableEntity.class,
OtherEntity.class
};
}
@Override
protected void buildSessionFactory() {
try {
super.buildSessionFactory();
}
catch (Exception failureExpected) {
//HHH-9188
}
}
)
@SessionFactory
@FailureExpected(jiraKey = "HHH-9188")
public class OneToOneJoinTableTest {
@Test
@TestForIssue(jiraKey = "HHH-9188")
@FailureExpected( jiraKey = "HHH-9188" )
public void test() throws Exception {
Long id = doInHibernate( this::sessionFactory, s -> {
public void test(SessionFactoryScope scope) throws Exception {
Long id = scope.fromTransaction( s -> {
Event childEvent = new Event();
childEvent.setDescription( "childEvent" );
s.save( childEvent );
@ -84,7 +75,7 @@ public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase {
return childEvent.getId();
} );
doInHibernate( this::sessionFactory, s -> {
scope.inTransaction( s -> {
Event saved = s.find( Event.class, id );
assertNotNull( saved );
} );

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.onetoone.jointable;
package org.hibernate.orm.test.onetoone.jointable;
import javax.persistence.Entity;
import javax.persistence.Id;

View File

@ -0,0 +1,168 @@
/*
* 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.onetoone.lazy;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.Hibernate.isInitialized;
import static org.junit.jupiter.api.Assertions.assertFalse;
@TestForIssue(jiraKey = "HHH-12842")
@DomainModel(
annotatedClasses = {
LazyToOneTest.Post.class,
LazyToOneTest.PostDetails.class
}
)
@SessionFactory
public class LazyToOneTest {
@BeforeEach
public void setUp(SessionFactoryScope scope) {
scope.inTransaction( s -> {
Post post = new Post();
post.setDetails( new PostDetails() );
post.getDetails().setCreatedBy( "ME" );
post.getDetails().setCreatedOn( new Date() );
post.setTitle( "title" );
s.persist( post );
} );
}
@Test
public void testOneToOneLazyLoading(SessionFactoryScope scope) {
scope.inTransaction( s -> {
PostDetails post = (PostDetails) s.createQuery( "select a from PostDetails a" ).getResultList().get( 0 );
assertFalse( isInitialized( post.post ) );
} );
}
@Entity(name = "PostDetails")
@Table(name = "post_details")
public static class PostDetails {
@Id
private Long id;
@Column(name = "created_on")
private Date createdOn;
@Column(name = "created_by")
private String createdBy;
@MapsId
@OneToOne(fetch = FetchType.LAZY, mappedBy = "details", optional = false)
private Post post;
public PostDetails() {
}
public PostDetails(String createdBy) {
createdOn = new Date();
this.createdBy = createdBy;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Post getPost() {
return post;
}
public void setPost(Post post) {
this.post = post;
}
}
@Entity(name = "Post")
@Table(name = "post")
public static class Post {
@Id
@GeneratedValue
private Long id;
private String title;
@PrimaryKeyJoinColumn
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private PostDetails details;
public void setDetails(PostDetails details) {
if ( details == null ) {
if ( this.details != null ) {
this.details.setPost( null );
}
}
else {
details.setPost( this );
}
this.details = details;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public PostDetails getDetails() {
return details;
}
}
}

View File

@ -6,7 +6,7 @@
*/
//$Id: Customer.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.onetoone.link;
package org.hibernate.orm.test.onetoone.link;
/**

View File

@ -6,7 +6,7 @@
*/
//$Id: Employee.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.onetoone.link;
package org.hibernate.orm.test.onetoone.link;
/**

View File

@ -0,0 +1,102 @@
/*
* 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.onetoone.link;
import java.util.Date;
import org.hibernate.Hibernate;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.type.DateType;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
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.Assert.assertTrue;
/**
* @author Gavin King
*/
@DomainModel(
xmlMappings = {
"org/hibernate/orm/test/onetoone/link/Person.hbm.xml"
}
)
@SessionFactory
public class OneToOneLinkTest {
@Test
@SkipForDialect(dialectClass = OracleDialect.class, reason = "oracle12c returns time in getDate. For now, skip.")
@SkipForDialect(dialectClass = AbstractHANADialect.class, reason = " HANA doesn't support tables consisting of only a single auto-generated column")
public void testOneToOneViaAssociationTable(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Person p = new Person();
p.setName( "Gavin King" );
p.setDob( new Date() );
Employee e = new Employee();
p.setEmployee( e );
e.setPerson( p );
session.persist( p );
}
);
scope.inTransaction(
session -> {
Employee e = (Employee) session.createQuery( "from Employee e where e.person.name like 'Gavin%'" )
.uniqueResult();
assertEquals( e.getPerson().getName(), "Gavin King" );
assertFalse( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
session.clear();
e = (Employee) session.createQuery( "from Employee e where e.person.dob = :date" )
.setParameter( "date", new Date(), DateType.INSTANCE )
.uniqueResult();
assertEquals( e.getPerson().getName(), "Gavin King" );
assertFalse( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
session.clear();
}
);
scope.inTransaction(
session -> {
Employee e = (Employee) session.createQuery(
"from Employee e join fetch e.person p left join fetch p.customer" )
.uniqueResult();
assertTrue( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
Customer c = new Customer();
e.getPerson().setCustomer( c );
c.setPerson( e.getPerson() );
}
);
scope.inTransaction(
session -> {
Employee e = (Employee) session.createQuery(
"from Employee e join fetch e.person p left join fetch p.customer" )
.uniqueResult();
assertTrue( Hibernate.isInitialized( e.getPerson() ) );
assertTrue( Hibernate.isInitialized( e.getPerson().getCustomer() ) );
assertNotNull( e.getPerson().getCustomer() );
session.delete( e );
}
);
}
}

View File

@ -18,7 +18,7 @@
-->
<hibernate-mapping package="org.hibernate.test.onetoone.link">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.link">
<class name="Person">
<id name="name"/>

View File

@ -6,7 +6,7 @@
*/
//$Id: Person.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.onetoone.link;
package org.hibernate.orm.test.onetoone.link;
import java.util.Date;
/**

View File

@ -0,0 +1,87 @@
/*
* 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: DynamicMapOneToOneTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.orm.test.onetoone.nopojo;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.cfg.Environment;
import org.hibernate.stat.EntityStatistics;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Gavin King
*/
@DomainModel(
xmlMappings = "org/hibernate/orm/test/onetoone/nopojo/Person.hbm.xml"
)
@SessionFactory(
generateStatistics = true
)
@ServiceRegistry(
settings = {
@Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "false"),
@Setting(name = Environment.DEFAULT_ENTITY_MODE, value = "dynamic-map"),
}
)
public class DynamicMapOneToOneTest {
@Test
public void testOneToOneOnSubclass(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Map person = new HashMap();
person.put( "name", "Steve" );
Map address = new HashMap();
address.put( "zip", "12345" );
address.put( "state", "TX" );
address.put( "street", "123 Main St" );
person.put( "address", address );
address.put( "owner", person );
session.persist( "Person", person );
}
);
EntityStatistics addressStats = scope.fromTransaction(
session -> {
EntityStatistics aStats = scope.getSessionFactory().getStatistics()
.getEntityStatistics( "Address" );
Map person = (Map) session.createQuery( "from Person p join fetch p.address" ).uniqueResult();
assertNotNull( person, "could not locate person" );
assertNotNull( person.get( "address" ), "could not locate persons address" );
session.clear();
Object[] tuple = (Object[]) session.createQuery(
"select p.name, p from Person p join fetch p.address" ).uniqueResult();
assertEquals( tuple.length, 2 );
person = (Map) tuple[1];
assertNotNull( person, "could not locate person" );
assertNotNull( person.get( "address" ), "could not locate persons address" );
session.delete( "Person", person );
return aStats;
}
);
assertEquals( addressStats.getFetchCount(), 0 );
}
}

View File

@ -9,7 +9,7 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.onetoone.nopojo">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.nopojo">
<class entity-name="Person">
<id name="id" type="long">

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.onetoone.optional;
package org.hibernate.orm.test.onetoone.optional;
/**

View File

@ -4,57 +4,53 @@
* 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.onetoone.optional;
package org.hibernate.orm.test.onetoone.optional;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpected;
import org.junit.Test;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import static javax.persistence.CascadeType.ALL;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Vlad Mihalcea
*/
public class BidirectionalOptionalOneToOneTest
extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Parent.class,
Child.class
};
}
@Jpa(
annotatedClasses = {
BidirectionalOptionalOneToOneTest.Parent.class,
BidirectionalOptionalOneToOneTest.Child.class
}
)
public class BidirectionalOptionalOneToOneTest {
@Test
public void test() {
public void test(EntityManagerFactoryScope scope) {
doInJPA( this::entityManagerFactory, entityManager -> {
scope.inTransaction( entityManager -> {
Parent a = new Parent();
a.id = 1L;
Child b = new Child();
b.id = 1L;
a.setChild(b);
b.setParent(a);
a.setChild( b );
b.setParent( a );
entityManager.persist(a);
entityManager.persist( a );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
Parent a = entityManager.find(Parent.class, 1L);
scope.inTransaction( entityManager -> {
Parent a = entityManager.find( Parent.class, 1L );
entityManager.remove(a);
entityManager.remove( a );
} );
}
@javax.persistence.Entity( name = "Parent" )
@Entity(name = "Parent")
public static class Parent {
@Id
@ -78,7 +74,7 @@ public class BidirectionalOptionalOneToOneTest
}
@javax.persistence.Entity( name = "Child" )
@Entity(name = "Child")
public static class Child {
@Id

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.onetoone.optional;
package org.hibernate.orm.test.onetoone.optional;
/**

View File

@ -0,0 +1,53 @@
/*
* 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.onetoone.optional;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Gavin King
*/
@DomainModel(
xmlMappings = { "org/hibernate/orm/test/onetoone/optional/Person.hbm.xml" }
)
@SessionFactory(
generateStatistics = true
)
@ServiceRegistry(
settings = @Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "false")
)
public class OptionalOneToOneTest {
@Test
public void testOptionalOneToOneRetrieval(SessionFactoryScope scope) {
String name = scope.fromTransaction(
session -> {
Person me = new Person();
me.name = "Steve";
session.save( me );
return me.name;
}
);
scope.inTransaction(
session -> {
Person me = session.load( Person.class, name );
assertNull( me.address );
session.delete( me );
}
);
}
}

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.onetoone.optional;
package org.hibernate.orm.test.onetoone.optional;

View File

@ -21,7 +21,7 @@
This is so we can properly determine whether to use null or some value
for the association property's value.
-->
<hibernate-mapping package="org.hibernate.test.onetoone.optional" default-access="field">
<hibernate-mapping package="org.hibernate.orm.test.onetoone.optional" default-access="field">
<class name="Entity">
<id name="name"/>

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.onetoone.optional;
package org.hibernate.orm.test.onetoone.optional;
/**

View File

@ -23,14 +23,22 @@
*/
package org.hibernate.test.onetoone.bidirectional;
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Test;
import javax.persistence.*;
import java.util.concurrent.atomic.AtomicInteger;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import org.hibernate.engine.internal.StatisticalLoggingSessionEventListener;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
@ -39,37 +47,36 @@ import static org.junit.Assert.assertEquals;
*
* @author Christian Beikov
*/
public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = {
BiDirectionalOneToOneFetchTest.EntityA.class,
BiDirectionalOneToOneFetchTest.EntityB.class
}
)
@SessionFactory
public class BiDirectionalOneToOneFetchTest {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
EntityA.class,
EntityB.class
};
}
@After
public void delete() {
inTransaction( s -> {
@AfterEach
public void delete(SessionFactoryScope scope) {
scope.inTransaction( s -> {
s.createQuery( "delete from EntityA" ).executeUpdate();
s.createQuery( "delete from EntityB" ).executeUpdate();
} );
}
@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testEagerFetchBidirectionalOneToOneWithDirectFetching() {
inTransaction( session -> {
@TestForIssue(jiraKey = "HHH-3930")
public void testEagerFetchBidirectionalOneToOneWithDirectFetching(SessionFactoryScope scope) {
scope.inTransaction( session -> {
EntityA a = new EntityA( 1L, new EntityB( 2L ) );
session.persist( a );
session.flush();
session.clear();
// Use atomic integer because we need something mutable
final AtomicInteger queryExecutionCount = new AtomicInteger();
session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
@Override
public void jdbcExecuteStatementStart() {
@ -77,9 +84,9 @@ public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
queryExecutionCount.getAndIncrement();
}
} );
session.find( EntityA.class, 1L );
assertEquals(
"Join fetching inverse one-to-one didn't use the object already present in the result set!",
1,
@ -89,9 +96,9 @@ public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testFetchBidirectionalOneToOneWithOneJoinFetch() {
inTransaction( session -> {
@TestForIssue(jiraKey = "HHH-3930")
public void testFetchBidirectionalOneToOneWithOneJoinFetch(SessionFactoryScope scope) {
scope.inTransaction( session -> {
EntityA a = new EntityA( 1L, new EntityB( 2L ) );
session.persist( a );
@ -122,9 +129,9 @@ public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testFetchBidirectionalOneToOneWithCircularJoinFetch() {
inTransaction( session -> {
@TestForIssue(jiraKey = "HHH-3930")
public void testFetchBidirectionalOneToOneWithCircularJoinFetch(SessionFactoryScope scope) {
scope.inTransaction( session -> {
EntityA a = new EntityA( 1L, new EntityB( 2L ) );
session.persist( a );
@ -155,10 +162,10 @@ public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
@Entity(name = "EntityA")
public static class EntityA {
@Id
private Long id;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "b_id")
private EntityB b;
@ -175,10 +182,10 @@ public class BiDirectionalOneToOneFetchTest extends BaseCoreFunctionalTestCase {
@Entity(name = "EntityB")
public static class EntityB {
@Id
private Long id;
@OneToOne(mappedBy = "b", fetch = FetchType.EAGER)
private EntityA a;

View File

@ -1,120 +0,0 @@
package org.hibernate.test.onetoone.cache;
import static org.junit.Assert.assertEquals;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
public class OneToOneCacheTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] {
"onetoone/cache/Details.hbm.xml",
"onetoone/cache/Person.hbm.xml",
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true");
configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
}
private <TPerson extends Person, TDetails extends Details> void OneToOneTest(Class<TPerson> personClass,
Class<TDetails> detailsClass) throws Exception {
// Initialize the database with data.
List<Object> ids = createPersonsAndDetails(personClass, detailsClass);
// Clear the second level cache and the statistics.
SessionFactoryImplementor sfi = sessionFactory();
CacheImplementor cache = sfi.getCache();
StatisticsImplementor statistics = sfi.getStatistics();
cache.evictEntityData(personClass);
cache.evictEntityData(detailsClass);
cache.evictQueryRegions();
statistics.clear();
// Fill the empty caches with data.
this.getPersons(personClass, ids);
// Verify that no data was retrieved from the cache.
assertEquals("Second level cache hit count", 0, statistics.getSecondLevelCacheHitCount());
statistics.clear();
this.getPersons(personClass, ids);
// Verify that all data was retrieved from the cache.
assertEquals("Second level cache miss count", 0, statistics.getSecondLevelCacheMissCount());
}
private <TPerson extends Person, TDetails extends Details> List<Object> createPersonsAndDetails(Class<TPerson> personClass,
Class<TDetails> detailsClass) throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Constructor<TPerson> ctorPerson = personClass.getConstructor();
Constructor<TDetails> ctorDetails = detailsClass.getConstructor();
List<Object> ids = new ArrayList<>();
for (int i = 0; i < 6; i++) {
Person person = ctorPerson.newInstance();
if (i % 2 == 0) {
Details details = ctorDetails.newInstance();
details.setData(String.format("%s%d", detailsClass.getName(), i));
person.setDetails(details);
}
person.setName(String.format("%s%d", personClass.getName(), i));
ids.add(s.save(person));
}
tx.commit();
s.close();
return ids;
}
private <TPerson extends Person> List<TPerson> getPersons(Class<TPerson> personClass, List<Object> ids) {
Session s = openSession();
Transaction tx = s.beginTransaction();
List<TPerson> people = new ArrayList<>();
for (Object id : ids) {
people.add(s.get(personClass, id));
}
tx.commit();
s.close();
return people;
}
@Test
public void OneToOneCacheByForeignKey() throws Exception {
OneToOneTest(PersonByFK.class, DetailsByFK.class);
}
@Test
public void OneToOneCacheByRef() throws Exception {
OneToOneTest(PersonByRef.class, DetailsByRef.class);
}
}

View File

@ -1,164 +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.onetoone.lazy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import java.util.Date;
import static org.hibernate.Hibernate.isInitialized;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertFalse;
@TestForIssue(jiraKey = "HHH-12842")
public class LazyToOneTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Post.class, PostDetails.class};
}
@Before
public void setUp() throws Exception {
doInHibernate( this::sessionFactory, s -> {
Post post = new Post();
post.setDetails(new PostDetails());
post.getDetails().setCreatedBy("ME");
post.getDetails().setCreatedOn(new Date());
post.setTitle("title");
s.persist(post);
} );
}
@Test
public void testOneToOneLazyLoading() {
doInHibernate( this::sessionFactory, s -> {
PostDetails post = (PostDetails) s.createQuery("select a from PostDetails a").getResultList().get(0);
assertFalse(isInitialized(post.post));
} );
}
@Entity(name = "PostDetails")
@Table(name = "post_details")
public static class PostDetails {
@Id
private Long id;
@Column(name = "created_on")
private Date createdOn;
@Column(name = "created_by")
private String createdBy;
@MapsId
@OneToOne(fetch = FetchType.LAZY, mappedBy = "details", optional = false)
private Post post;
public PostDetails() {}
public PostDetails(String createdBy) {
createdOn = new Date();
this.createdBy = createdBy;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Post getPost() {
return post;
}
public void setPost(Post post) {
this.post = post;
}
}
@Entity(name = "Post")
@Table(name = "post")
public static class Post {
@Id
@GeneratedValue
private Long id;
private String title;
@PrimaryKeyJoinColumn
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private PostDetails details;
public void setDetails(PostDetails details) {
if (details == null) {
if (this.details != null) {
this.details.setPost(null);
}
}
else {
details.setPost(this);
}
this.details = details;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public PostDetails getDetails() {
return details;
}
}
}

View File

@ -1,100 +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.onetoone.link;
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.Assert.assertTrue;
import java.util.Date;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.type.DateType;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Gavin King
*/
public class OneToOneLinkTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "onetoone/link/Person.hbm.xml" };
}
@Test
@SkipForDialect(value = Oracle10gDialect.class, comment = "oracle12c returns time in getDate. For now, skip.")
@SkipForDialect(value = AbstractHANADialect.class, comment = " HANA doesn't support tables consisting of only a single auto-generated column")
public void testOneToOneViaAssociationTable() {
Person p = new Person();
p.setName("Gavin King");
p.setDob( new Date() );
Employee e = new Employee();
p.setEmployee(e);
e.setPerson(p);
Session s = openSession();
Transaction t = s.beginTransaction();
s.persist(p);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
e = (Employee) s.createQuery("from Employee e where e.person.name like 'Gavin%'").uniqueResult();
assertEquals( e.getPerson().getName(), "Gavin King" );
assertFalse( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
s.clear();
e = (Employee) s.createQuery( "from Employee e where e.person.dob = :date" )
.setParameter( "date", new Date(), DateType.INSTANCE )
.uniqueResult();
assertEquals( e.getPerson().getName(), "Gavin King" );
assertFalse( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
s.clear();
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
e = (Employee) s.createQuery("from Employee e join fetch e.person p left join fetch p.customer").uniqueResult();
assertTrue( Hibernate.isInitialized( e.getPerson() ) );
assertNull( e.getPerson().getCustomer() );
Customer c = new Customer();
e.getPerson().setCustomer(c);
c.setPerson( e.getPerson() );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
e = (Employee) s.createQuery("from Employee e join fetch e.person p left join fetch p.customer").uniqueResult();
assertTrue( Hibernate.isInitialized( e.getPerson() ) );
assertTrue( Hibernate.isInitialized( e.getPerson().getCustomer() ) );
assertNotNull( e.getPerson().getCustomer() );
s.delete(e);
t.commit();
s.close();
}
}

View File

@ -1,85 +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: DynamicMapOneToOneTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.onetoone.nopojo;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.EntityMode;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.stat.EntityStatistics;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Gavin King
*/
public class DynamicMapOneToOneTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "onetoone/nopojo/Person.hbm.xml" };
}
@Override
public void configure(Configuration cfg) {
cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
cfg.setProperty( Environment.DEFAULT_ENTITY_MODE, EntityMode.MAP.toString() );
}
@Test
public void testOneToOneOnSubclass() {
Map person = new HashMap();
person.put( "name", "Steve" );
Map address = new HashMap();
address.put( "zip", "12345" );
address.put( "state", "TX" );
address.put( "street", "123 Main St" );
person.put( "address", address );
address.put( "owner", person );
Session s = openSession();
s.beginTransaction();
s.persist( "Person", person );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics( "Address" );
person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult();
assertNotNull( "could not locate person", person );
assertNotNull( "could not locate persons address", person.get( "address" ) );
s.clear();
Object[] tuple = ( Object[] ) s.createQuery( "select p.name, p from Person p join fetch p.address" ).uniqueResult();
assertEquals( tuple.length, 2 );
person = ( Map ) tuple[1];
assertNotNull( "could not locate person", person );
assertNotNull( "could not locate persons address", person.get( "address" ) );
s.delete( "Person", person );
s.getTransaction().commit();
s.close();
assertEquals( addressStats.getFetchCount(), 0 );
}
}

View File

@ -1,51 +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.onetoone.optional;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertNull;
/**
* @author Gavin King
*/
public class OptionalOneToOneTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "onetoone/optional/Person.hbm.xml" };
}
@Override
public void configure(Configuration cfg) {
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false");
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
@Test
public void testOptionalOneToOneRetrieval() {
Session s = openSession();
s.beginTransaction();
Person me = new Person();
me.name = "Steve";
s.save( me );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
me = ( Person ) s.load( Person.class, me.name );
assertNull( me.address );
s.delete( me );
s.getTransaction().commit();
s.close();
}
}