Reputation: 24342
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
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
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