-2

We are using @sequencegenerator annotations to generate sequence in mssql database but when we execute sequence is generated as table instead of sequence, we have used 2012Dialect but still we face same issue and application throws exception invalid object name - sequence name-. Please help with solution

2 Answers2

0

Have you used GeneratedValue annotation to specify that the id generation value witll be from a database sequence?

example:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_name")
@SequenceGenerator(name = "seq_name", sequenceName = "seq_name_in_database", allocationSize = 1)
@Column(name = "id")
private Long id;
0

It seems that Hibernate (v 5.6.3) is using its own tables to manage sequences in sql server, you must create the table with the same name as your sequence with one column named next_val then insert a line with the init value. Hibernate use the query to select :

select next_val as id_val from sequence_name with (updlock,rowlock)

then increment the next_val :

update sequence_utilisateur set next_val= ? where next_val=?

Also don't define the column for wich you use the generated value as IDENTITY.

Lhoussin Ghanem
  • 179
  • 1
  • 8