andPat
andPat

Reputation: 4522

Java - Openjpa: how to specify sequence generator starting from hibernate hbm

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?

Upvotes: 1

Views: 1820

Answers (1)

Kevin Bowersox
Kevin Bowersox

Reputation: 94489

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

Upvotes: 3

Related Questions