[英]hibernate doesn't create all the associated tables
我有三個實體類。 通過使用Spring Boot,我試圖創建所有這三個表。 但只會創建三張桌子中的一張。
我所有的三個班是:
Users.java
@Entity
@Table(name = "users")
public class Users {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable = false, updatable = false)
private long id;
private String username;
private String password;
private String firstName;
private String lastName;
@Column(name="email", nullable = false, updatable = false)
private String email;
private String phone;
private boolean enabled=true;
@OneToMany(mappedBy = "users", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonIgnore
private Set<UserRole> userRoles = new HashSet<>();
---------------------getter setters--------------------------------
}
UserRole.java
@Entity
@Table(name="user_role")
public class UserRole {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long userRoleId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="user_id")
private Users users;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="role_id")
private Role role;
===============getter setters==============================
}
Role.java
@Entity
@Table(name="user_role")
public class UserRole {
@Id
private long roleId;
private String name;
@OneToMany(mappedBy = "role", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
private Set<UserRole> userRoles = new HashSet<>();
==============getter setters ====================
我希望休眠會創建三個表,但就我而言,只有一個表角色正在創建,並且出現錯誤
由以下原因引起:org.hibernate.tool.schema.spi.SchemaManagementException:無法執行對JDBC目標的架構管理[創建表user_role(user_role_id數字(19,0)身份不為null,role_id數字(19,0),user_id數字( 19,0),主鍵(user_role_id))]
引起原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL語法有錯誤; 檢查與您的MySQL服務器版本相對應的手冊以獲取正確的語法,以在'identity not null,role_id numeric(19,0),user_id numeric(19,0),primary key(us)第1行附近使用
錯誤指出您正在MySQL數據庫引擎中嘗試使用“ IDENTITY NOT NULL”,這是無效的。 IDENTITY是一個SQL SERVER關鍵字。
確保已為數據庫引擎正確配置了Hibernate。 您應該使用MySQLDialect。
在您的application.properties中:
spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.