1用户应该有很多邮件,但是当我运行spring boot应用程序时,它不会创建我的邮件表。(它会创建用户,角色,users_roles,users_mails)
我的用户类。我尝试使用mappingBy =“ user”,但是我也没有创建users_mail表。
@Entity
@Table(name="users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private String email;
private String password;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(
name = "users_roles",
joinColumns = @JoinColumn(
name = "user_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(
name = "role_id", referencedColumnName = "id"))
private Collection < Role > roles;
@OneToMany
private List<Mail > mails;
public User() {}
public User(String firstName, String lastName, String email, String password, Collection<Role> roles, List<Mail> mails) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.password = password;
this.roles = roles;
this.mails = mails;
}
}
我的角色课程。
@Entity
@Table(name="roles")
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public Role() {}
}
我的邮件班级。
@Entity
@Table(name="mails")
public class Mail {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@ManyToOne
private User user;
private String subject;
private String from;
private String text;
public Mail() {
}
public Mail(String destination,String subject, String text) {
this.from = destination;
this.subject=subject;
this.text = text;
}
}
我的application.properties。请不要告诉我使用... ddl-auto = update。头疼。
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp spring.datasource.url = jdbc:mysql://localhost:3306/users_app?useSSL=false spring.datasource.username = root spring.datasource.password = 123456 spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
我的代码错误: :GenerationTarget遇到异常接受命令:通过JDBC语句执行DDL错误
org.hibernate.tool.schema.spi.CommandAcceptanceException:通过JDBC语句执行DDL错误
休眠:更改表users_mails删除外键FKl5thenbbsfpv2fv7etw9o800n 2019-04-30 19:31:27.017 WARN 7004 --- [restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl:GenerationTarget遇到异常接受命令:通过JDBC语句执行DDL错误
产生原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 无法删除'FKl5thenbbsfpv2fv7etw9o800n';检查列/键是否存在
但是它开始了。
....在8.654秒内启动MailApplication(JVM运行9.887)