Hibernate OnDelete Cascade not working for MySql but Works on postgres and Ms-Sql

后端 未结 1 1503
借酒劲吻你
借酒劲吻你 2021-02-04 20:22

I\'m having 2 Entities. Thread entity and Post entity using OnetoOne mapping from Post->Thread.

A Thread

1条回答
  •  悲&欢浪女
    2021-02-04 20:44

    This is what I did to resolve this problem based on Spring Boot.

    Solution

    from

    // application.properties  
    spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
    

    to

    spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
    

    Explanation
    As you can see below, it seems like the default value for CascadeDelete at MySQL5InnoDBDialect.java only support Cascade.

    // MySQLDialect.java
    @Override
        public boolean supportsCascadeDelete() {
            return false;
        }
    
    // MySQL5InnoDBDialect.java
    @Override
        public boolean supportsCascadeDelete() {
            return true;
        }
    

    0 讨论(0)
提交回复
热议问题