数据未保存在连接表中

时间:2013-10-04 05:51:24

标签: jpa jointable

我使用NetBeans(EclipseLink JPA)基于下图生成实体:

enter image description here

相关的生成代码是:

Course

@JoinTable(name = "course_software", joinColumns = {
    @JoinColumn(name = "course_id", referencedColumnName = "id", nullable = false)}, inverseJoinColumns = {
    @JoinColumn(name = "software_id", referencedColumnName = "id", nullable = false)})
  @ManyToMany
  private List<Software> softwareList;

Software

@ManyToMany(mappedBy = "softwareList")
  private List<Course> courseList;

问题在于Course实体。当我尝试坚持如下时

getFacade().create(currentCourse);
currentCourse.setSoftwareList(selectedSoftware);

然后在course中创建记录,但在course_software联接表中没有创建任何内容。

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:0)

只要连接表中引用的列已经是主键,您似乎不需要指定referencedColumnName注释的@JoinColumn属性。

相关问题