Hibernate version: 3.1.3
I'm trying to figure out how to initialize my POJO's generic Set property (it's children, if you will).
Here's the situation...
Class Parent is as follows (my apologies for syntax errors):
Code:
package x.y.foo;
public class Parent implements java.io.Serializable {
static final long serialVersionUID = -123L;
private String propertyA;
private String propertyB;
private Set setOfChildren; //of type x.y.foo.Child
public Parent() {
}
public void setPropertyA(String str) {
this.propertyA = str;
}
public String getPropertyA() {
return this.propertyA;
}
public void setPropertyB(String str) {
this.propertyB = str;
}
public String getPropertyB() {
return this.propertyB;
}
// Of what concrete implementation must newSet be
// inorder for the Hibernate persistence to work?
public void setSetOfChildren(Set newSet) {
this.setOfChildren = newSet;
}
public Set getSetOfChildren() {
return this.setOfChildren;
}
// Convenience Method
public void addChildToSetOfChildren(Child child) {
if (setOfChildren == null) {
// I would like to initialize setOfChildren here
// BUT what concrete implementation should I use???
}
this.setOfChildren.add(child);
}
}
In the example above I would like to know what concrete implementation of Set to use to initialize the Set of children.
I know that Hibernate is using
org.hibernate.collection.PersistentSet and I can use this as well BUT that will then tightly
couple my POJO to a Hibernate implementation and I would like to avoid this if possible.
Thank you for your help.