spring 未找到序列“HIBERNATE_SEQUENCE”;SQL语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39807483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:13:58  来源:igfitidea点击:

Sequence "HIBERNATE_SEQUENCE" not found; SQL statement

springhibernatejpahbm2ddl

提问by Jeff

In my spring mvc app, i have the following object. I am trying to make a visual of data using devtoolin my app.

在我的 spring mvc 应用程序中,我有以下对象。我正在尝试devtool在我的应用程序中使用数据可视化。

@Entity
@Data
public class ConsultationRequest {
    @Id
    @GeneratedValue
    private Long id;

    private String name;

    private String email;

    private String purpose;

    private String programme;

    private int year;

    private String language;

    private String comments;
    @Enumerated(EnumType.STRING)
    private ConsultationStatus status;
}

Then i used the jpa to make the entity:

然后我使用 jpa 来制作实体:

@Repository
public interface ConsultationRequestRepository extends JpaRepository<ConsultationRequest, Long> {

}

The problem is when i load my application, i face with 2 errors:

问题是当我加载我的应用程序时,我面临 2 个错误:

 Unsuccessful: drop sequence hibernate_sequence
[36morg.hibernate.tool.hbm2ddl.SchemaExport  Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:

Then when i open the

然后当我打开

http://localhost:8080/h2-console/

I cannot see the table. It seems that the in the boot process, table is not made.

我看不到桌子。似乎在引导过程中,表没有被制作。

回答by Rohit Gaikwad

Update your code as below:

更新您的代码如下:

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

As you have not specified a sequence table name, hibernate will look for a sequence table named as hibernate_sequenceand use it as default.

由于您没有指定序列表名称,hibernate 将查找名为hibernate_sequence的序列表并将其用作默认值

For Oracle/Postgres, increment fields used are sequence tables.
In MySql, there are increment fields that automatically increment.

对于 Oracle/Postgres,使用的增量字段是序列表。
在MySql中,有自动递增的递增字段。

回答by David

Check persistence.xml

查看 persistence.xml

property name="hibernate.hbm2ddl.auto" value="create"

not hdm2ddl

不是 hdm2ddl

This worked in my case.

这在我的情况下有效。

回答by Oncledjo

If you use a 2nd cache with liquidbase, you have to add the sequence in the changelog like this:

如果您在liquidbase 中使用第二个缓存,则必须像这样在变更日志中添加序列:

<changeSet author="liquibase-docs"
    id="createSequence-example">
    <createSequence catalogName="cat" cycle="false"
        incrementBy="1" ordered="true" schemaName="public"
        sequenceName="hibernate_sequence" startValue="0" />
</changeSet>