Hi, every one.
I am a Hibernate beginner, now I need to persist the following Inheritance classes.
Entity (inteerface)
|
AbstractEntity (an abstract implementation to Entity)
/ | \
Concrete Entityies
The root node of the inheritance tree is "Entity", it is an interface, then I give its an abstract implementation --AbstractEntity,which every concrete entity inherited from.
Code:
public interface Entity
extends Serializable {
//
public String getUUID();
//
public void setUUID(String uuid);
}
public abstract class AbstractEntity
implements Entity {
//
protected AbstractEntity() {
}
//
protected AbstractEntity(String uuid) {
setUUID(uuid);
}
//
private String uuid;
//
public String getUUID() {
return uuid;
}
//
public void setUUID(String uuid) {
this.uuid = uuid;
}
}
The following is a sample concrete entity :
Code:
public class DD extends AbstractEntity {
/** identifier field */
private String uuid;
/** nullable persistent field */
private String ssjwq;
/** nullable persistent field */
private String sspcs;
/** nullable persistent field */
private String ssxzqh;
/** nullable persistent field */
private String szddz;
/** nullable persistent field */
private String szdxz;
.....
}
we know that the Entity and AbstractEntity needn't be persisted to database, every concrete entity need to be persisted to database.
Hibernate have 3 strategies for inheritance mapping:
A.one table per class hierarchy
B.one table per subclass
C.one table per concrete class
in my opinion, strategy A and stragety B are not right to this case. the only choose is strategy C. But, I don't master the usage of the any tag in hibernate.so I don't know how to write the mapping file.
Can you give me some hint or write the mapping file for me?
Thank you very much.
Aotian