views:

385

answers:

1

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.

A: 

No existing key generator can do that for you but you can write your own. See this answer for some pointers about getting started.

Aaron Digulla