mohitgupta_india wrote:
Hi,
<snip>
If we are right, one solution may be to put a 'class name' field in 'basic object' class. So on getting request, first we get the class name for the id from 'basicObject' table and then try getObjectById() with retrieved class name and id. But it also involves two hits to the database. Is it the right approach?
waiting for replies, Thanks
Mohit.
This will not solve your initial problem, but:
Hibernate supports the notion of an <any> type which allows it to repersent
polymorphic references to instances of types in your domain. You need
to speciffy the pairing of key name/type for identifying an instance of
a particular type and Hibernate will know how to resolve to the right
type, etc. Behaind the scenes, Hibernate represents the reference in a
manner similar to your suggestion - by creating a discriminator field.
Note however, that this does not help in your initial use case since
providing the id to Hibernate is not sufficient when the possible number
of types is large, but it could help when you have references to instances
of your BasicObject in other objects.