Reputation: 57
there are 3 classes here:
abstract class AbstractClass{@Column("type") public int type;......}
class A extends AbstractClass{......}
class B extends AbstractClass{......}
in database, when type=1 means A and type=2 means B. So how can i fetch these objects as AbstractClass, and the concrete class is A when type=1 and B when type=2 ?
Thanks very much.
Upvotes: 0
Views: 86
Reputation: 691785
You need to use the "one table per class hierarchy" inheritance mapping, described here. The explicit mapping of the discriminator column is possible, but not mandatory.
Upvotes: 0
Reputation: 3893
It depends on your database structure. If you are using one table for the whole class hierarchy, check out Hibernates documentation on table per class hierarchy. If you are using one table to store the common fields in the AbstractClass and a table for each subclass you can have a look at the documentation on Mixing table per class hierarchy with table per subclass. In both cases it comes down to defining a descriminator (in your case the type column).
Upvotes: 1