Hibernate: mapping many-to-one association to different parent table depending on type?

Up vote 0 down vote favorite share g+ share fb share tw.

I have tables which look like this: Item table: ItemName Varchar2(200) ItemId Number OwnerId Number OwnerType number Person table: PersonName Varchar2(200) PersonId Number Company table: CompanyName Varchar2(200) CompanyId Number When the ownerType for an Item is '1', the ownerId of the item is a foreign key PersonId of the 'person' table. When the OwnerType is '2', the ownerId is a foreign key of the CompanyId of the Company table. I didn't do the data modelling & I don't have the option of changing the schema.

I'd like to solve two problems: (1) I'd like a mapping file for the Item table which would give me the items's owner. (2) I'd like mapping files for the Person & Company tables which would give me the Items owned by the Person or Company, respectively. Note: a CompanyId and a PersonId can be the same number, so an item is only owned by a Person when person.

Personid = item. Ownerid and item. Ownertype = 1.

I can control the mapping files & the object diagram, so I could create an Owner interface or super-class. Can Hibernate do this sort of thing? Java hibernate hibernate-mapping link|improve this question edited Aug 30 '11 at 9:33Sean Patrick Floyd54.8k539113 asked Aug 29 '11 at 22:49Josh1.

Case 1: you can use the concept of Table per class hierarchy. Case 2: map items as set for person/company class with where condition on the set mapping.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions