2

This is the error. The 'SQ_USERS' is the sequence created in a sql server database.

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'dbo.SQ_USERS'.

This is the entity that is used to get the sequence...

@Entity
@Table(name="USERS")
public class User {

    @Id
    @Column(name="id")
    @SequenceGenerator(name = "USER", schema="dbo", sequenceName = "SQ_USERS", allocationSize = 20)
    @GeneratedValue(generator = "USER", strategy = GenerationType.SEQUENCE)
    private int id;
}

The sql that is generated is "select next_val as id_val from dbo.SQ_USERS with (updlock, rowlock)", but if i try this in sql server management studio, i get the error "Invalid object name 'dbo.SQ_USERS'."

Can anyone help?

Thanks.

3 Answers 3

3

I found the issue to the problem. I was using the wrong hibernate dialect. When I changed the dialect to "SQLServer2008Dialect" it worked correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

I was using : spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect It works with : spring.jpa.database-platform=org.hibernate.dialect.SQLServer2008Dialect
0

Try adding schema and catalog to your @Table annotation and see if the error is fixed:

Something like this:

@Table(name="USERS", catalog="<your database name>", schema="dbo")

Comments

0

If Hibernate dialect is specified as org.hibernate.dialect.SQLServerDialect, then the SQL generated to obtain a sequence's next value is:

select next_val from my_sql_server_sequence with (updlock, rowlock);

which fails with an error: [S0002][208] Invalid object name 'my_sql_server_sequence'.

If Hibernate dialect is specified as org.hibernate.dialect.SQLServer2012Dialect, then the SQL generated to obtain a sequence's next value is:

select next value for my_sql_server_sequence;

This works with Microsoft SQL Server 2017 and Hibernate 5.4.23.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.