I have a pretty simple object structure that is giving me an error I'm not able to resolve. Have done a bunch of searching, and I think this must be a pretty common use case, so not sure what the issue is. I have these three classes:
@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;
}
when saving in the DAO I'm getting errors I don't really understand, such as
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
and further down
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
I have these properties in my config
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
I thought I had gone thru the docs pretty carefully, and think this is a pretty straight forward object design...any ideas as to how to resolve, and where in the docs should I research more carefully to understand the root cause?
thanks!
I had used an SQL reserved word 'order'
as the entity name, due to which I was getting a similar error. Renaming it solved it for me. Look at your entity names, have you used any reserved word in them?
replacing
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
by
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8InnoDBDialect</property>
will do the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With