0 Replies Latest reply on Dec 13, 2006 11:52 AM by bairaulinter

    The problem of

    bairaulinter

      I have 3 entity beans, followings are the codes:

      public class Product implements Serializable {
      ........
      @ManyToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "categoryID")
      public Category getCategory() {
      return category;
      }
      public void setCategory(Category cate) {
      this.category = cate;
      }

      @ManyToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "productOwner")
      public User getUser() {
      return user;
      }
      public void setUser(User u) {
      this.user = u;
      }
      .......
      }

      =============================================
      public class User implements Serializable{
      .........
      @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      public Collection getProducts() {
      return products;
      }
      public void setProducts(Collection pro) {
      this.products = pro;
      }
      }

      =============================================
      public class Category implements Serializable {
      ..........
      @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @OrderBy(value = "productID ASC")
      public Collection getProducts() {
      return products;
      }
      public void setProducts(Collection pro) {
      this.products = pro;
      }
      }

      \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
      Then, I want to insert a record into the database. First, the categoryID and userID have been in the database! categoryID and userID are the foreign key of table: Product!

      I don't know how to do it! Can you help me?
      Thank you!