i have the following hibernate mapping:
Class Magazine:
@Entity
@Table(name = "PROJECTNAME_MAGAZINE")
@SequenceGenerator(name = "MAGAZINE_SEQUENCE_GENERATOR", sequenceName = "MAGAZINE_SEQUENCE")
@Analyzer(definition = "customanalyzer")
public class Magazine extends AbstractBaseEntity implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MAGAZINE_SEQUENCE_GENERATOR")
@Column(name = "ID")
private Long id;
@NotNull
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, mappedBy="magazine", orphanRemoval = true)
private List<MagazineKeywordMapper> magazineKeywordMappings;
Class MagazineKeyword
@Entity
@Table(name = "PROJECTNAME_MAGAZINE_KEYWORD")
public class MagazineKeyword extends AbstractBaseEntity {
public MagazineKeyword(String keyword) {
this.keyword = keyword;
this.id = (long) keyword.hashCode();
}
@Id
@Column(name = "ID")
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="keyword",orphanRemoval=true)
private List<MagazineKeywordMapper> magazineMappings;
Class MagazineKeywordMapper
@Entity
@Table(name="MAGAZINE_KEYWORD_MAPPER")
public class MagazineKeywordMapper extends AbstractBaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID")
private Long id;
@ManyToOne
@PrimaryKeyJoinColumn(name="MAGAZINE_ID", referencedColumnName="ID")
private Magazine magazine;
@ManyToOne
@PrimaryKeyJoinColumn(name="KEYWORD_ID", referencedColumnName="ID")
private MagazineKeyword keyword;
public MagazineKeywordMapper() {
}
public MagazineKeywordMapper(Magazine magazine, MagazineKeyword keyword) {
this.magazine = magazine;
this.keyword = keyword;
this.id = Long.parseLong(magazine.getId()+""+keyword.getId());
}
I tried alot of stuff, but somehow i could not manage to find a good way to do deletes on the mappings. If i delete a keyword i want all the mappings containing this keyword to be deleted. Somehow all i get are IntegrityConstraintViolations...what am i doing wrong? I use DAO's and call EntityManager.remove() on the keyword object. I also tried manually removing the mappings from the associated Magazine objects. Any hints are highly appreciated. Thanks for your help guys!:)