Questions tagged [many-to-one]
1040 questions
304
votes
6 answers
What is the meaning of the CascadeType.ALL for a @ManyToOne JPA association
I think I misunderstood the meaning of cascading in the context of a @ManyToOne relationship.
The case:
public class User {
@OneToMany(fetch = FetchType.EAGER)
protected Set userAddresses;
}
public class Address {
…

forhas
- 11,551
- 21
- 77
- 111
161
votes
15 answers
Difference between one-to-many and many-to-one relationship
What is the real difference between one-to-many and many-to-one relationship? It is only reversed, kind of?
I can't find any 'good-and-easy-to-understand' tutorial about this topic other than this one: SQL for Beginners: Part 3 - Database…

Zhaf
- 1,804
- 5
- 19
- 16
126
votes
7 answers
JPA: unidirectional many-to-one and cascading delete
Say I have a unidirectional @ManyToOne relationship like the following:
@Entity
public class Parent implements Serializable {
@Id
@GeneratedValue
private long id;
}
@Entity
public class Child implements Serializable {
@Id
…

perp
- 3,883
- 4
- 31
- 29
76
votes
4 answers
Hibernate/JPA ManyToOne vs OneToMany
I am reading currently the documentation of Hibernate regarding the entity associations and I come accross a little difficulty to figure out some things. It has to do in essence with the difference between ManyToOne and OneToMany associations.…

arjacsoh
- 8,932
- 28
- 106
- 166
58
votes
3 answers
Doctrine 2 - Disallow null value on foreign keys of ManyToOne relationships
I have a ManyToOne relationship in one of my entities, like so:
class License {
// ...
/**
* Customer who owns the license
*
* @var \ISE\LicenseManagerBundle\Entity\Customer
* @ORM\ManyToOne(targetEntity="Customer",…

Tobias Gies
- 724
- 1
- 6
- 15
57
votes
8 answers
JPA many-to-one relation - need to save only Id
I have 2 classes: Driver and Car. Cars table updated in separate process. What I need is to have property in Driver that allows me to read full car description and write only Id pointing to existing Car. Here is example:
@Entity(name =…

Andrei V
- 1,468
- 3
- 17
- 32
55
votes
4 answers
Hibernate ManyToOne vs OneToOne
I can't see any difference in the schema of a Many-To-One relationship vs a OneToOne relationship:
@Entity
public class Order {
@ManyToOne
@JoinColumn(nullable = false)
private Address address;
vs
@Entity
public class Order {
…

DD.
- 21,498
- 52
- 157
- 246
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
32
votes
3 answers
Can a @ManyToOne JPA relation be null?
I have a table that has foreign key of another table (many to one relationship) but i want it to be nullable.
Something like this:
public class SubType() {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name =…

Narges
- 1,345
- 6
- 14
- 29
24
votes
4 answers
Cannot make @ManyToOne relationship nullable
I have a many-to-one relationship that I want to be nullable:
@ManyToOne(optional = true)
@JoinColumn(name = "customer_id", nullable = true)
private Customer customer;
Unfortunately, JPA keeps setting the column in my database as NOT NULL. Can…

vcattin
- 687
- 1
- 4
- 15
23
votes
9 answers
IllegalStateException with Hibernate 4 and ManyToOne cascading
I've got those two classes
MyItem Object:
@Entity
public class MyItem implements Serializable {
@Id
private Integer id;
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private Component defaultComponent;
…

Clayton Louden
- 1,056
- 2
- 11
- 28
21
votes
6 answers
How to save parent and child in one shot (JPA & Hibernate)
I start showing you my scenario.
This is my parent object:
@Entity
@Table(name="cart")
public class Cart implements Serializable{
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
@Column(name="id")
private Integer id;
…

MDP
- 4,177
- 21
- 63
- 119
21
votes
2 answers
django difference between - one to one, many to one and many to many
So, this is my first time learning computer language. And I chose python and django. Now, I got many of the basic concepts of python and also django. I can create new page with the views and all other stuff. But I am still confused with the…

Aamu
- 3,431
- 7
- 39
- 61
20
votes
3 answers
How does hibernate save one-to-many / many-to-one annotations? (Children not saving)
I've inherited a hibernate application and I've run into issues. It seems that the code does not save the child in a One-To-Many relationship. It's bidirectional, but on save of parent object, it doesn't seem to save the child.
The Question class…
user1732480
19
votes
4 answers
Many-to-one mapping (creating equivalence classes)
I have a project of converting one database to another. One of the original database columns defines the row's category. This column should be mapped to a new category in the new database.
For example, let's assume the original categories…

Adam Matan
- 128,757
- 147
- 397
- 562