I have a table with two fields I would like to have two objects.
First one only has field1
@Entity(name = \"simpleTableObject\")
@Table(name = \"someTabl
The comment is a bit too long, so I have to write it in the answer.
Are you going to have two separate DAO to retrieve TableObject
and SimpleTableObject
separately?If yes, you don't need the extend, just treat them as two separate entities. If not, you can first get the TableObject and maybe create a constructor with SimpleTableObject(TableObject)
and copy all the fields you need there. I don't think it is possible to retrieve two entities with one findById
function. Hibernate will be confused which entity to map to with the id, which means it doesn't make much sense to have the extend. If you want to keep the consistency, how about considering SimpleTableObject as a view of TableObjec.
UPDATE : @Quillion I don't think it is possible this way. Since these two entities are basically identical(you can ignore some fields in an entity), there is no way for hibernate to identify which entity to map. Of course you can add an extra column as a discriminator, then use the @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
to map these two entities, but I assume this is not what you want.