Hibernate inheritance implementation issue

70 Views Asked by At

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.

1

There are 1 best solutions below

0
Firo On

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