Hibernate不会在数据库中为单向ManyToOne创建外键

时间:2019-01-02 15:50:00

标签: hibernate jpa jpa-2.0

我有两个实体

@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;
}

enter image description here

在控制台中休眠打印,表明已为城市表创建了外键

Hibernate: alter table Address add constraint FKpwa35mv5w9mb3syngd4m8fprw foreign key (city_id) references City (city_id)

,但在数据库上看不到

谢谢。

1 个答案:

答案 0 :(得分:1)

您可能使用MyISAM作为存储。 MyISAM不支持外键。