tags:

views:

2098

answers:

2

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.

A: 
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...

tehvan
+2  A: 

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;
mattsidesinger