4 Replies Latest reply on Mar 13, 2007 10:51 PM by hanasaki jiji

    ejb3 - setList(Set<MyObjs> list) - fails to persist.

    hanasaki jiji Newbie

      reload the instance and call getList returns empty list.

      
      @OneToMany(
       cascade= {CascadeType.ALL, CascadeType.ALL}
       fetch=FetchType.EAGER)
      @JoinTable(
       name="myjointable",
       joinColumns={ @JoinColumn(name="owner_fk") }
       inverseJoinColumn=@JoinColumn(name="owned_fk")
      public Set<OwnedItem> getOwnedItems() {
       return(ownedItems);
      }
      
      private Set<OwnedItem> ownedItems = new HashSet<OwnedItem>();
      

      ////
      Q1: the cascade type in OneToMany can either be an array, as above, or a
      single item. Both compile. Both are in the hibernate annotations docs;
      however I do not find an explanation of the types or when to use an
      array and when not to (also how many items to put in the array and their
      meaning). Could someone explain this and point to reference docs?
      Q2: the above class was instantiated and persisted fine. Now it is
      loaded with an Query and the following is done:
      myObject.getOwnedItems.add(unsavedNewOwnedItem);
      em.flush();
      - Does the unsavedNewOwnedItem need to be persisted first?
      - what happens if it is not persisted yet?
      - what happens if it is already persisted?

      I have tried this withe the new owned item instanced already saved and
      not yet saved/persisted. The join table appears to be updated; however,
      when the class is reloaded, by a call to a new session bean (used by a
      subsequent call to a servlet), the Set is empty. It is expected to
      contain the item that was added.