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
Asked
Active
Viewed 1,388 times
-2
-
Possible duplicate of Q in the link and A is here : https://stackoverflow.com/a/25052275/2384806 – mdoflaz Jun 09 '22 at 13:52
-
Please provide enough code so others can better understand or reproduce the problem. – Community Jun 09 '22 at 15:35
2 Answers
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;

Tsimpragakis Vasilis
- 56
- 5
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