I have an entity With primary key such as "id" below. As this entity evolves I have another column that will group this entity around the first "id" of the group.
In short the second column "idstore" should be inserted with the "id" value if "idstore" is null, else with "idstore" value. How can I achive this with Hibernate? Im using Hibernate 4.0.1
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id;
@Column(nullable=flase)
Integer idstore;
The idea is to have a simular situation in db (assuming two groups with id 1 and 3)
+----+---------+
| id | idstore |
+----+---------+
| 1 | 1 |
+----+---------+
| 2 | 1 |
+----+---------+
| 3 | 3 |
+----+---------+
| 4 | 1 |
+----+---------+
| 5 | 3 |
+----+---------+
Since no answer, I did not know how to handle this with JPA so I added a Trigger on database to do the job. Not pretty but only quick way out.