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.