hibernate-onetomany

Don't change the reference to a collection with cascade=“all-delete-orphan”

南笙酒味 提交于 2019-12-05 22:00:50
问题 I am getting an error: Don't change the reference to a collection with cascade="all-delete-orphan" while trying the following operation: beginTx(); Parent parent = new Parent(); Child child = new Child(); parent.addChild(child); getSession().save(parent); commitTx(); closeSession(); beginTx(); //id is the primary key child.setID(null); getSession().update(child); commitTx(); closeSession(); Parent and child are related by one-to-many with cascade = ' all-delete-orphan '. class Parent { Set

Don't change the reference to a collection with cascade=“all-delete-orphan”

寵の児 提交于 2019-12-04 03:37:41
I am getting an error: Don't change the reference to a collection with cascade="all-delete-orphan" while trying the following operation: beginTx(); Parent parent = new Parent(); Child child = new Child(); parent.addChild(child); getSession().save(parent); commitTx(); closeSession(); beginTx(); //id is the primary key child.setID(null); getSession().update(child); commitTx(); closeSession(); Parent and child are related by one-to-many with cascade = ' all-delete-orphan '. class Parent { Set child; } <set name="child" table="Child" cascade="all-delete-orphan" inverse="true"> <key column="FK"><

TransientObjectException - object references an unsaved transient instance - save the transient instance before flushing

徘徊边缘 提交于 2019-12-03 10:14:10
I've come across a few good possible answers to my questions, but this is regarding an upgrade from Hibernate 3.4.0GA to Hibernate 4.1.8. So this used to work under the previous version and I've searched high and low for why its breaking in this new version. I get a org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.test.server.domain.model.NoteItem.note -> com.test.server.domain.model.Note Any help would be great. Here are my classes. @MappedSuperclass public abstract class EntityBase implements

How can I map “insert='false' update='false'” on a composite-id key-property which is also used in a one-to-many FK?

心已入冬 提交于 2019-11-30 07:18:18
问题 I am working on a legacy code base with an existing DB schema. The existing code uses SQL and PL/SQL to execute queries on the DB. We have been tasked with making a small part of the project database-engine agnostic (at first, change everything eventually). We have chosen to use Hibernate 3.3.2.GA and "*.hbm.xml" mapping files (as opposed to annotations). Unfortunately, it is not feasible to change the existing schema because we cannot regress any legacy features. The problem I am

why hibernate creates a join table for unidirectional OneToMany?

人盡茶涼 提交于 2019-11-30 01:43:36
问题 Why hibernate uses a join table for these classes? @Entity public class CompanyImpl { @OneToMany private Set<Flight> flights; @Entity public class Flight { I don't want neither a join table nor a bidirectional association:( 回答1: Because that's how it's designed, and what the JPA spec tells it to map such an association. If you want a join column in the Flight table, use @Entity public class CompanyImpl { @OneToMany @JoinColumn(name = "company_id") private Set<Flight> flights; } This is

How can I map “insert='false' update='false'” on a composite-id key-property which is also used in a one-to-many FK?

不问归期 提交于 2019-11-29 02:48:45
I am working on a legacy code base with an existing DB schema. The existing code uses SQL and PL/SQL to execute queries on the DB. We have been tasked with making a small part of the project database-engine agnostic (at first, change everything eventually). We have chosen to use Hibernate 3.3.2.GA and "*.hbm.xml" mapping files (as opposed to annotations). Unfortunately, it is not feasible to change the existing schema because we cannot regress any legacy features. The problem I am encountering is when I am trying to map a uni-directional, one-to-many relationship where the FK is also part of a

One to many association - Join tables with non primary key column in JPA

时光总嘲笑我的痴心妄想 提交于 2019-11-28 03:33:34
问题 I'm working on legacy system, need to read some of the info from database. Below are the table relationship Vendor (vendorId - pk, vendorEid, name) VendorContactBridge (bridgeId -pk, vendorEid, contactEid) Contact (contactId -pk, contactEid, phone) vendorEid and contactEid are not the primary key of the table but used as join column in Join table VendorContactBridge. Vendor Entity - @Entity @Table(name="Vendor") public class Vendor implements Serializable{ @Id @Column(name="VENDORID") private

inverse=true in JPA annotations

旧城冷巷雨未停 提交于 2019-11-27 04:46:45
In my application I use JPA 2.0 with Hibernate as the persistence provider. I have a one-to-many relationship between two entities (using a @JoinColumn and not @JoinTable ). I wanted to know how could I specify inverse=true (as specified in hbm.xml ) in JPA annotations to reverse the relationship owner. Thank you. I found an answer to this. The mappedBy attribute of @OneToMany annotation behaves the same as inverse = true in the xml file. The attribute mappedBy indicates that the entity in this side is the inverse of the relationship, and the owner resides in the other entity. Other entity

inverse=true in JPA annotations

≡放荡痞女 提交于 2019-11-26 11:20:53
问题 In my application I use JPA 2.0 with Hibernate as the persistence provider. I have a one-to-many relationship between two entities (using a @JoinColumn and not @JoinTable ). I wanted to know how could I specify inverse=true (as specified in hbm.xml ) in JPA annotations to reverse the relationship owner. Thank you. 回答1: I found an answer to this. The mappedBy attribute of @OneToMany annotation behaves the same as inverse = true in the xml file. 回答2: The attribute mappedBy indicates that the