0

The entity A has an OneToMany relation with the entity B. I would like to use a composite primary key for the entity B, where one of the columns is the same as the the primary key of the entity A and the second column should be generated. How can the second column be started from 1 whenever the the other involving column within the composite primary key changes?

I use Oracle data bank and could not find any solution.

Thanks in advance!

  • So you want a sequence/count that is per A? There isn't a DB sequence, so such functionality isn't included in JPA, but you can write your own in any pre-persist event on B to count all Bs associated with that A (or return the max ID value for those Bs) and use the next one. Or use a database stored proc to do the insert and set the ID for you. – Chris Jan 31 '23 at 18:47

0 Answers0