There is two tables which are connected with help of view. View has only two ids of those tables. We have also two entities which are based on those tables.
To connect entities I use @ManyToMany and @JoinTable annotations. In @JoinTable annotation I tried to use view as join-table. Everything works, all entities are connected but when one entity (which is master) is removed, I am getting exception "ERROR:Can not delete from view" (even if there is no slave entity).
Piece of code:
@Entity ... public class JobGroup implements Serializable { private long id ; private String name; private Collection<Category> categories; public JobGroup() { } ... @ManyToMany(cascade = {}) @JoinTable(name = "some_view", joinColumns = {@JoinColumn(name = "job_group_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "category_id", referencedColumnName = "id")}) public Collection<Category> getCategories() { return this.categories; } public void setCategories(Collection<Category> categories) { this.categories = categories; } } //----------------- @Entity ... public class Category implements Serializable { protected long id; protected String name; ... @ManyToMany(mappedBy = "categories", cascade = {}) public Collection<JobGroup> getJobGroups() { return jobGroups; } public void setJobGroups(Collection<JobGroup> jobGroups) { this.jobGroups = jobGroups; } }