many-to-many

JPA: detached entity passed to persist: nested exception is org.hibernate.PersistentObjectException

浪尽此生 提交于 2019-12-19 11:34:55
问题 JPA: many-to-many connection. Scenerio: Multiple product can be saved under multiple categories. Like: Mango can be used as Fruit category and Desert Category. Product == [COMMODITY] Category == [GENRE] Exception: detached entity passed to persist: sari.core.domain.account.Genre; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: Commodity.java: @Entity @Table(name = "COMMODITY") public class Commodity implements Serializable { @Id @Column(name =

Get all entries from Table B which have a relation to multiple entries (given list) from Table A

一个人想着一个人 提交于 2019-12-19 11:23:04
问题 I have two tables. Table A and Table B . Both are connected with a many-to-many relationship. Table A: ID --- 1 2 Table B: ID --- 3 4 Table AB: ID | A_ID | B_ID ---------------- 5 | 1 | 4 6 | 1 | 3 7 | 2 | 3 I want to get the list of ID s from table B which have a relation to a list of ID s of table A . Example from the above tables: I want to get all B s which have a relation to table A ID 1 and ID 2. I get then ID 3 has to both ID s of table A . How could I do this with an SQL query ? 回答1:

Many to Many inside Many to Many Table

不羁岁月 提交于 2019-12-19 10:50:10
问题 I have a Table Orders which contains a List of Products . For each of the Products corresponding to the specific Order I need to store a List of Addresses where individual product(per Order per Product basis) should be delivered to +----------------+------------+ | Order_ID | Product_ID | +----------------+------------+ | 1 | 1000 | | 2 | 1000 | | 2 | 1001 | +----------------+------------+ So I have this table which is a many to many on Orders and Products what I need is to map each of the

Dynamic finders with Grails many-to-many relationship

大憨熊 提交于 2019-12-19 10:15:53
问题 I have 2 domain classes which are mapped by many-to-many relationship. I followed the instruction of Grails documentation, but I still have some problem when processing data on those domains. Here are my 2 domain classes: class User { String name int age String job static hasMany = [groups : Group] static belongsTo = [org : Organization] } class Group { String groupName String code static hasMany = [members : User] } My problems are: 1. The above relationship require one class hold belongsTo

Dynamic finders with Grails many-to-many relationship

删除回忆录丶 提交于 2019-12-19 10:15:03
问题 I have 2 domain classes which are mapped by many-to-many relationship. I followed the instruction of Grails documentation, but I still have some problem when processing data on those domains. Here are my 2 domain classes: class User { String name int age String job static hasMany = [groups : Group] static belongsTo = [org : Organization] } class Group { String groupName String code static hasMany = [members : User] } My problems are: 1. The above relationship require one class hold belongsTo

Hibernate Bidirectional ManyToMany delete issue

蹲街弑〆低调 提交于 2019-12-19 08:59:48
问题 In my project I have entities for users and companies: @Entity @Table(name = "users") public class UserDetails { @Id @GeneratedValue @Column(name = "user_id") private int id; @Column(name = "first_name") @NotEmpty @Size(min = 2, max = 20) private String firstName; @ManyToMany(cascade = CascadeType.REFRESH) @JoinTable(name = "users_companies", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "company_id")) private Set<CompanyDetails> userCompanies = new

How to work with unsaved many-to-many relations in django?

天大地大妈咪最大 提交于 2019-12-19 07:59:19
问题 I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory , present them to the user (via custom method-calls inside the view-templates) and if the user is satisfied, save them to the database. However, if I try to do anything on the model-instances (call rendering methods, e.g.), I get an error message that says that I have to save the instances first. The documentation says that this is because the models are in a many-to-many

How to work with unsaved many-to-many relations in django?

ぃ、小莉子 提交于 2019-12-19 07:59:12
问题 I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory , present them to the user (via custom method-calls inside the view-templates) and if the user is satisfied, save them to the database. However, if I try to do anything on the model-instances (call rendering methods, e.g.), I get an error message that says that I have to save the instances first. The documentation says that this is because the models are in a many-to-many

Cyclic references in a bidirectional many to many relationship

僤鯓⒐⒋嵵緔 提交于 2019-12-19 05:58:29
问题 I'm having a bidirectional many to many relationship in my entities. See the example below: public class Collaboration { @JsonManagedReference("COLLABORATION_TAG") private Set<Tag> tags; } public class Tag { @JsonBackReference("COLLABORATION_TAG") private Set<Collaboration> collaborations; } When I try to serialize this to JSON, I'm getting the following exception: ` "java.lang.IllegalArgumentException: Can not handle managed/back reference 'COLLABORATION_TAG': back reference type (java.util

How to access fields in a customized many-to-many through object in templates

依然范特西╮ 提交于 2019-12-19 05:17:41
问题 Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) date_joined = models.DateField() invite_reason = models.CharField(max_length=64) Membership is a customized many-to-may through object with extra fields. If I have a