I am running hibernate against mysql for the first time. I have tables that have relations but do not physically have foreign key relations.
We are using Mysql 4.1 which doesn't support foreign key relations.
I am using xdoclet tags to generate my hbm files. I have tried a number of variations and can't get ANY calls to a one-to-many relation to work.
For instance: Class = ProductReview
Table Product_review has key 'products_id'.
Table reviews has key reviews_id and contains a field for products_id.
A manual query to join the databases on products_id works fine. But when I call productReview.getReviews() ... even after fetching the object from DAO.get(PRoductID), saving, etc.
ProductReview
Code:
/**
* @struts.form extends="BaseForm"
* @hibernate.class table="product_review"
*/
public class ProductReview extends BaseObject implements java.io.Serializable {
// Fields
private Integer productsId;
....
private Set reviews;
/**
* @hibernate.set
* lazy="false"
* inverse="true"
* @hibernate.collection-key column="products_id"
* @hibernate.collection-one-to-many class="com.mysite.model.Review"
*/
public Set getReviews() {
return this.reviews;
}
public void setReviews(Set reviews) {
this.reviews = reviews;
}
// Property accessors
/**
* @hibernate.id generator-class="assigned"
* type="java.lang.Integer"
* column="products_id"
*/
public Integer getProductsId() {
return this.productsId;
}
public void setProductsId(Integer productsId) {
this.productsId = productsId;
}
Review
Code:
/**
* @struts.form extends="BaseForm"
* @hibernate.class table="reviews"
*/
public class Review extends BaseObject implements java.io.Serializable {
// Property accessors
/**
* @hibernate.id
* generator-class="assigned"
* type="int"
* column="reviews_id"
*/
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* @hibernate.many-to-one not-null="true" class="com.mysite.model.ProductReview name="ProductReview"
* @hibernate.column name="PRODUCTS_ID"
*/
public ProductReview getProductReview() {
return this.productReview;
}
public void setProductReview(ProductReview productReview) {
this.productReview = productReview;
}
This is happening in EVERY similar case on every other table.
The one exception is the one-to-one relation between Reviews and ReviewsDescription, which fetches fine.
Code:
/**
* @hibernate.one-to-one not-null="true" class="com.mysite.model.ReviewsDescription"
* cascade="all" name="reviewDescription"
* @hibernate.column name="REVIEWS_ID"
*/
public ReviewsDescription getReviewsDescription() {
return this.reviewsDescription;
}
public void setReviewsDescription(ReviewsDescription reviewsDescription) {
this.reviewsDescription = reviewsDescription;
}