[hibernate-commits] Hibernate SVN: r19528 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon May 17 10:28:56 EDT 2010
Author: epbernard
Date: 2010-05-17 10:28:55 -0400 (Mon, 17 May 2010)
New Revision: 19528
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Country.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java
Log:
HHH-5233 add test on @FetchProfile and multiple @FetchOverride
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Country.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Country.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Country.java 2010-05-17 14:28:55 UTC (rev 19528)
@@ -0,0 +1,22 @@
+package org.hibernate.test.annotations.fetchprofile;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at Table(name="Order_Country")
+public class Country {
+ @Id @GeneratedValue
+ public Integer getId() { return id; }
+ public void setId(Integer id) { this.id = id; }
+ private Integer id;
+
+ public String getName() { return name; }
+ public void setName(String name) { this.name = name; }
+ private String name;
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java 2010-05-17 12:47:14 UTC (rev 19527)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java 2010-05-17 14:28:55 UTC (rev 19528)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -25,21 +25,34 @@
*/
package org.hibernate.test.annotations.fetchprofile;
+import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.FetchProfile;
+import org.hibernate.annotations.FetchProfiles;
/**
* @author Hardy Ferentschik
*/
@Entity
- at FetchProfile(name = "customer-with-orders", fetchOverrides = {
- @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
+ at FetchProfiles( {
+ @FetchProfile(name = "customer-with-orders", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
+ }),
+ @FetchProfile(name = "customer-with-orders-and-country",
+ fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN),
+ //The following does not work
+ //@FetchProfile.FetchOverride(entity = Customer.class, association = "orders.country", mode = FetchMode.JOIN),
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "lastOrder", mode = FetchMode.JOIN)
+ })
})
public class Customer {
@Id
@@ -51,8 +64,27 @@
private long customerNumber;
@OneToMany
- private Set<Order> orders;
+ private Set<Order> orders = new HashSet<Order>();
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Order lastOrder;
+
+ public Order getLastOrder() {
+ return lastOrder;
+ }
+
+ public void setLastOrder(Order lastOrder) {
+ this.lastOrder = lastOrder;
+ }
+
+ public Set<SupportTickets> getTickets() {
+ return tickets;
+ }
+
+ public void setTickets(Set<SupportTickets> tickets) {
+ this.tickets = tickets;
+ }
+
@OneToMany
private Set<SupportTickets> tickets;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java 2010-05-17 12:47:14 UTC (rev 19527)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java 2010-05-17 14:28:55 UTC (rev 19528)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -49,6 +49,7 @@
config.addAnnotatedClass( Customer.class );
config.addAnnotatedClass( Order.class );
config.addAnnotatedClass( SupportTickets.class );
+ config.addAnnotatedClass( Country.class );
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory();
assertTrue(
@@ -65,6 +66,7 @@
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass( Customer2.class );
config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( Country.class );
try {
config.buildSessionFactory();
@@ -79,6 +81,7 @@
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass( Customer3.class );
config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( Country.class );
try {
config.buildSessionFactory();
@@ -93,6 +96,7 @@
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass( Customer4.class );
config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( Country.class );
try {
config.buildSessionFactory();
@@ -107,6 +111,7 @@
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass( Customer5.class );
config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( Country.class );
InputStream is = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" );
@@ -122,6 +127,7 @@
config = new AnnotationConfiguration();
config.addAnnotatedClass( Customer5.class );
config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( Country.class );
try {
config.buildSessionFactory();
fail();
@@ -136,6 +142,7 @@
config.addAnnotatedClass( Customer.class );
config.addAnnotatedClass( Order.class );
config.addAnnotatedClass( SupportTickets.class );
+ config.addAnnotatedClass( Country.class );
config.addPackage( Customer.class.getPackage().getName() );
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory();
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java 2010-05-17 14:28:55 UTC (rev 19528)
@@ -0,0 +1,75 @@
+package org.hibernate.test.annotations.fetchprofile;
+
+import java.util.Date;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.junit.FailureExpected;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MoreFetchProfileTest extends TestCase{
+
+ @FailureExpected( jiraKey = "HHH-5233")
+ public void testFetchWithTwoOverrides() throws Exception {
+ Session s = openSession( );
+ s.enableFetchProfile( "customer-with-orders-and-country" );
+ final Transaction transaction = s.beginTransaction();
+ Country ctry = new Country();
+ ctry.setName( "France" );
+ Order o = new Order();
+ o.setCountry( ctry );
+ o.setDeliveryDate( new Date() );
+ o.setOrderNumber( 1 );
+ Order o2 = new Order();
+ o2.setCountry( ctry );
+ o2.setDeliveryDate( new Date() );
+ o2.setOrderNumber( 2 );
+ Customer c = new Customer();
+ c.setCustomerNumber( 1 );
+ c.setName( "Emmanuel" );
+ c.getOrders().add( o );
+ c.setLastOrder( o2 );
+
+ s.persist( ctry );
+ s.persist( o );
+ s.persist( o2 );
+ s.persist( c );
+
+ s.flush();
+
+ s.clear();
+
+ c = (Customer) s.get( Customer.class, c.getId() );
+ assertTrue( Hibernate.isInitialized( c.getLastOrder() ) );
+ assertTrue( Hibernate.isInitialized( c.getOrders() ) );
+ for(Order so : c.getOrders() ) {
+ //assertTrue( Hibernate.isInitialized( so.getCountry() ) );
+ }
+ final Order order = c.getOrders().iterator().next();
+ c.getOrders().remove( order );
+ s.delete( c );
+ final Order lastOrder = c.getLastOrder();
+ c.setLastOrder( null );
+ s.delete( order.getCountry() );
+ s.delete( lastOrder );
+ s.delete( order );
+
+ transaction.commit();
+ s.close();
+
+ }
+
+ @Override
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class<?>[] {
+ Order.class,
+ Country.class,
+ Customer.class,
+ SupportTickets.class
+ };
+ }
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java 2010-05-17 12:47:14 UTC (rev 19527)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java 2010-05-17 14:28:55 UTC (rev 19528)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -27,13 +27,17 @@
import java.util.Date;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
/**
* @author Hardy Ferentschik
*/
@Entity
+ at Table(name="C_ORDER")
public class Order {
@Id
@GeneratedValue
@@ -43,6 +47,17 @@
private Date deliveryDate;
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Country country;
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
public Date getDeliveryDate() {
return deliveryDate;
}
More information about the hibernate-commits
mailing list