[hibernate-commits] Hibernate SVN: r18732 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/derivedidentities and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Feb 8 14:14:30 EST 2010


Author: epbernard
Date: 2010-02-08 14:14:29 -0500 (Mon, 08 Feb 2010)
New Revision: 18732

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/
Removed:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/
Modified:
   core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Customer.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventory.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventoryPK.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/IdClassGeneratedValueManyToOneTest.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Item.java
Log:
HHH-4889 if the @IdClass support the legacy approach ie the reference to the association in the IdClass (as opposed to its pk), treat it the old way

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -2201,8 +2201,11 @@
 											+ idClassPropertyData.getPropertyName() 
 							);
 						}
-						if ( entityPropertyData.getProperty().isAnnotationPresent( ManyToOne.class )
-								|| entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class ) ) {
+						final boolean hasXToOneAnnotation = entityPropertyData.getProperty()
+								.isAnnotationPresent( ManyToOne.class )
+								|| entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class );
+						final boolean isOfDifferentType = ! entityPropertyData.getClassOrElement().equals( idClassPropertyData.getClassOrElement() );
+						if ( hasXToOneAnnotation && isOfDifferentType ) {
 							//don't replace here as we need to use the actual original return type
 							//the annotation overriding will be dealt with by a mechanism similar to @MapsId
 						}

Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2 (from rev 18731, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex)

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Customer.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/Customer.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Customer.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.complex;
+package org.hibernate.test.annotations.derivedidentities.e1.b2;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -6,11 +6,8 @@
 import java.util.Calendar;
 import java.util.List;
 
-import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
-import javax.persistence.Embedded;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Id;

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/CustomerInventory.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventory.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.complex;
+package org.hibernate.test.annotations.derivedidentities.e1.b2;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -20,99 +20,103 @@
 import javax.persistence.Version;
 
 @NamedQueries({
-   @NamedQuery(name="CustomerInventory.selectAll",
-         query="select a from CustomerInventory a")
+		@NamedQuery(name = "CustomerInventory.selectAll",
+				query = "select a from CustomerInventory a")
 })
 @SuppressWarnings("serial")
