-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping problem with nested many-to-one fields
PostPosted: Fri Mar 28, 2008 4:20 pm 
Newbie

Joined: Fri Mar 28, 2008 3:39 pm
Posts: 1
Hi, I'm having problems with some of my mappings and I'm not sure what the problem could be...

I have 3 persistent classes - SiteTest, ProductTest, OfferTest. Products have a single parent Site, Offers have a single parent Product. I'm not doing anything with collections, I just have @ManyToOne annotations in the children. In the Product & Offer classes, their parent object is a part of a composite key.

Here is SiteTest.java:
Code:
@Entity
@Table(name="easyaccesssite_test")
public class SiteTest {
   @Id
   String sitename;

   public boolean equals(SiteTest that) {
      return this.sitename.equals(that.sitename);
   }
}


Here is ProductTest.java:
Code:
@Entity
@Table(name="easyaccessproduct_test")
@IdClass(ProductTest.PK.class)
public class ProductTest {
    @Id
   String productname;
   @Id @ManyToOne
   SiteTest site;

   public boolean equals(ProductTest that) {
      return this.productname.equals(that.productname) && this.site.equals(that.site);
   }

   @SuppressWarnings("serial")
   private static class PK implements Serializable {
      @Column(length=100)
      String productname;
      @ManyToOne @JoinColumn(name = "sitename", referencedColumnName = "sitename")
      SiteTest site;
      public boolean equals(Object other) {
         boolean retval = false;
         if (other instanceof PK) {
            PK that = (PK) other;
            retval = (this.productname.equals(that.productname) && this.site.sitename.equals(that.site.sitename));
         }
         return retval;
      }
      public int hashCode() {
         return (site.sitename + "_" + productname).hashCode();
      }
   }
}



Here is OfferTest.java:
Code:
@Entity
@Table(name="easyaccessoffer_test")
@IdClass(OfferTest.PK.class)
public class OfferTest {
   @Id
   String offercode;
   @Id @ManyToOne
   ProductTest product;

   public boolean equals(OfferTest that) {
      return this.offercode.equals(that.offercode) && this.product.equals(that.product);
   }

   @SuppressWarnings("serial")
   private static class PK implements Serializable {
      @Column(length=100)
      String offercode;
      @ManyToOne @JoinColumns({@JoinColumn(name="sitename", referencedColumnName="sitename"), @JoinColumn(name="productname", referencedColumnName="productname")})
      ProductTest product;
      public boolean equals(Object other) {
         boolean retval = false;
         if (other instanceof PK) {
            PK that = (PK) other;
            retval = (this.offercode.equals(that.offercode) && this.product.equals(that.product));
         }
         return retval;
      }
      public int hashCode() {
         return (product.site.sitename + "_" + product.productname + "_" + offercode).hashCode();
      }
   }
}


The AnnotationConfiguration ends up throwing this:
org.hibernate.MappingException: Unable to find column with logical name: sitename in org.hibernate.mapping.Table(easyaccessproduct_test) and its related supertables and secondary tables

There is a column named "sitename" in the table for the Product class, so I don't know what the problem could be...

I assume that nested many-to-one mappings are allowed, so is the problem with the composite key?

By the way - if I leave out the OfferTest class entirely, the rest is working fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.