我有两个实体
@Entity
public class Address {
@ManyToOne(cascade = {CascadeType.PERSIST})
@JoinColumn(name = "city_id")
private City city;
}
@Entity
public class City {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "city_id")
private int id;
}
在控制台中休眠打印,表明已为城市表创建了外键
Hibernate: alter table Address add constraint FKpwa35mv5w9mb3syngd4m8fprw foreign key (city_id) references City (city_id)
,但在数据库上看不到
谢谢。
答案 0 :(得分:1)
您可能使用MyISAM作为存储。 MyISAM不支持外键。