-->
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: A question on parent-children relationship
PostPosted: Mon Oct 19, 2009 8:30 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 3:36 pm
Posts: 78
In a parent-children relationship of a pair of classes, the key in the child class is a compound one with its parent key as one of components. This design seems to be good for data retrieval. I, however, need to make a few twists on the code. The data insertion operations is the follwoings: save the A instance first, get its ID and assign it to the B instances and save the Bs. I are wondering whether or not there is a good approach in the regard so that only one save() would do the job.

Code:
public class A implements Serializable {
   private Integer id;
...
   private Set<B> bs = new HashSet<B>();
...
   // business method
   public void addB(B b){
      this.bs.add(b);
   }
}

public class B implements Serializable {

   private BStringCompoundKey pk;

   private String l;
...
   public B(String langCode, String name) {
      this.locale = langCode;
      this.name = name;
   }
...
   public void setPk(A a) {
      this.pk = new BStringCompoundKey(a, l);
   }
...
   @Transient
   public String getL() {
      return l;
   }
}

@Embeddable
public class BStringCompoundKey implements Serializable {

   private A a;

   private String l;

   public BStringCompoundKey(A a, String l) {
      this.a = a;
      this.l = l;
   }
...
}


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.