Sequence “HIBERNATE_SEQUENCE” not found; SQL statement

大兔子大兔子 提交于 2019-11-29 08:16:02

问题


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

@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:

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

}

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

 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.


回答1:


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_sequence and use it as default.

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




回答2:


Check persistence.xml

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

not hdm2ddl

This worked in my case.




回答3:


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

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


来源:https://stackoverflow.com/questions/39807483/sequence-hibernate-sequence-not-found-sql-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!