- at Entity 
- at Table(name="O_CUSTINVENTORY")
+ at Entity
+ at Table(name = "O_CUSTINVENTORY")
 @IdClass(CustomerInventoryPK.class)
 public class CustomerInventory implements Serializable, Comparator<CustomerInventory> {
-   
-   @Id
-   @TableGenerator(name="inventory",
-         table="U_SEQUENCES",
-         pkColumnName="S_ID",
-         valueColumnName="S_NEXTNUM",
-         pkColumnValue="inventory",
-         allocationSize=1000)
-         @GeneratedValue(strategy=GenerationType.TABLE,generator="inventory")
-         @Column(name="CI_ID")
-         private Integer         id;
 
- 
-   @Id
-   @ManyToOne(cascade=CascadeType.MERGE)
-   @JoinColumn(name="CI_CUSTOMERID")
-   private Customer        customer;
+	@Id
+	@TableGenerator(name = "inventory",
+			table = "U_SEQUENCES",
+			pkColumnName = "S_ID",
+			valueColumnName = "S_NEXTNUM",
+			pkColumnValue = "inventory",
+			allocationSize = 1000)
+	@GeneratedValue(strategy = GenerationType.TABLE, generator = "inventory")
+	@Column(name = "CI_ID")
+	private Integer id;
 
-   @ManyToOne(cascade=CascadeType.MERGE)
-   @JoinColumn(name = "CI_ITEMID")
-   private Item            vehicle;
 
-   @Column(name="CI_VALUE")
-   private BigDecimal      totalCost;
+	@Id
+	@ManyToOne(cascade = CascadeType.MERGE)
+	@JoinColumn(name = "CI_CUSTOMERID")
+	private Customer customer;
 
-   @Column(name="CI_QUANTITY")
-   private int             quantity;
+	@ManyToOne(cascade = CascadeType.MERGE)
+	@JoinColumn(name = "CI_ITEMID")
+	private Item vehicle;
 
-   @Version 
-   @Column(name = "CI_VERSION")
-   private int             version;
+	@Column(name = "CI_VALUE")
+	private BigDecimal totalCost;
 
-   protected CustomerInventory() {
-   }
+	@Column(name = "CI_QUANTITY")
+	private int quantity;
 
-   CustomerInventory(Customer customer, Item vehicle, int quantity , BigDecimal totalValue) 
-   {
-      this.customer = customer;
-      this.vehicle = vehicle;
-      this.quantity = quantity;
-      this.totalCost = totalValue;
-   }
+	@Version
+	@Column(name = "CI_VERSION")
+	private int version;
 
-   public Item getVehicle() {
-      return vehicle;
-   }
+	protected CustomerInventory() {
+	}
 
-   public BigDecimal getTotalCost() {
-      return totalCost;
-   }
+	CustomerInventory(Customer customer, Item vehicle, int quantity, BigDecimal totalValue) {
+		this.customer = customer;
+		this.vehicle = vehicle;
+		this.quantity = quantity;
+		this.totalCost = totalValue;
+	}
 
-   public int getQuantity() {
-      return quantity;
-   }
+	public Item getVehicle() {
+		return vehicle;
+	}
 
-   public Integer getId() {
-      return id;
-   }
+	public BigDecimal getTotalCost() {
+		return totalCost;
+	}
 
-   public Customer getCustomer() {
-      return customer;
-   }
+	public int getQuantity() {
+		return quantity;
+	}
 
-   public int getVersion() {
-      return version;
-   }
+	public Integer getId() {
+		return id;
+	}
 
-   public int compare(CustomerInventory cdb1, CustomerInventory cdb2) {
-      return cdb1.id.compareTo(cdb2.id);
-   }
+	public Customer getCustomer() {
+		return customer;
+	}
 
-   @Override
-   public boolean equals (Object obj) {
-      if (obj == this)
-         return true;
-      if (obj == null || !(obj instanceof CustomerInventory)) 
-         return false;
-      if (this.id == ((CustomerInventory)obj).id)
-         return true;
-      if (this.id != null && ((CustomerInventory)obj).id == null)
-         return false;
-      if (this.id == null && ((CustomerInventory)obj).id != null)
-         return false;
+	public int getVersion() {
+		return version;
+	}
 
-      return this.id.equals(((CustomerInventory)obj).id);
-   }
+	public int compare(CustomerInventory cdb1, CustomerInventory cdb2) {
+		return cdb1.id.compareTo( cdb2.id );
+	}
 
+	@Override
+	public boolean equals(Object obj) {
+		if ( obj == this ) {
+			return true;
+		}
+		if ( obj == null || !( obj instanceof CustomerInventory ) ) {
+			return false;
+		}
+		if ( this.id == ( ( CustomerInventory ) obj ).id ) {
+			return true;
+		}
+		if ( this.id != null && ( ( CustomerInventory ) obj ).id == null ) {
+			return false;
+		}
+		if ( this.id == null && ( ( CustomerInventory ) obj ).id != null ) {
+			return false;
+		}
+
+		return this.id.equals( ( ( CustomerInventory ) obj ).id );
+	}
+
 }

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventoryPK.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/CustomerInventoryPK.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/CustomerInventoryPK.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -1,45 +1,45 @@
-package org.hibernate.test.annotations.derivedidentities.complex;
+package org.hibernate.test.annotations.derivedidentities.e1.b2;
 
 import java.io.Serializable;
 
 
 public class CustomerInventoryPK implements Serializable {
 
-   private Integer id;
+	private Integer id;
 
-   private Customer        customer;
+	private Customer customer;
 
-   public CustomerInventoryPK() {
-   }
+	public CustomerInventoryPK() {
+	}
 
-   public CustomerInventoryPK(Integer id, Customer customer) {
-      this.id = id;
-      this.customer = customer;  
-   }
+	public CustomerInventoryPK(Integer id, Customer customer) {
+		this.id = id;
+		this.customer = customer;
+	}
 
-   public boolean equals(Object other) {
-      if (other == this) {
-         return true;
-      }
-      if (other == null || getClass() != other.getClass()) {
-         return false;
-      }
-      CustomerInventoryPK cip = (CustomerInventoryPK) other;
-      return (getCustomer().getId() == cip.getCustomer().getId() && (id == cip.id || 
-            ( id != null && id.equals(cip.id))));
-   }
+	public boolean equals(Object other) {
+		if ( other == this ) {
+			return true;
+		}
+		if ( other == null || getClass() != other.getClass() ) {
+			return false;
+		}
+		CustomerInventoryPK cip = ( CustomerInventoryPK ) other;
+		return ( getCustomer().getId() == cip.getCustomer().getId() && ( id == cip.id ||
+				( id != null && id.equals( cip.id ) ) ) );
+	}
 
-   public int hashCode() {
-      return (id == null ? 0 : id.hashCode()) ^ getCustomer().getId();
-   }
+	public int hashCode() {
+		return ( id == null ? 0 : id.hashCode() ) ^ getCustomer().getId();
+	}
 
-   public Integer getId() {
-      return id;
-   }
+	public Integer getId() {
+		return id;
+	}
 
-   public Customer getCustomer() {
-      return customer;
-   }
+	public Customer getCustomer() {
+		return customer;
+	}
 
 
 }

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/IdClassGeneratedValueManyToOneTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/IdClassGeneratedValueManyToOneTest.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/IdClassGeneratedValueManyToOneTest.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -1,70 +1,67 @@
-package org.hibernate.test.annotations.derivedidentities.complex;
+package org.hibernate.test.annotations.derivedidentities.e1.b2;
 
 import java.math.BigDecimal;
 import java.util.List;
 
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.junit.FailureExpected;
 import org.hibernate.test.annotations.TestCase;
 
