3 Replies Latest reply on Feb 10, 2009 8:55 PM by Ingo Jobling

    How to refresh an Entity instance after persisting its collection?

    Tong Wang Newbie

      I have two entity classes with a bi-directional one-to-many relation between them. Code below:


      @Entity
      @Name("business")
      public class Business extends EntityBase {
           @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "business")
           private List<Campaign> campaigns = new ArrayList<Campaign>(0);
      ......
      }
      
      @Entity
      public class Campaign extends EntityBase {
           
           @ManyToOne(fetch = FetchType.LAZY)
           @JoinColumn(name = "BUSINESS_ID")
           private Business business;
      ......
      }
      



      Then, by extending EntityHome, I have CampaignHome:


      @Name("campaignHome")
      @TideEnabled
      public class CampaignHome extends EntityHome<Campaign> {
      
           private static final long serialVersionUID = -7083267087708513892L;
           
           @In(required=true) @Out
           private Business business;
           
           public void wire() {
                getInstance().setBusiness(business);
           }
      
           @Transactional
           @Override
           public String persist() {
                wire();
                super.persist();
                
                business.getCampaigns().add(getInstance());
                
                return "persisted";
           }
      }



      What I want to achieve is that after persisting a new Campaign, refresh the Business instance so that its campaigns collection will have the newly persisted campaign. Suggestions/help will be highly appreciated.