Reputation: 4130
Because of some issues with implementing Spring Security on top of a legacy database schema, our user id needs to be generated by a sequence, but stored as a VARCHAR(9). So, we'll convert on the database side to make this invisible to the code side (sequences/triggers/etc).
However, as far as I know, this will blow up if mapped via GenerationType.SEQUENCE like this:
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="MYGENERATOR")
Since the field will be populated via trigger, can I just map with a GenerationType.IDENTITY?
@GeneratedValue(strategy=GenerationType.IDENTITY)
Thanks, Jason
Upvotes: 0
Views: 1771
Reputation: 21000
This might work. You can set the type of identifier field to String and use the GenerationType.IDENTITY strategy.
The one thing to ensure is that the generated id can be fetched using the JDBC api (PreparedStatement.getGeneratedKeys). This page has more details on what is needed to make it work.
Upvotes: 1