Tuesday, September 16, 2008

Defining the name of a sequence with JPA annotations

Last week I was giving another workshop about object-relational mapping at the workshop-days of /ch/open.

I got quite positive feedback from several participants and I am curious about the official ratings.

During the exercises there was the question how to define the name of a sequence when using the strategy GenerationType.SEQUENCE.
I did not know the answer then, but here it is:

@SequenceGenerator(name="PROD_SEQ", sequenceName="product_seq")
public class Product {

    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="PROD_SEQ")
    long id;
    String title;


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...