Questions regarding the implementation of one to many relations using Hibernate ORM framework
Questions tagged [hibernate-onetomany]
281 questions
54
votes
2 answers
How can I map "insert='false' update='false'" on a composite-id key-property which is also used in a one-to-many FK?
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…

Jesse Webb
- 43,135
- 27
- 106
- 143
28
votes
9 answers
Hibernate @OneToMany Relationship Causes Infinite Loop Or Empty Entries in JSON Result
I have two entities, an entity "movie" and an entity "Clip"
each clip belongs to one movie and a movie can have multiple clips.
My code looks like:
Movie.java
@OneToMany(mappedBy = "movie", targetEntity = Clip.class, cascade = CascadeType.ALL,…

Lama
- 2,886
- 6
- 43
- 59
27
votes
3 answers
inverse=true in JPA annotations
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)…

Andy Dufresne
- 6,022
- 7
- 63
- 113
22
votes
2 answers
TransientObjectException - object references an unsaved transient instance - save the transient instance before flushing
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…

Derek Perriero
- 232
- 1
- 2
- 9
21
votes
3 answers
why hibernate creates a join table for unidirectional OneToMany?
Why hibernate uses a join table for these classes?
@Entity
public class CompanyImpl {
@OneToMany
private Set flights;
@Entity
public class Flight {
I don't want neither a join table nor a bidirectional association:(

morteza khosravi
- 1,599
- 1
- 20
- 36
12
votes
2 answers
One to many association - Join tables with non primary key column in JPA
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,…

Pankaj
- 3,512
- 16
- 49
- 83
10
votes
4 answers
Don't change the reference to a collection with cascade="all-delete-orphan"
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…

user2599052
- 1,056
- 3
- 12
- 27
6
votes
3 answers
Hibernate Many-to-Many with join-class Cascading issue
I have a Many-to-Many relationship between the class Foo and Bar. Because I want to have additional information on the helper table, I had to make a helper class FooBar as explained here: The best way to map a many-to-many association with extra…

kscherrer
- 5,486
- 2
- 19
- 59
5
votes
3 answers
Hibernate retrieve null for OneToMany collection
My problem is that hibernate retrieve null in the value of the @OneToMany Set organizationMemberCollection when fetching an instance on the following object :
UserAccount.java :
@Entity
@Table(name="USER_ACCOUNT")
public class UserAccount {
…

Tom
- 375
- 1
- 4
- 13
5
votes
1 answer
How to avoid Hibernate generating two queries for an update with OneToMany?
I'm facing the same situation as in this question, that has no useful answer.
When I add a new element to the many part of my one-to-many relation, Hibernate generates two queries, one to insert and one to update the foreign key to the parent.
Why…

mark951131b
- 475
- 5
- 13
5
votes
2 answers
saveorupdate() does not update collection (list) one-to-many mapping in hibernate
class Student
public class Student {
private Long id;
private String name;
private String className;
private List phones;
// getter setter
}
class Phone
public class Phone {
private Long id;
private String number;
//getter…

gursahib.singh.sahni
- 1,559
- 3
- 26
- 51
5
votes
1 answer
Hibernate paginated OneToMany relationship
how can I map a one-to-many relationship in Hibernate where the many-side needs to be paginated? (i.e. you have hundreds or more related objects)
Using the OneToMany annotation (or its xml equivalent) is not useful because loading the one-side…

user1607194
- 51
- 2
4
votes
4 answers
@OneToMany Bidirectional - Join Column is inserting "null" value (Hibernate)
I have 2 model/annotated classes, ProductDetails and VnfDetails.
I want to join the 2 tables with @OnetoMany relation using JPA HIbernate
ProductDetails model class is below with @OnetoMany Mapping:
@Entity
@Table(name="product_details")
public…

Tushar
- 67
- 1
- 8
4
votes
2 answers
Hibernate "Provided id of the wrong type expected Long, got class DelayedPostInsertIdentifier" exception
In short:
When I try to add New(Unsaved) Entities to one-to-many set of the saved parent, after calling Merge on the Parent entity, I get the following exception:
Provided id of the wrong type for class com.test.Child. Expected:
class…

Dmitrii Semenov
- 315
- 4
- 16
4
votes
1 answer
JPA native query result returns duplicate child objects
I have a parent table and a child Table in my DB, and have a OneToMany mapping for them in their corresponding entity classes. The child table has a foreign key parent_id. I am using JPA 2 with Hibernate and MySQL DB.
I wish to retrieve all the…

dumbcoder
- 41
- 1
- 4