Reputation: 197
I need to map a legacy database table which has some weird primary key generated from a sequence concatenated with a static String.
An Oracle Sequence generates the ID as per the norm'. but the ID Column of the table in question is a concatenation of that sequence number and a String AA
. Is it possible to use JPA to create the ID value in that same format when persisting new objects?.
The Oracle Sequence generates incremental numbers, 1
, 2
, 3
, `4 ... etc..
The Id of the table needs to be AA_1
, AA_2
, AA_3
, AA_4
... etc..
I understand how to create an ID from a sequence by annotating the id field in the class and I assume I need to write my own bespoke ID generation class which gets the sequence and conatenates the AA
String on to it.
Upvotes: 0
Views: 910
Reputation: 7218
You will need to create your own custom identifier generator by extending the IdentifierGenerator interface.
This can then use the Oracle sequence to get your value and then perform the concatenation.
You can then specify your generator class in your mappings.
Upvotes: 2