SQL Server 2016 - 无效的对象名称'hibernate_sequence'

Inv*_*tor 5 sql-server jpa spring-boot

我有一个图像备份,我恢复到MS SQL服务器2016.我有一个实体声明其ID如下:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlID
@XmlElement
@XmlJavaTypeAdapter(IntToStringXmlAdapter.class)
private Integer id;
Run Code Online (Sandbox Code Playgroud)

当我保存我收到的实体时:

Hibernate: select next_val as id_val from hibernate_sequence with (updlock, rowlock) 2018-02-28 22:05:41.935 
ERROR 18152 --- [nio-8080-exec-6] o.hibernate.id.enhanced.TableStructure   : could not read a hi value com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'hibernate_sequence'. 

...... 
2018-02-28 22:05:41.942  WARN 18152 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 208, SQLState: S0002 

2018-02-28 22:05:41.942 ERROR 18152 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : Invalid object name 'hibernate_sequence'.
Run Code Online (Sandbox Code Playgroud)

我已经手动创建了SQL服务器的序列,并确保它通过SSMS存在.

CREATE SEQUENCE hibernate_sequence
 AS INTEGER
 START WITH 1
 INCREMENT BY 1
 MINVALUE 1
 MAXVALUE 99
 NO CYCLE; 
Run Code Online (Sandbox Code Playgroud)

尽管如此,我继续收到上一个错误.

我有什么想法我做错了吗?

先感谢您

Rob*_*roj 15

以下要点检查:

  • 你正在使用什么方言?
  • 你正在使用什么hibernate版本?版本5更改了GenerationType.AUTO行为
  • 设置"hibernate.hbm2ddl.auto"update看看它在数据库中创建
  • 避免GenerationType.AUTO.将其设置为显式GenerationType.IDENTITYGenerationType.SEQUENCE根据您的需要或您的数据库支持.
  • 检查您是否具有最新的SQL Server JDBC驱动程序.我遇到了从hibertnate 4.3迁移到5.0的问题
  • 在hibernate 5中设置hibernate.id.new_generator_mappings为false

  • 谢谢你。它与 IDENTITY 一起使用。方言是 org.hibernate.dialect.SQLServer2012Dialect。Sprigg Boot version1.5.10.RELEASE。 (3认同)