Jef*_*eff 15 spring hibernate jpa hbm2ddl
在我的春季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;
}
Run Code Online (Sandbox Code Playgroud)
然后我使用jpa来制作实体:
@Repository
public interface ConsultationRequestRepository extends JpaRepository<ConsultationRequest, Long> {
}
Run Code Online (Sandbox Code Playgroud)
问题是当我加载我的应用程序时,我遇到了2个错误:
Unsuccessful: drop sequence hibernate_sequence
[36morg.hibernate.tool.hbm2ddl.SchemaExport Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
Run Code Online (Sandbox Code Playgroud)
然后,当我打开
http://localhost:8080/h2-console/
Run Code Online (Sandbox Code Playgroud)
我看不到桌子.似乎在启动过程中,表没有制作.
Roh*_*wad 39
更新您的代码如下:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Run Code Online (Sandbox Code Playgroud)
由于您尚未指定序列表名称,因此hibernate将查找名为hibernate_sequence的序列表并将其用作默认值.
对于Oracle/Postgres,使用的增量字段是序列表.
在MySql中,有增量字段自动递增.
小智 7
如果有人在Spring Boot testing(with H2) 中遇到此错误,我们必须在 application.properties(或我们正在使用的任何配置文件)中使用以下内容:
spring.jpa.hibernate.ddl-auto=create-drop
Run Code Online (Sandbox Code Playgroud)
小智 5
校验 persistence.xml
property name="hibernate.hbm2ddl.auto" value="create"
Run Code Online (Sandbox Code Playgroud)
不 hdm2ddl
就我而言,这是可行的。
在属性文件中设置以下属性帮助我解决了hibernate_sequencehibernate 5.4v的问题
spring:
jpa:
hibernate:
use-new-id-generator-mappings: false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20446 次 |
| 最近记录: |