HHH-14071 Add test cases for issue
This commit is contained in:
parent
f8fe50ad09
commit
20273b81ee
|
@ -0,0 +1,52 @@
|
|||
package org.hibernate.test.annotations.fetchprofile;
|
||||
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.FetchProfile;
|
||||
import org.hibernate.test.annotations.fetchprofile.mappedby.Address;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
@FetchProfile(name = "customer-with-address", fetchOverrides = {
|
||||
@FetchProfile.FetchOverride(entity = Customer6.class, association = "address", mode = FetchMode.JOIN)
|
||||
})
|
||||
public class Customer6 {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
private Address address;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.hibernate.test.annotations.fetchprofile;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.test.annotations.fetchprofile.mappedby.Address;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-14071" )
|
||||
public class MappedByFetchProfileFunctionTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testFetchWithOneToOneMappedBy() {
|
||||
final Session session = openSession();
|
||||
session.enableFetchProfile( "address-with-customer" );
|
||||
final Transaction transaction = session.beginTransaction();
|
||||
|
||||
Address address = new Address();
|
||||
address.setStreet("Test Road 1");
|
||||
Customer6 customer = new Customer6();
|
||||
customer.setName("Tester");
|
||||
customer.setAddress(address);
|
||||
|
||||
session.persist(address);
|
||||
session.persist(customer);
|
||||
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
address = session.get(Address.class, address.getId());
|
||||
assertTrue(Hibernate.isInitialized(address.getCustomer()));
|
||||
session.delete(address.getCustomer());
|
||||
session.delete(address);
|
||||
|
||||
transaction.commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Customer6.class,
|
||||
Address.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package org.hibernate.test.annotations.fetchprofile;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.test.annotations.fetchprofile.mappedby.Address;
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-14071" )
|
||||
public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchProfileConfigured() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer6.class );
|
||||
config.addAnnotatedClass( Address.class );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "address-with-customer" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageConfiguredFetchProfile() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer6.class );
|
||||
config.addAnnotatedClass( Address.class );
|
||||
config.addPackage( Address.class.getPackage().getName() );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-1" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package org.hibernate.test.annotations.fetchprofile.mappedby;
|
||||
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.FetchProfile;
|
||||
import org.hibernate.test.annotations.fetchprofile.Customer6;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
@FetchProfile(name = "address-with-customer", fetchOverrides = {
|
||||
@FetchProfile.FetchOverride(entity = Address.class, association = "customer", mode = FetchMode.JOIN)
|
||||
})
|
||||
public class Address {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
private String street;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "address")
|
||||
private Customer6 customer;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public Customer6 getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer6 customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
@FetchProfile(name = "mappedBy-package-profile-1", fetchOverrides = {
|
||||
@FetchProfile.FetchOverride(entity = Address.class, association = "customer", mode = FetchMode.JOIN)
|
||||
})
|
||||
@FetchProfile(name = "mappedBy-package-profile-2", fetchOverrides = {
|
||||
@FetchProfile.FetchOverride(entity = Customer6.class, association = "address", mode = FetchMode.JOIN)
|
||||
})
|
||||
package org.hibernate.test.annotations.fetchprofile.mappedby;
|
||||
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.FetchProfile;
|
||||
import org.hibernate.test.annotations.fetchprofile.Customer6;
|
Loading…
Reference in New Issue