I found configuration with that it compiles and allows to add ojects. But I have a problem, that by removing of the objects (even if I do it on both sides) - entries in the JoinTable are not removed and therefore, I always have foreign key constraint violation. Only if I delete these JoinTable entries manually per ebean SQL Query it seems to work. But is there a better way to remove JoinTable entries? I thought that should happen automatically?
Regards,
Roman
@Entity
@Table(name = "taxonomy")
public class Taxonomy extends Model {
@Id
@Column(name="ID")
public Long tid;
//bi-directional many-to-many association to Target
@ManyToMany
@JoinTable(name = "subject_target", joinColumns = { @JoinColumn(name = "id_taxonomy", referencedColumnName="ID") },
inverseJoinColumns = { @JoinColumn(name = "id_target", referencedColumnName="ID") })
private List<Target> targets = new ArrayList<Target>();
public List<Target> getTargets() {
return this.targets;
}
public void setTargets(List<Target> targets) {
this.targets = targets;
}
@Entity
@Table(name = "target")
public class Target extends Model {
@Required
@Id
@Column(name="ID")
public Long nid;
@ManyToMany(mappedBy="targets")
public List<Taxonomy> subject_to_target = new ArrayList<Taxonomy>();
TargetController.java:
SqlUpdate removeOldAssociation = Ebean.createSqlUpdate("DELETE FROM subject_target WHERE id_target = " + target.nid);
removeOldAssociation.execute();