I am new to Hibernate and trying to connect to a legacy database that I have not control over.
I have a database table that holds all of the statuses for the system. It has a composite key of (Table Name, Code). Eg...
Code:
Table Name Code Description
---------- ----- -----------
INV_STS ACTIVE Invoice has been issued
INV_STS PENDING Invoice is pending
INV_STS CANCEL Invoice is cancelled
JOB_STS ACTIVE Job is Active
JOB_STS FINISH Job is Finished
So what I am attempting to do is have an Many-to-One relationship to the Invoice Status on the Invoice class and a Many-to-One relationship to the Job Status on the Job class. But have not been able to do it.
I have attempted to use inheritance, but the discriminator field also part of the composite key. If I map it I get ....
Quote:
org.hibernate.MappingException: Repeated column in mapping for entity: nz.co.xxxxx.bo.entity.status.Hib_JobStatus column: TBTABL (should be mapped with insert="false" update="false").
Obviously, if the discriminator column is not part of the Id then hibernate retrieves return multiple rows when it should only return 1 (eg. "ACTIVE" is a valid code for Invoice Status as well as Job Status). I have tried many combinations to try and get it to work without success.
I read about Filtering but it didn't seem appropriate, the Table name is not really dynamic and seems a real overkill.
So, please tell me what would be the best approach. I could have included my latest experiment but was not sure it would add much value, my question is really what is the best approach. However, if you answer, an example (using annotations if possible) would be very much appreciated.
Thank you :)