Questions tagged [one-to-many]

one-to-many is relationship between two different object properties.

One object property is relating with many properties of other object. Or you can say one object relating to many objects.

In sql, a one-to-many relationship, each row in the related to table can be related to many rows in the relating table.

http://en.wikipedia.org/wiki/One-to-many

3715 questions
54
votes
2 answers

JPA OneToMany and ManyToOne throw: Repeated column in mapping for entity column (should be mapped with insert="false" update="false")

I have three classes one of the names is User and this user has other classes instances. Like this; public class User{ @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL) public List aPosts; …
Ömer Faruk AK
  • 2,409
  • 5
  • 26
  • 47
53
votes
4 answers

Saving related records in laravel

I have users, and users belong to a dealership. Upon user registration, I'm trying to save a new user, and a new dealership. User database has a dealership_id column, which I want to be populated with the ID of the newly created dealership. This…
BeardedInBinary
  • 705
  • 1
  • 8
  • 15
50
votes
6 answers

Synchronizing a one-to-many relationship in Laravel

If I have a many-to-many relationship it's super easy to update the relationship with its sync method. But what would I use to synchronize a one-to-many relationship? table posts: id, name table links: id, name, post_id Here, each Post can have…
user2834172
  • 861
  • 1
  • 9
  • 17
48
votes
3 answers

@OneToMany without inverse relationship and without a join table?

This is a similar problem to "Hibernate @OneToMany without a separate join table", in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to…
jsight
  • 27,819
  • 25
  • 107
  • 140
45
votes
5 answers

JPA @OneToMany -> Parent - Child Reference (Foreign Key)

i have a Question about referencing ParentEntities from Child Entites ir If i have something like this: Parent.java: @Entity(name ="Parent") public class Parent { @Id @Generate..... @Column private int id; @OneToMany(cascade…
Sim0rn
  • 632
  • 1
  • 6
  • 9
39
votes
1 answer

Hibernate @OneToMany remove child from list when updating parent

I have the following entities: TEAM @Entity @Table public class Team { [..] private Set userTeamRoles; /** * @return the userTeamRoles */ @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "team", fetch = FetchType.LAZY) public…
AndaP
  • 1,308
  • 8
  • 23
  • 40
37
votes
3 answers

Spring 3 MVC: one-to-many within a dynamic form (add/remove on create/update)

I'm looking for a solution to manage a one-to-many relation within an HTML form using jQuery. I'm developing with Spring, Spring MVC and Hibernate. I found many tracks on the web, but not any working full-example. The background I've three JPA…
sp00m
  • 47,968
  • 31
  • 142
  • 252
37
votes
9 answers

@OneToMany and composite primary keys?

I'm using Hibernate with annotations (in spring), and I have an object which has an ordered, many-to-one relationship which a child object which has a composite primary key, one component of which is a foreign key back to the id of the parent…
Kris Pruden
  • 3,280
  • 4
  • 25
  • 30
34
votes
4 answers

How to create a one-to-many relationship with JDBI SQL object API?

I'm creating a simple REST application with dropwizard using JDBI. The next step is to integrate a new resource that has a one-to-many relationship with another one. Until now I couldn't figure out how to create a method in my DAO that retrieves a…
Tilman
  • 925
  • 1
  • 8
  • 18
33
votes
2 answers

Hibernate unidirectional one to many association - why is a join table better?

In this document (scroll down to the Unidirectional section): http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections it says that a unidirectional one-to-many association with a join table…
UrLicht
  • 939
  • 1
  • 14
  • 25
32
votes
7 answers

Laravel - Form Input - Multiple select for a one to many relationship

One of the requirements in an application that I am building is for a form input which takes in a varying number of items for a single field. For instance, sports that I play are ('Soccer','Tennis','Croquet'). There are a finite number of sports one…
datavoredan
  • 3,536
  • 9
  • 32
  • 48
31
votes
2 answers

@OneToMany mappedBy maps to _____

What does mappedBy map to? Or, rather, what should it map to? The headers field below maps to @Entity Foo as per @OneToMany docs? And then Foo would be a wrapper for javax.mail.Header? package net.bounceme.dur.usenet.model; import…
Thufir
  • 8,216
  • 28
  • 125
  • 273
30
votes
4 answers

JPA one-to-many filtering

We are nesting several entities. However upon retrieving we only want to get those entities which are active. @Entity public class System { @Id @Column(name = "ID") private Integer id; @OneToMany(mappedBy = "system") private…
Udo Held
  • 12,314
  • 11
  • 67
  • 93
28
votes
5 answers

Hibernate: OneToMany save children by cascade

In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try…
Steve Eastwood
  • 1,783
  • 3
  • 16
  • 21
28
votes
3 answers

On delete set null in hibernate in @OneToMany

I have a Department entity which relations are as follows: Many departments can be in one parent department: @ManyToOne @JoinColumn(name = "ik_parent_department_id") private Department parentDepartment; One parent department can have many…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498