one-to-many

JPA OneToMany and ManyToOne throw: Repeated column in mapping for entity column (should be mapped with insert=“false” update=“false”)

南笙酒味 提交于 2019-11-26 10:26:53
问题 I have three classes one of the name is User and this user have other classes instances. Like this; public class User{ @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL) public List<APost> aPosts; @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL) public List<BPost> bPosts; } public class BPost extends Post { @ManyToOne(fetch=FetchType.LAZY) public User user; } public class APost extends Post { @ManyToOne(fetch=FetchType.LAZY) public User user; } it\'s working like this but

When to use inverse=false on NHibernate / Hibernate OneToMany relationships?

故事扮演 提交于 2019-11-26 10:08:44
问题 I have been trying to get to grips with Hibernate\'s inverse attribute, and it seems to be just one of those things that is conceptually difficult. The gist that I get is that when you have a parent entity (e.g. Parent) that has a collection of Child objects using a one-to-many mapping, setting inverse=true on the mapping tells Hibernate that \'the other side (the Child) has responsibility to update itself to maintain the foreign key reference in its table\'. Doing this appears to have 2

Difference Between One-to-Many, Many-to-One and Many-to-Many?

吃可爱长大的小学妹 提交于 2019-11-26 06:52:45
问题 Ok so this is probably a trivial question but I\'m having trouble visualizing and understanding the differences and when to use each. I\'m also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the one-to-many/many-to-many relationships. I\'m using Hibernate right now so any explanation that\'s ORM related will be helpful. As an example let\'s say I have the following set-up: public class Person{ private Long personId; private Set<Skill> skills; /

@OrderColumn annotation in Hibernate 3.5

此生再无相见时 提交于 2019-11-26 06:33:58
问题 I\'m trying to use the @OrderColumn annotation with Hibernate 3.5 @OneToMany(mappedBy = \"parent\",fetch=FetchType.EAGER, cascade=CascadeType.ALL) @OrderColumn(name = \"pos\") private List<Children> childrenCollection; When retrieving data, everything works fine. But I can\'t make it reorder elements in the List and save the new order to the database. 回答1: The combination of @OneToMany(mappedBy="...") and @OrderColumn is not supported by Hibernate. This JIRA issue tracks a request to throw a

JPA: How to have one-to-many relation of the same Entity type

冷暖自知 提交于 2019-11-26 02:16:37
问题 There\'s an Entity Class \"A\". Class A might have children of the same type \"A\". Also \"A\" should hold it\'s parent if it is a child. Is this possible? If so how should I map the relations in the Entity class? [\"A\" has an id column.] 回答1: Yes, this is possible. This is a special case of the standard bidirectional @ManyToOne / @OneToMany relationship. It is special because the entity on each end of the relationship is the same. The general case is detailed in Section 2.10.2 of the JPA 2

What&#39;s the difference between @JoinColumn and mappedBy when using a JPA @OneToMany association

元气小坏坏 提交于 2019-11-26 01:19:19
问题 What is the difference between: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY) @JoinColumn(name = \"companyIdRef\", referencedColumnName = \"companyId\") private List<Branch> branches; ... } and @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY, mappedBy = \"companyIdRef\") private List<Branch> branches; ... } 回答1: The annotation @JoinColumn indicates that this entity is the owner of the relationship

What is the meaning of the CascadeType.ALL for a @ManyToOne JPA association

心已入冬 提交于 2019-11-26 00:57:02
问题 I think I misunderstood the meaning of cascading in the context of a @ManyToOne relationship. The case: public class User { @OneToMany(fetch = FetchType.EAGER) protected Set<Address> userAddresses; } public class Address { @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) protected User addressOwner; } What is the meaning of the cascade = CascadeType.ALL ? For example, if I delete a certain address from the database, how does the fact that I added the cascade = CascadeType.ALL

What is the meaning of the CascadeType.ALL for a @ManyToOne JPA association

余生长醉 提交于 2019-11-25 23:42:16
I think I misunderstood the meaning of cascading in the context of a @ManyToOne relationship. The case: public class User { @OneToMany(fetch = FetchType.EAGER) protected Set<Address> userAddresses; } public class Address { @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) protected User addressOwner; } What is the meaning of the cascade = CascadeType.ALL ? For example, if I delete a certain address from the database, how does the fact that I added the cascade = CascadeType.ALL affect my data (the User , I guess)? The meaning of CascadeType.ALL is that the persistence will propagate