-import org.hibernate.junit.FailureExpected;
 /**
  * A test.
- * 
+ *
  * @author <a href="mailto:stale.pedersen at jboss.org">Stale W. Pedersen</a>
  * @version $Revision: 1.1 $
  */
-public class IdClassGeneratedValueManyToOneTest extends TestCase
-{
-   @FailureExpected(jiraKey="HHH-4848")
-   public void testComplexIdClass()
-   {
-      Logger.getLogger("org.hibernate").setLevel(Level.TRACE);
-      Session s = openSession();
-      Transaction tx = s.beginTransaction();
-      
-      Customer c1 = new Customer("foo", "bar", "contact1", "100", new BigDecimal(1000),new BigDecimal(1000), new BigDecimal(1000));
+public class IdClassGeneratedValueManyToOneTest extends TestCase {
 
-      s.persist(c1);
-      Item boat = new Item();
-      boat.setId("1");
-      boat.setName("cruiser");
-      boat.setPrice(new BigDecimal(500));
-      boat.setDescription("a boat");
-      boat.setCategory(42);
-      
-      s.persist(boat);
-      s.flush();
-      s.clear();
-      
-      c1.addInventory(boat, 10, new BigDecimal(5000));
-      s.merge(c1);
-      s.flush();
-      s.clear();
+	@FailureExpected(jiraKey="HHH-4890")
+	public void testComplexIdClass() {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
 
-      Customer c2 = (Customer) s.createQuery( "select c from Customer c" ).uniqueResult();
+		Customer c1 = new Customer(
+				"foo", "bar", "contact1", "100", new BigDecimal( 1000 ), new BigDecimal( 1000 ), new BigDecimal( 1000 )
+		);
 
-      List<CustomerInventory> inventory = c2.getInventories();
-      
-      assertEquals(1, inventory.size());
-      assertEquals(10, inventory.get(0).getQuantity());
-      
-      tx.rollback();
-      s.close();
-      
-      assertTrue(true);
-   }
-   
-   protected Class[] getAnnotatedClasses() 
-   {
-      return new Class[] {
-            Customer.class, 
-            CustomerInventory.class,
-            CustomerInventoryPK.class,
-            Item.class
-            
-      };
-   }
+		s.persist( c1 );
+		Item boat = new Item();
+		boat.setId( "1" );
+		boat.setName( "cruiser" );
+		boat.setPrice( new BigDecimal( 500 ) );
+		boat.setDescription( "a boat" );
+		boat.setCategory( 42 );
+
+		s.persist( boat );
+		s.flush();
+		s.clear();
+
+		c1.addInventory( boat, 10, new BigDecimal( 5000 ) );
+		s.merge( c1 );
+		s.flush();
+		s.clear();
+
+		Customer c2 = ( Customer ) s.createQuery( "select c from Customer c" ).uniqueResult();
+
+		List<CustomerInventory> inventory = c2.getInventories();
+
+		assertEquals( 1, inventory.size() );
+		assertEquals( 10, inventory.get( 0 ).getQuantity() );
+
+		tx.rollback();
+		s.close();
+
+		assertTrue( true );
+	}
+
+	protected Class[] getAnnotatedClasses() {
+		return new Class[] {
+				Customer.class,
+				CustomerInventory.class,
+				CustomerInventoryPK.class,
+				Item.class
+
+		};
+	}
 }

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Item.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/complex/Item.java	2010-02-08 18:44:26 UTC (rev 18731)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b2/Item.java	2010-02-08 19:14:29 UTC (rev 18732)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.complex;
+package org.hibernate.test.annotations.derivedidentities.e1.b2;
 
 import java.io.Serializable;
 import java.math.BigDecimal;



More information about the hibernate-commits mailing list