The case involves both inheritance and association mappings
Class Structure is as under: abstract Class ContactDetail { String type; String label; Long id; }
Class Email extends ContactDetail { // discriminator value type is set to 'E' String emailAddress; }
Class PhoneNumber extends ContactDetail { // discriminator value type is set to 'P' String phoneNumber; }
Class PostalAddress extends ContactDetail { // discriminator value type is set to 'A' String addressLine1; String addressLine2; String addressLine3; String city; String state; String country; String zip; }
I hv these mapped based on the Table per Class Hierarchy model and it works fine.
Next Step was to add these as a collection to a Person Class.
Class Person { Long id; Collection<ContactDetail> contactDetails; }
I need this collection based on a JoinTable and hv used required mappings and am able to do fetch etc.
The problem comes when I want to query for a Person based on phoneNumber / EmailAddress.
Query q1 = session.createQuery("select e from Person as e, IN (e.contactDetails) as c WHERE c.emailAddress like :p1"); Query q2 = session.createQuery("select e from Person as e, IN (e.contactDetails) as c WHERE c.phoneNumber like :p2");
etc. work - "querying on subclass attributes ..."
But is it a BUG or a FEATURE of hibernate ?? Can I rely on this feature existing in future versions of Hibernate ??
|