I have a PROPERTY table whose primary key is defined as (REF_1_ID, PROPERTY_ID, PROPERTY_IDX) , where PROPERTY_IDX ranges from 0 to n for the same values of (REF_1_ID, PROPERTY_ID) .
I would like to leave it to Hibernate to mange the value of PROPERTY_IDX, so that I can set it to null for new objects and have it populated on save.
What is the most straightforward way of achieving that?
You can retrieve how many Property Entity with the same (REF_1_ID, PROPERTY_ID) you have
Then you set up
You can use an HibernateInterceptor to achieve this funcionality (onSave method) Keep in mind concurrency issues when dealing with this scenario
Or encapsulate as follows