[jboss-user] [EJB 3.0] - Relation many to many based on views
Sadreg
do-not-reply at jboss.com
Mon Sep 3 05:39:39 EDT 2007
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;
| }
| }
JobGroup is master and Category is slave.
Thanks for advance for any answer.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080414#4080414
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080414
More information about the jboss-user
mailing list