2 Replies Latest reply on Jan 16, 2008 1:45 PM by Diego Coronel

    Conversations - EntityManager.refresh and Cascade.ALL

    di pas Newbie

      In my SFSB I manage a master/detail relationship. Now I have implemented an Undo Function. This way a user can edit the master and also add/edit/remove the detail associations in the same conversation without flushing to the Database. When the user now applys the Undo Function I do em.refresh(MasterObject) but the associations are not refreshed together with the MasterObject.


      The EntityManager documentation says that with CascadeType.ALL defined on the Collection it should be refreshed with the Object. This did not work. I tried also to define an additional org.hibernate.annotations.CascadeType.REFRESH in the @Cascade Annotation. Nothing happend. The same thing happens to the OneToOne Association from ServiceComp to Remark.


      This is my definition of the Entity.


      
      @Entity
      
      @org.hibernate.annotations.Table(
      
              appliesTo = "ServiceComp",
      
              indexes = @org.hibernate.annotations.Index(
      
                      name = "IDX_ServiceComp_Name", columnNames = {"Name", "Description"})
      
      )
      
      public class ServiceComp implements Serializable {
      
      
          @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "serviceCompGenerator")
      
          @GenericGenerator(
      
              name = "serviceCompGenerator",
      
              strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
      
              parameters = {
      
                  @Parameter(name = "sequence_name", value = "CORE_ServiceComp_Seq"),
      
                  @Parameter(name = "initial_value", value = "100000")}
      
          )
      
          @Column(name = "Id")
      
          private Long id;
      
      
          @Column( name = "Name", updatable = false )
      
          @org.hibernate.validator.Length( min = 3, max = 50 )
      
          @org.hibernate.validator.NotNull
      
          private String name;
      
      
          @Column( name = "Description" )
      
          @org.hibernate.validator.Length( min = 2, max = 150 )
      
          @org.hibernate.validator.NotNull
      
          private String description;
      
      
          @OneToOne( optional = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL )
      
          @org.hibernate.annotations.Cascade({
      
                  org.hibernate.annotations.CascadeType.SAVE_UPDATE,
      
                  org.hibernate.annotations.CascadeType.DELETE_ORPHAN
      
                  })
      
          @JoinColumn( name = "Remark_Id" )
      
          @org.hibernate.annotations.ForeignKey(name = "FK_ServiceComp_Remark_Id")
      
          @org.hibernate.annotations.Index( name = "IDX_ServiceComp_Remark_Id", columnNames = {"Remark_Id"} )       
      
          private Remark remark;
      
      
          @OneToMany( mappedBy = "serviceComp", fetch = FetchType.LAZY, cascade = CascadeType.ALL )
      
          @org.hibernate.annotations.Cascade({
      
                  org.hibernate.annotations.CascadeType.SAVE_UPDATE,
      
                  org.hibernate.annotations.CascadeType.DELETE_ORPHAN
      
                  }
      
          )    
      
          @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
      
          private Set<ServiceCompAction> serviceCompActions = new HashSet<ServiceCompAction>();
      
      
          @Version
      
          @Column( name = "Version" )
      
          private Integer version;
      
      


      After the refresh operation I see the right selects for the Master and for the collection plus the remark in my console, but I think that the collections get read from the Persistence Context and not from the Database!?


      For the moment I solved the problem by looping through the Collection and refreshing each object one by one.


      I'm not sure if this issue belongs to the EntityManager Forum or has to do with Seam or if it is my fault.


      Have you any suggestion?