Questions tagged [hibernate-onetomany]

Questions regarding the implementation of one to many relations using Hibernate ORM framework

248 questions
47
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
  • 36,395
  • 25
  • 99
  • 138
24
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
  • 5,424
  • 7
  • 53
  • 86
23
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,…
Goot
  • 2,599
  • 5
  • 36
  • 56
20
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
  • 213
  • 1
  • 2
  • 8
15
votes
2 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,445
  • 17
  • 33
10
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,062
  • 13
  • 42
  • 78
8
votes
3 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
  • 753
  • 1
  • 8
  • 19
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
  • 4,952
  • 2
  • 12
  • 50
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
  • 435
  • 5
  • 12
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…
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…
4
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
  • 345
  • 4
  • 13
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
  • 305
  • 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…
4
votes
2 answers

org.hibernate.AssertionFailure: null identifier with OneToMany/ManyToOne Relationship

I have a problem with a OneToMany/ManyToOne relationship: Class Project: @OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL, orphanRemoval=true ) @JoinColumn(name="PROJECT_ID", nullable=true) private Set personlist = new…
1
2 3
16 17