Questions regarding the implementation of one to many relations using Hibernate ORM framework
Questions tagged [hibernate-onetomany]
281 questions
1
vote
1 answer
Hibernate: How do I write the HQL for getting records of an entity without records for its identifying relation
I have Hibernate Objects defined as
Class SomeText{
private Long textId;
private Set Tags = new HashSet();
@ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE })
@JoinTable(name = "text_tag_reln",
joinColumns = {…

Ritesh M Nayak
- 8,001
- 14
- 49
- 78
1
vote
1 answer
Hibernate failed to lazily initialize a collection of role no session in entity service even with @Transactional
I have a hibernate project that connects to two data sources and has a base dao. I use the base dao to derive generic daos for the data sources as well.
I have a service that fetches a join relationship and I am running into the following error when…

Sakib
- 1,503
- 4
- 26
- 39
1
vote
1 answer
Bidirectional @ManyToOne with join table creates duplicate key
I'm implementing a @ManyToOne bidirectional relationship with a join table using hibernate, but when I'm persisting some data, the hibernate claims that the record in relationship table is being inserted twice, violating the unique constraint, as…

marionmaiden
- 3,250
- 8
- 33
- 50
1
vote
3 answers
Hibernate can not correctly operates on multiple bags
I have a model which has 2 oneToMany relation to another 2 model. When i remove 1 record from first bag and save the object, hibernate removes 1 record from 1st bag which is ok but it also removes the record which has same index as the record in…

Omer Temel
- 804
- 1
- 7
- 18
1
vote
2 answers
java.lang.ExceptionInInitializerError and org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:
I've used the Hibernate Reverse engineering to create my models along with its mapping and relationships. However when I try to do a simple select, an error is shown. I don't know what's wrong with my mapping. Here is the code of two models. The…
1
vote
2 answers
HIbernate reverse engineering configuration eager loading
I can't find any solutions on how to configure Hibernate reverse engineering tools (on Eclipse) for defining properties of domain classes fetch = FetchType.EAGER.
PS:By default all foreign keys defining fetch = FetchType.LAZY
For example I define…

vugar_saleh
- 324
- 1
- 10
1
vote
1 answer
CascadeType problem in One to Many Relation
I have two classes which have a Unidirectional One to Many relation with each other.
public class Offer{
...
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name = "Offer_Fields",
joinColumns =
@JoinColumn(name = "OFFER_ID"),
…

Milad.KH
- 11
- 4
1
vote
0 answers
@OneToMany with @JoinFormula using polymorphism and generic
I have the following use case:
Parents contain Children and ParentTags.
Children contain ChildrenTags and their Parent node.
Both ParentTags and ChildrenTags are Tags with T being Parent or Child.
Now I want a derived field in Parent that map all…

Simon
- 31
- 1
- 5
1
vote
1 answer
Hibernate Annotation Mapping Exception in Spring MVC "org.hibernate.PropertyAccessException"
I am new for both Spring MVC and Hibernate. I tried to implement Hibernate annotation based mapping in Spring MVC to add a column into tables Users and Address using @OneToMany bidirectional annotation. But I got the following exception of…

SiVi
- 177
- 1
- 14
1
vote
1 answer
Hibernate: NaturalId with inheritance
I have following Entities (short version):
GroupOfStudents:
@Entity
@Table(name = "group_of_students")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class AGroupOfStudents extends AModel {
}
Centuria:
@Entity
@Table(name =…

jansepke
- 1,933
- 2
- 18
- 30
1
vote
2 answers
Hibernate How to correctly delete children in @OneToMany?
I have a very simple unidirectional @OneToMany from a Parent object to a List of children with CascadeType.ALL. How would I correctly remove and delete one of the children?
Simply calling remove(child) on the List and then…
user1736248
1
vote
3 answers
Hibernate Mapping - connecting table with no @Id
I have three tables, Member, Address and Mem_Addr.
Member and Address entities are mapped / connected by Mem_Addr table. Many to Many.
I have the following entities for Member and Address:
@Entity
@Table (name="Member")
public class Member{
…

Kevin Rave
- 13,876
- 35
- 109
- 173
1
vote
1 answer
Play 2.3.4 Java - JPA oneToMany not saving foreign key. Please check where am going wrong
Here are the entity snippet.......Ignore DaoObject..it just adds autogenerated Id to each entity it subclasses.
I've highlighted which is necessary to persist Content. Eventullally it is not able to add value to contentid column in streams table. It…

Ketan Khairnar
- 1,620
- 3
- 12
- 21
1
vote
1 answer
n+1 query not working
In the below code I expect the n+1 query problem to occur, but it's not happening.
User.java:
import java.util.*;
public class User {
private long userId;
private String firstName;
private Set phones;
public User() {
…

jayendra bhatt
- 1,337
- 2
- 19
- 41
1
vote
1 answer
Hibernate -- cascading on @OneToMany
I have a @OneToMany relationship between
Table1 and Table2 in Hibernate.
Table1 is the owner, and the relationship is one-directional-- i haven't mapped
Table2 back to Table1.
So, as part of this, I defined a Collection of Table2
instances for…

Roam
- 4,831
- 9
- 43
- 72