Vikas
Vikas

Reputation: 24342

Hibernate annotations, autoincrement related

i am using hibernate annotations, at the back end i am using Postgres SQL 8.3. So, i don't know how to apply sequence in annotations of my Class.

Plz provide related help for this.

Upvotes: 2

Views: 6971

Answers (2)

Matt Sidesinger
Matt Sidesinger

Reputation: 2154

You can have more control over the generated sequence by implementing it like this:

@Id
@GeneratedValue(generator="YourGeneratorName")
@GenericGenerator(
        name="YourGeneratorName", strategy="seqhilo",
        parameters={
                @Parameter(name="max_lo", value="1"),
                @Parameter(name="sequence", value="seq_name_of_the_sequence")
            }
)
private Long id;

Upvotes: 4

tehvan
tehvan

Reputation: 10369

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

Then, put this in front of your sequence field:

@GeneratedValue(strategy=GenerationType.SEQUENCE)

hope that was of any help...

Upvotes: 3

Related Questions