Questions regarding the implementation of one to many relations using Hibernate ORM framework
Questions tagged [hibernate-onetomany]
281 questions
1
vote
1 answer
How get Null value for child in OneToMany in Spring Boot JPA
I need to get simple List of Parent objects with null values for childs.
But when i use findAll() method and then try to get child object i get
LazyInitializationException: failed to lazily initialize a collection of role: ... could not initialize…

Pavel Verhoturov
- 51
- 1
- 1
- 4
1
vote
2 answers
Named type [com.go_task.entity.User@5b4d25e7] did not implement BasicType nor UserType
I have 2 models. One is the User model and another is the Task model. I'm trying to obtain "one to many" bidirectional relations. But even before doing that when I'm trying to create a user from Test.java class. I'm having an exception.
Named type…

Farhat Shahir
- 174
- 1
- 12
1
vote
1 answer
save an object with childs in Hibernate/JPA - @OneToMany
In Hibernate I want to save an object that has a child.In parent Object I have Set of other classes that are child. The parent hase a @OneToMany relationship with the child.
parent :
@Entity
public class TalentIdentitySetting {
@OneToMany(fetch =…

Mohammad Lami
- 13
- 3
1
vote
2 answers
Unable to create a table in hibernate using OneToMany and ManyToOne relationship(also unable to create Foreign Key)
This code here is simply used to determine the relation of OnetoMany and ManyToOne, I use Spring Tool suite 3.9.11 with XAMPP and Server as apache 7.5
This is first file/table customer.java
package com.bean;
import java.util.List;
import…

Aarsh Shukla
- 13
- 2
1
vote
1 answer
How to use generic types into a super class using a ManyToOne relationship with hibernate
I have one generic class using single table inheritance and other sub classes :
File, the main class
Folder extends File
Card extends File
Abstract FileLink extends File : a FileLink abstract class extending File
FolderLink extends FileLink and is…

kaizokun
- 926
- 3
- 9
- 31
1
vote
1 answer
How to use @ElementCollection for Set mapping?
I have 2 tables. report_id is PK. animals_in_area doesn't have a PK key.
I need to check is an animal_id in the animal_report by given report_id and report_date.
It seems like a simple task, but can I somehow describe a field Set adimalIds…

Diacrome
- 85
- 1
- 1
- 7
1
vote
1 answer
How to tell JPA to manage dependent entities?
My model has a typical parent-children-relation which is JPA-modelled by an unidirectional @OneToMany relation:
a Parent has 0..n instances of Child (i.e. a List).
Trying to create and persist an Entity with one dependent Property as…

Min-Soo Pipefeet
- 2,208
- 4
- 12
- 31
1
vote
0 answers
foreign key of previously saved data is updated as null in spring boot while saving for second time
Developing an application of shopping cart below are my entity classes....
When i save it for the first time user entity is saved properly when same request is used to save user again then previously saved foreign key is becoming null i am using…

Darshan
- 11
- 1
1
vote
1 answer
wiered behavior of OneToMany relationship while using spring boot and spring data jpa
I am developint simple Crud Application in Spring Boot with Data JPA, my goal is simple where I have two Entities: Foo.java
@Data // lombok annotation
@Entity(name = "foos")
public class Foo{
@Id
@GeneratedValue(strategy =…

Logical Error
- 95
- 7
1
vote
1 answer
JPA/Hibernate - delete child removes parent (from same table)
I have a class Comment (see below) with some Comment objects belonging to a parent Comment.
So far, when I delete a parent Comment, the childs are also deleted (as expected), BUT the problem comes when a child is deleted because the parent is also…

txemix
- 45
- 9
1
vote
0 answers
column name and inverse column name in PrimaryKeyJoinColumn
I want to give Column name and inverse column names of my join columns. However I am not sure how can I do it in case of PrimaryKeyJoinColumn. Please help.
Below is the statement for PrimaryKeyJoinColumn
@PrimaryKeyJoinColumn(name =…

Vipin
- 21
- 4
1
vote
0 answers
Spring-Data-Jpa OneToMany query duplicate ids in the info log?
I don't understand why the ids are duplicated (id_msg, id_pers_acct), that's what's in my Springboot log :
select personneco0_.id_pers_acct as id_pers_1_2_0_,
…
from test.person_account personacc0_ where personacc0_.id_pers_acct=?
select…

L.G
- 1,458
- 4
- 14
- 24
1
vote
1 answer
Spring JPA : Update entity with updated child entities
DB Used : Postgres with Spring jpa
I have a Main Entity which has structure as follows :
Parent (CascadeType.All for childs)
-->Child 1 (Join column with parent here)
-->Child 2 (Join column with parent here)
-->Child 3 (Join column with parent…

Rohan Lopes
- 165
- 7
- 18
1
vote
3 answers
Hibernate Persist Unidirectional One To Many Relationship
I have the following model:
The corresponding mapping is as follows:
Quote entity
@Entity
@Table(name="Quote")
@Getter
@Setter
public class Quote {
@Id
@GeneratedValue(strategy= GenerationType.AUTO, generator="native")
…

AlejoDev
- 4,345
- 9
- 36
- 67
1
vote
1 answer
Get input from postman using one to many relation mapping? spring java
I have created two entity's. One is User and other is Location. It has one to many relation i.e one user will have multiple locations.
I am able to create the user. Now I want to create a location under some user.
I mapped both entity's by oneToMany…

Sid
- 2,792
- 9
- 55
- 111