在jpa中删除与复合键的多对多关系

时间:2015-07-01 11:24:45

标签: java jpa many-to-many eclipselink

我与复合键有很多关系。现在我想从连接实体类中删除一个项目,该项目是数据库中的一行。我怎样才能做到这一点?

第1节

@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tag", , orphanRemoval = true)
private List<TagDefinitionProject> tagProjects = new ArrayList<TagDefinitionProject>();

第2侧

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "project", , orphanRemoval = true)
private List<TagDefinitionProject> tagProjects = new ArrayList<TagDefinitionProject>();

加入课程:

    @Id
    @JoinColumn(name = "id_tag", referencedColumnName = "id")
    @ManyToOne(optional = false)
    @JsonBackReference
    private Tag tag;

    @Id
    @JoinColumn(name = "id_project", referencedColumnName = "id_project")
    @ManyToOne(optional = false,fetch = FetchType.EAGER)    
    private Project project;

PK课程:

    @Id
    @Column(name = "id_tag")
    private Integer tag;

    @Id
    @Column(name = "id_project")
    private Integer project;

在我的服务层代码中,我正在尝试这样做,但它不起作用。

 TagDefinitionProject t = tagDao.findByTagAndProject(i,j);
 tdpDao.remove(t);

0 个答案:

没有答案