Indirectly generate sequence numbers for composite primary keys with JPA
-
18-09-2019 - |
Question
I have a JPA entity class with a composite primary key (uid,lid) that in the database should look like this;
UID | LID | ...
---------------
1 | 1 | ...
1 | 2 | ...
1 | 3 | ...
2 | 1 | ...
2 | 2 | ...
2 | 3 | ...
How can I make EclipseLink/JPA generate sequence numbers on the fly, or how can I find out the highest number in the UID-column?
Or if I have a UID but want to add a new LID?
Apologies if this is a too easy question. :) Composite keys a quite complex thing to me, but I think I start to understand them a bit.
Solution
No existing key generator can do that for you but you can write your own. See this answer for some pointers about getting started.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow