I'm testing the Hib-annotation water. I try to implement a class ProductCategoryRollup as following:
Composite Id:
* String productCategoryId;
* String parentProductCategoryId;
* Date fromDate;
I want to do these because a particular category can rollup to multiple parent-categories and a have a effective starting date.
ProductCategoryRollup has the following associations to other instances of the same class:
* ManyToMany parentProductCategories; a category can have multiple parents
* ManyToMany childProductCategories; a category can have many children
* ManyToMany siblingProductCategories; a category can have many siblings
The parent/child relations is implemented as shown belowed. But I'm stuck on the sibling relation. Is there a way to model the sibling relation without using query?
Code:
@Entity(access = AccessType.FIELD)
public class ProductCategoryRollup {
@Embeddable(access = AccessType.FIELD)
class ProductCategoryRollupID implements Serializable {
String productCategoryId; // id-ne
String parentProductCategoryId; // id-ne
Date fromDate; // date-time
...
}
@EmbeddedId
ProductCategoryRollupID id = new ProductCategoryRollupID();
@ManyToMany
// Let hibernate fillin the JoinTable
Set<ProductCategoryRollup> parentProductCategoryRollup;
@ManyToMany(mappedBy="parentProductCategoryRollup")
Set<ProductCategoryRollup> childProductCategoryRollup;
//How to model the Sibling relation?