Questions regarding the implementation of one to many relations using Hibernate ORM framework
Questions tagged [hibernate-onetomany]
281 questions
0
votes
1 answer
Using hibernate criteria in one to many mapping (Search header table with line table column as one of search criteria)
I have two classes InvoiceHeader and InvoiceLine with a one to many (One InvoiceHeader maps to multiple InvoiceLine) mapping between them.
class InvoiceHeader
{
private int id;
private String title;
private Set invoiceLines;…

vishnu pratap singh
- 81
- 2
- 7
0
votes
1 answer
Should I update bidirectional relation also in Java?
Suppose I have User and Group entities and wish them to have 1 to many relationship between. I.e. each User belongs to one Group, while any Group can contain many Users.
Group entity:
@Entity
@Table(name="GroupTable")
public class Group {
@Id
…

Suzan Cioc
- 29,281
- 63
- 213
- 385
0
votes
2 answers
Cannot delete child in one-to-many relationship
When I put inverse=true into set, nothing gets deleted. When I don't, and I remove MealIngredient from set, then Hibernate tries to set null, it fails and exception is thrown:
[SQLITE_CONSTRAINT] Abort due to constraint violation…

mnn
- 1,952
- 4
- 28
- 51
0
votes
1 answer
@OneToMany relationship with non primary key Hibernate
I have one @Entity called Team as
@Entity
@Table(name="projects_participants")
public class Team {
@Id`enter code here`
@GeneratedValue(strategy = GenerationType.AUTO)
@Column
private int id;
…

Milople Inc
- 399
- 1
- 8
- 34
0
votes
2 answers
Rather than child is deleting its updating ,when parent is deleted
My problem is when i delete the parent, child is not deleted but instead of deleting child ,child is updating.Parent table is Employee and child table is EmployeeProject there is one-to-many relation ship exist between employee and project one…

henrycharles
- 1,019
- 6
- 28
- 66
0
votes
2 answers
Hibernate: Child table having two different ManyToOne relationships
In the Spring/Hibernate/Java/Tomcat app I'm writing I have a OneToMany relationship between an Organization and its Contacts.
Organization 1:M Contact (has foreign key org_id)
In Organization I have this…

Jerome P Mrozak
- 1,907
- 4
- 21
- 33
0
votes
0 answers
Hibernate MappingException converting to ElementCollection
I am having a problem refactoring my code to use the JPA ElementCollection instead of the deprecated CollectionOfElements.
I am seeing the following stack trace:
org.hibernate.MappingException: Could not determine type for: java.util.Set, at table:…

PeterD
- 51
- 1
- 4
0
votes
0 answers
Hibernate maxResults with OneToMany Fetch counts children as result rows
I have a class Video that has a OneToMany annotation to another class Comment.
@OneToMany(fetch = FetchType.LAZY, mappedBy = "videoId", cascade = CascadeType.ALL, orphanRemoval = true)
@Sort(type = SortType.COMPARATOR, comparator =…

tumanov
- 539
- 1
- 7
- 14
0
votes
2 answers
NHibernate CreateCriteria with Restrictions does not work as expected
The bellow given code sample is to retrieve all the active records.
session.CreateCriteria()
.CreateAlias("BasicInfo", "bsInfo")
.CreateAlias("DimentionInfo", "diInfo")
…

Desmond
- 1,308
- 1
- 19
- 27
0
votes
2 answers
hibernate jpa join two table with another table
I have two table A and B
Table A:
ID_A
name
table B
ID_B
name
I joined both by a third table C table with their primary key
table C
ID_C
ID_A
ID_B
I'd like to know this relationship in jpa mapping to retrieve the list of object B inside object…

user820688
- 719
- 2
- 13
- 27
0
votes
1 answer
Unable to persist OneToMany relationship in HIbernate 4
Having a problem getting some data persisted with hibernate
I declare two independent classes, License and MacAddress. MacAddress can exist in its own right, but it can also be linked to to a license, when hibernate generates the underlying tables…

Paul Taylor
- 13,411
- 42
- 184
- 351
0
votes
1 answer
Am I need to use @Access=FIELD annotation with many-to-one relationship?
I have entities which are divided into categories. Each entity can belong to many categories, so I have one to many association.
Is it ORM-ed correctly below:
@OneToMany
@Access(AccessType.FIELD)
private Set parents = new…

Suzan Cioc
- 29,281
- 63
- 213
- 385
0
votes
1 answer
Spring callback when Entity exits @Transactional context?
Does Spring have any hooks to call a method on an entity or an entity listener for each entity at the exit of a transactional context?
We're using Spring and Hibernate to manage a bunch of entities that we also index for searching. We currently use…

Brandon
- 2,367
- 26
- 32
0
votes
1 answer
Issue while updating @OneToMany collection
I am stuck at a point where i am trying to update a @OneToMany mapping.
Problem:
I have 2 entities: Criteria and Tasks. A criteria can contain multiple tasks.
class Criteria {
@OneToMany(mappedBy = "criteria", cascade = { CascadeType.PERSIST,
…

Rakesh Sinha
- 19
- 1
- 6
0
votes
2 answers
Hibernate: new or old record
I have a OneToMany connection between tables Result and ResultAux. I can retrieve a set of ResultAux objects from Result. After that I'm adding some ResultAux objects to set and using merge on each set entry to flush changes into database. Like…

Aleksandr Kravets
- 5,750
- 7
- 53
- 72