Author: epbernard
Date: 2006-11-30 19:34:34 -0500 (Thu, 30 Nov 2006)
New Revision: 10904
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Customer.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Store.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomer.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomerPK.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
Log:
ANN-425 Property not found when defined in a @IdClass and referenced by a @OneToMany
ANN-499 @IdClass and @ManyToOne leads to repeated column exception
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/PersistentClass.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -330,6 +330,12 @@
public Property getRecursiveProperty(String propertyPath) throws MappingException {
Iterator iter = getPropertyIterator(); // getReferenceablePropertyIterator();
+ if ( getIdentifierMapper() != null ) {
+ ArrayList iterators = new ArrayList(2);
+ iterators.add(iter);
+ iterators.add( getIdentifierMapper().getPropertyIterator() );
+ iter = new JoinedIterator( iterators );
+ }
try {
return getRecursiveProperty( propertyPath, iter );
}
@@ -640,7 +646,11 @@
protected void checkColumnDuplication() {
HashSet cols = new HashSet();
- checkColumnDuplication( cols, getKey().getColumnIterator() );
+ if (getIdentifierMapper() == null ) {
+ //an identifier mapper => getKey will be included in the
getNonDuplicatedPropertyIterator()
+ //and checked later, so it needs to be excluded
+ checkColumnDuplication( cols, getKey().getColumnIterator() );
+ }
checkColumnDuplication( cols, getDiscriminatorColumnIterator() );
checkPropertyColumnDuplication( cols, getNonDuplicatedPropertyIterator() );
Iterator iter = getJoinIterator();
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -657,6 +657,8 @@
entityBinder.getPropertyAccessor(), "id", compositeClass
);
HashMap<String, IdGenerator> localGenerators = new HashMap<String,
IdGenerator>();
+ boolean ignoreIdAnnotations = entityBinder.isIgnoreIdAnnotations();
+ entityBinder.setIgnoreIdAnnotations( true );
bindId(
generatorType,
generator,
@@ -683,6 +685,7 @@
true, true,
false, mappings
);
+ entityBinder.setIgnoreIdAnnotations( ignoreIdAnnotations );
persistentClass.setIdentifierMapper( mapper );
Property property = new Property();
property.setName( "_identifierMapper" );
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Customer.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Customer.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Customer.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -0,0 +1,28 @@
+//$Id: $
+package org.hibernate.test.annotations.idmanytoone;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Table;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+
+
+
+@Entity
+@Table(name = "Bs")
+public class Customer implements Serializable {
+ @Id @GeneratedValue
+ public Integer id;
+
+ @OneToMany(mappedBy = "customer")
+ public Set<StoreCustomer> stores;
+
+ private static final long serialVersionUID = 3818501706063039923L;
+}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/IdManyToOne.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -39,8 +39,30 @@
s.close();
}
+ public void testIdClassManyToOne() {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Store store = new Store();
+ Customer customer = new Customer();
+ s.persist( store );
+ s.persist( customer );
+ StoreCustomer sc = new StoreCustomer( store, customer );
+ s.persist( sc );
+ s.flush();
+ s.clear();
+
+ store = (Store) s.get(Store.class, store.id );
+ assertEquals( 1, store.customers.size() );
+ assertEquals( customer.id, store.customers.iterator().next().customer.id );
+ tx.rollback();
+ s.close();
+ }
+
protected Class[] getMappings() {
return new Class[] {
+ Store.class,
+ Customer.class,
+ StoreCustomer.class,
CardKey.class,
CardField.class,
Card.class,
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Store.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Store.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/Store.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -0,0 +1,27 @@
+//$Id: $
+package org.hibernate.test.annotations.idmanytoone;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Table;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name = "`As`")
+public class Store implements Serializable {
+ @Id @GeneratedValue
+ public Integer id;
+
+ @OneToMany(mappedBy = "store")
+ public Set<StoreCustomer> customers;
+
+
+ private static final long serialVersionUID = 1748046699322502790L;
+}
+
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomer.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomer.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomer.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -0,0 +1,38 @@
+//$Id: $
+package org.hibernate.test.annotations.idmanytoone;
+
+import java.io.Serializable;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name = "ABs")
+@IdClass( StoreCustomerPK.class)
+public class StoreCustomer implements Serializable {
+ StoreCustomer() {}
+ @Id
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "idA")
+ public Store store;
+
+ @Id
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "idB")
+ public Customer customer;
+
+
+ public StoreCustomer(Store store, Customer customer) {
+ this.store = store;
+ this.customer = customer;
+ }
+
+
+ private static final long serialVersionUID = -8295955012787627232L;
+}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomerPK.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomerPK.java 2006-11-30
22:12:54 UTC (rev 10903)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/idmanytoone/StoreCustomerPK.java 2006-12-01
00:34:34 UTC (rev 10904)
@@ -0,0 +1,32 @@
+//$Id: $
+package org.hibernate.test.annotations.idmanytoone;
+
+import java.io.Serializable;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class StoreCustomerPK implements Serializable {
+ StoreCustomerPK() {}
+ @Id
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "idA")
+ public Store store;
+
+ @Id
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "idB")
+ public Customer customer;
+
+
+ public StoreCustomerPK(Store store, Customer customer) {
+ this.store = store;
+ this.customer = customer;
+ }
+
+
+ private static final long serialVersionUID = -1102111921432271459L;
+}