From c7e45cdf23c4be8ba1a729f600983444e55d8b47 Mon Sep 17 00:00:00 2001
From: Devan Goodwin <dgoodwin@redhat.com>
Date: Fri, 23 Jul 2010 08:49:01 -0300
Subject: [PATCH] Attempted fix for product attribute mapping.

---
 .../org/fedoraproject/candlepin/model/Pool.java    |    2 +-
 .../candlepin/model/PoolAttribute.java             |    8 ++++++++
 .../org/fedoraproject/candlepin/model/Product.java |    2 +-
 .../candlepin/model/ProductAttribute.java          |    8 ++++++++
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/Pool.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/Pool.java
index 25f3109..d083c67 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/Pool.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/Pool.java
@@ -125,7 +125,7 @@ public class Pool extends AbstractHibernateObject implements AccessControlEnforc
     @JoinTable(name = "pool_products", joinColumns = @JoinColumn(name = "pool_id"))
     private Set<String> providedProductIds = new HashSet<String>();
 
-    @OneToMany(cascade = CascadeType.ALL)
+    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pool")
     @Cascade({org.hibernate.annotations.CascadeType.ALL, 
         org.hibernate.annotations.CascadeType.MERGE,
         org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/PoolAttribute.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/PoolAttribute.java
index 89a928f..1bd4fdb 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/PoolAttribute.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/PoolAttribute.java
@@ -21,11 +21,15 @@ import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.ManyToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.hibernate.annotations.ForeignKey;
+
 /**
  * See Attributes interface for documentation.
  */
@@ -47,6 +51,10 @@ public class PoolAttribute extends AbstractHibernateObject implements Attribute
     protected String value;
 
     @ManyToOne
+    @ForeignKey(name = "fk_pool_id", inverseName = "fk_pool_attribute_id")
+    @JoinTable(name = "cp_pool_pool_attributes",
+        joinColumns = @JoinColumn(name = "pool_attribute_id"),
+        inverseJoinColumns = @JoinColumn(name = "pool_id"))
     private Pool pool;
     
     public PoolAttribute() {
diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/Product.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/Product.java
index 3fd2b1a..8792d32 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/Product.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/Product.java
@@ -66,7 +66,7 @@ public class Product extends AbstractHibernateObject {
     // NOTE: we need a product "type" so we can tell what class of
     //       product we are... 
 
-    @OneToMany(cascade = CascadeType.ALL)
+    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
     @Cascade({org.hibernate.annotations.CascadeType.ALL, 
         org.hibernate.annotations.CascadeType.MERGE,
         org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
diff --git a/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductAttribute.java b/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductAttribute.java
index 09b45e3..0eb6df1 100644
--- a/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductAttribute.java
+++ b/proxy/src/main/java/org/fedoraproject/candlepin/model/ProductAttribute.java
@@ -21,11 +21,15 @@ import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.ManyToOne;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.hibernate.annotations.ForeignKey;
+
 /**
  * See Attributes interface for documentation.
  */
@@ -48,6 +52,10 @@ public class ProductAttribute extends AbstractHibernateObject implements Attribu
 
     
     @ManyToOne
+    @ForeignKey(name = "fk_product_id", inverseName = "fk_product_attribute_id")
+    @JoinTable(name = "cp_product_product_attributes",
+        joinColumns = @JoinColumn(name = "product_attribute_id"),
+        inverseJoinColumns = @JoinColumn(name = "product_id"))
     private Product product;
 
     public ProductAttribute() {
-- 
1.7.1.1

