hibernate外键问题:执行DDL“alter table ...”时出错

问题描述 投票:4回答:1

我有一个非常简单的对象结构,给我一个我无法解决的错误。做了一堆搜索,我认为这必须是一个非常常见的用例,所以不确定问题是什么。我有这三个类:

@Entity
public class Widget {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int idd;
    private Date date;
    private String type;
    private int ownerId;

    @OneToOne(cascade = CascadeType.ALL)
    private Rating rating;


    @OneToMany(cascade = CascadeType.ALL)
    private List<Tag> tagList;


}


@Entity
public class Rating {
public enum ChartType  {RADAR, BAR, LINE, STAR};

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int ratingId;
private String name;

@Enumerated(EnumType.STRING)
private ChartType chartType;
private double normalizedValue;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<RatingComponent> componentList = new ArrayList<>();


public Rating() {
    buildNormalizedValue();
}
}


@Entity
public class RatingComponent {


@Id
@GeneratedValue()
private int compId;

private String name;
private double value;
private double maxValue;

}

在DAO中保存我遇到错误时我并不理解,例如

2018-07-23 11:43:07,208 WARN o.h.t.s.i.ExceptionHandlerLoggedImpl [main] GenerationTarget encountered exception accepting command : 
Error executing DDL "alter table Rating_RatingComponent drop foreign key FKaudjguwlo1i8tm2jgli5bbnq6" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table Rating_RatingComponent drop foreign key FKaudjguwlo1i8tm2jgli5bbnq6" via JDBC Statement

并进一步下来

2018-07-23 11:43:07,644 WARN o.h.t.s.i.ExceptionHandlerLoggedImpl [main] GenerationTarget encountered exception accepting command : Error executing DDL "create table RatingComponent (compId integer not null, maxValue double precision not null, name varchar(255), value double precision not null, primary key (compId)) engine=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table RatingComponent (compId integer not null, maxValue double precision not null, name varchar(255), value double precision not null, primary key (compId)) engine=InnoDB" via JDBC Statement

我的配置中有这些属性

    <property name="hibernate.hbm2ddl.auto">create</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> 

我以为我已经非常仔细地通过了文档,并且认为这是一个非常直接的对象设计......关于如何解决的任何想法,以及我应该在哪些文档中更仔细地研究以了解根本原因?

谢谢!

java hibernate hibernate-mapping
1个回答
0
投票

更换

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

通过

<property name="hibernate.dialect">org.hibernate.dialect.MySQL8InnoDBDialect</property>

会做的

© www.soinside.com 2019 - 2024. All rights reserved.