-->
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: Issue with one-to-many / many-to-one relations
PostPosted: Fri Nov 17, 2006 6:21 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
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;
    }


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.