-->
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: Hibernate Composite Pattern
PostPosted: Mon Oct 10, 2011 6:35 am 
Newbie

Joined: Mon Oct 10, 2011 6:26 am
Posts: 1
Hello
I am implementing a material list. Which means that I do have kind of a tree structure like in the composite pattern.
I have Material which may be a part or a parset whilst a partset may consist out of parts or other partsets (tree structure)
I do want TABLE_PER_CLASS strategy, so there should only be a table for part and partset, not material.

My code looks like this:

Code:
@Table(name = "Materialhierarchie")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
public abstract class Material {

}
@DiscriminatorValue("Part")
public class Part extends Material {

}
@DiscriminatorValue("Partset")
public class Partset extends Material {
    private List<Material> materials = new ArrayList<Material>();
}


I am wondering if this is the proper way to to this.
In my database a partset_materials table gets created, but I am not able to open it due to the error: "artset_materials`: table data is not editable because there is no primary key defined for the table"

BTW: I am working with spring roo...

Any suggestions? I really would appreciate any help!


Thanks in advance
Alex


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.