当我生成表格时,它会生成它,但JPA不生成任何FK .
当我告诉mysql向我展示它创建表时它做了什么,它显示缺少外键约束 . 它只生成KEY,而不是添加外键 .
mysql> show create table view_display;
| view_display | CREATE TABLE view_display(dtype varchar(31)NOT NULL,id bigint(20)NOT NULL,col int(11)NOT NULL,row int(11)NOT NULL,chart_id bigint(20)DEFAULT NULL,view_id bigint(20)NOT NULL,data_source_id bigint(20)DEFAULT NULL,PRIMARY KEY(id),KEY FKqllm025dtc51xf38qdr5je52q(chart_id),KEY FKb1gu01sld2cm281oa88pjq9ia(view_id),KEY FK2hljr3ohtf3vql7hhvyqbm2mc(data_source_id))ENGINE = MyISAM DEFAULT CHARSET = latin1 |
View.java
@Entity
@Table(name="view")
public class View {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "view_seq")
@SequenceGenerator(name = "view_seq", sequenceName = "view_seq", allocationSize = 1)
private Long id;
private String name;
@Column(name ="is_default",nullable= false,columnDefinition="tinyint(1) default 0")
private boolean isDefault;
@ManyToOne
@JoinColumn(name="userId",insertable=true, updatable= false,nullable=true)
private User user;
@OneToOne
@JoinColumn(name="cvId",insertable=true, updatable= false,nullable=true,unique=true)
private CV cv;
@OneToMany(mappedBy="view")
private List<ViewDisplay> viewDisplay;
// getters and setters....
}
ViewDisplay.java
@Entity
@Table(name = "view_display")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class ViewDisplay {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "view_display_seq")
@SequenceGenerator(name = "view_display_seq", sequenceName = "view_display_seq", allocationSize = 1)
private Long id;
@ManyToOne
@JoinColumn(name="chartId",insertable=true, updatable= true, nullable = true)
private Chart chart;
@ManyToOne
@JoinColumn(name = "viewId", insertable = true, updatable = true, nullable=false)
private View view;
private int col;
private int row;
public ViewDisplay() {}
public ViewDisplay(Long id, Chart chart, View view, int col, int row) {
super();
this.id = id;
this.chart = chart;
this.view = view;
this.col = col;
this.row = row;
}
// getters and setters...
}