emmanuel wrote:
That's different than what you described. In you last example B extends A
You're not getting my point I guess. Originally I had:
Code:
@Entity
class A {
// class A stuff
}
@Entity
class B {
// class B stuff
}
But this mapped everything (both class A stuff and class B stuff) to the same table. I could use joined tables or table per class instead, but anyway I don't care about mapping the hierarchy, just about reusing A stuff inside B at java level. And not without reasons, suppose I map the hierarchy as:
1) single table per hierarchy: I don't want a table mixing A stuff and B stuff
2) table per class: that's fine, but I can't autogenerate ids anymore.
3) joined tables: don't want the additional join
So, not finding another way, I refactor the above to:
Code:
@MappedSuperclass
abstract class X {
// class A stuff
}
@Entity class A extends X {
}
@Entity class B extends X {
// class B stuff
}
Now I reutilize class A stuff and both A and B are mapped to different classes without any id generation restriction.
Cheers,
Carlos