小编Rak*_*akz的帖子

Hibernate OnDelete Cascade不适用于MySql但适用于postgres和Ms-Sql

我有两个实体.使用Post-> Thread的 OnetoOne映射的线程实体和Post实体.

一个线程实体包含许多文章.我知道我应该使用OnetoMany而不是OnetoOne,但为了避免所有收集问题我正在使用OnetoOne

现在的问题是,当我删除一个线程时,还必须删除与之关联的所有帖子.我成功地使用了它

@OnDelete(action = OnDeleteAction.CASCADE)
Run Code Online (Sandbox Code Playgroud)

但它只适用于Postgres和Ms-SQl,但不适用于MySql(也尝试过InnoDb).在上删除级联未在架构生成查询生成.

以下是代码

//Thread Entity
@Id
@GeneratedValue
@Column(name = "thread_id")
private int ThreadID;
Run Code Online (Sandbox Code Playgroud)
//Post Entity
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "post_id")
private int PostID;

@OneToOne()
@OnDelete(action = OnDeleteAction.CASCADE)
private thread ThreadID;
Run Code Online (Sandbox Code Playgroud)

我使用以下查询从Thread实体中删除项目时出现以下错误

session.delete(session.load(thread.class,1));
Run Code Online (Sandbox Code Playgroud)

2014年9月2日下午8:33:51 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN:SQL错误:1451,SQLState:23000 Sep 02,2014 8:33:51 PM org.hibernate.engine.jdbc. spi.SqlExceptionHelper logExceptions错误:无法删除或更新父行:外键约束失败(forum.post_tbl,CONSTRAINT FK_bfbv5nknqj7ppd5630scimhtbFOREIGN KEY(ThreadID_thread_id)REFERENCES thread_tbl …

java mysql hibernate jpa hibernate-cascade

5
推荐指数
1
解决办法
1761
查看次数

H2嵌入DB,弹出启动错误自动配置

我正在尝试使用带有弹簧靴的H2嵌入式DB.但是,它会引发以下错误.

2016-10-19 22:05:25.818  INFO 14104 --- [           main] com.example.SpringDemoApplication        : Starting SpringDemoApplication on BOM1-LPMP12AS7U with PID 14104 (D:\workspace\eclipse\SpringDemo\target\classes started by e3028311 in D:\workspace\eclipse\SpringDemo)
2016-10-19 22:05:25.822  INFO 14104 --- [           main] com.example.SpringDemoApplication        : No active profile set, falling back to default profiles: default
2016-10-19 22:05:25.904  INFO 14104 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@543e710e: startup date [Wed Oct 19 22:05:25 IST 2016]; root of context hierarchy
2016-10-19 22:05:27.609  INFO 14104 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ece75ca4] …
Run Code Online (Sandbox Code Playgroud)

java jar h2 maven spring-boot

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×2

h2 ×1

hibernate ×1

hibernate-cascade ×1

jar ×1

jpa ×1

maven ×1

mysql ×1

spring-boot ×1