简体   繁体   中英

Hibernate inheritance implementation issue

I want to write one hbm file.

My class hierarchy is

BaseClassOne{
private long id;
...getters and setters....
}

ClassA extends BaseClassOne{
other private members;
...getters and setters....
}

classB extends BaseClassOne{
other private members;
...getters and setters....
}

now,

I am writing another classsay ClassMain which will have object type of ClassA OR classB depending on some criteria(say column type in ClassMain)

in my model class i have written

..other private members ....

private BaseClassOne objectAtRuntime;


...getters setters.....

Now, Please tell me in hbm files how to implement this...???

or tell me other alternatives to implement the same.

this is what <any> mapping is for. See here for a blogpost describing how to map it in xml . Despite it being written for NHibernate it should be the same for hibernate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM