1

I've to switch persistence of a project using HIBERNATE to OPENJPA and I started from entities and hbm files which define type of columns, etc. I've an Id on hibernate generated in this way:

<id name="id" type="java.lang.Integer">
      <column name="id"/>
      <generator class="sequence">
        <param name="sequence">seq_illness</param>
      </generator>
    </id>

how can I "translate" it ointo Jpa annotation to my entity class, in particular how can I represent sequence generator? I'm new to this feature and I don't understand well usage of

@GeneratedValue(strategy = GenerationType.SEQUENCE)

how can I reproduce sequence parameter and define the correct sequence generator?

1 Answer 1

3

In JPA, the mapping for this column would look like:

@Id
@SequenceGenerator(name="ID_GEN" sequenceName="NAME_OF_SEQ_IN_DB")
@GeneratedValue(generator="ID_GEN")
private Integer id;

See the following documentation for further information:

@SequenceGenerator

@GeneratedValue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.