Questions tagged [hibernate-cascade]
87 questions
1
vote
2 answers
Using composite identifiers @EmbeddedId with @OneToOne
My example below is for learning purpose. The goal is to create some examples using the Composite identifiers. Unfortunately, I'm getting some strange results.
Entities: Course, Teacher, CoursePk.
Each course should be given by only one Teacher.
I'm…

xmen-5
- 1,806
- 1
- 23
- 44
1
vote
0 answers
Getting constraint violation exception on deleting parent although i used cascadeType.all
As per my requirement I have two entities company and contact which are associated with @onetomany mapping and I want to delete the company and its related contacts with it.
I have used the Cascade.All but still I am getting the constraint violation…

user3852293
- 11
- 3
1
vote
1 answer
Hibernate TransientObjectException on OneToMany with CascadeType.ALL if we call iterator() before save
I have OneToMany Relation in hibernate like below:
class Container {
@OneToMany( cascade = {CascadeType.ALL}, mappedBy = "container", orphanRemoval = true)
List- items;
}
the simplified scenario is that I load a Container object…

Hossein Nasr
- 1,436
- 2
- 20
- 40
1
vote
1 answer
Cascade within @EmbeddedId in hibernate
I'm adding an intersection table with additional data and I use @EmbeddedId to make a complex ID for the entities which are bound by the record in this table(entity1 and entity2).
I want to save all the data via cascade when I save entity 1. So,…

dvelopp
- 4,095
- 3
- 31
- 57
1
vote
1 answer
nhibernate (or hibernate) Conditional cascading
I have a class User, that has a property Event, which has many Sessions. Basically, a user register to an event which have many sessions hours.
The user can register for an event, but the sessions hours are purely informative.
But when I write a…

Sebastien F.
- 1,613
- 2
- 23
- 40
1
vote
1 answer
Hibernate 5 + JPA 2 doesn't cascade delete over join table
We have this relationship:
public class RuleProviderEntity implements Serializable
{
...
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@OrderColumn(name = RuleEntity.RULE_SEQUENCE)
private List…

Ondra Žižka
- 43,948
- 41
- 217
- 277
1
vote
1 answer
Generate entities with cascade delete
I am generating entities for our large database via JBoss hibernate reverse engineering. I was hoping to see cascade annotations in entities, but did not see them on generation.
Is there a way to direct hibernate to consider foreign keys and…

nikel
- 3,402
- 11
- 45
- 71
1
vote
1 answer
Cascade is not working in Hibernate One-to-One mapping
Person.java
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import…

Ravi Nain
- 605
- 8
- 16
1
vote
1 answer
hibernate child table records are not getting deleted
I am having two tables with parent child relationship as below:
Parent Table:
@Entity
@Table(name = "frontend.rdp_strategy", uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "datatype","source"})})
public class FrontRdpStrategy…

Ajitkumar Patil
- 79
- 1
- 8
1
vote
0 answers
How can I save the Entity what have a Entity List When Entity List is Null
It's my first question.
I hope I can get any hint here to solve my problem.
I use the hibernate for my application.
Here is my Code.
public class A {
@OneToMany(mappedBy = "a", cascade = {CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval =…

Jin
- 57
- 1
- 6
1
vote
0 answers
Hibernate: Update children when updating parent
I have a problem in Hibernate when updating an object which contains a collection of another object. Here's what it looks like:
@Entity
@Table(name = "Garage")
public class Garage {
@OneToMany(targetEntity = Car.class, cascade = CascadeType.ALL,…

Richard Silvertass
- 301
- 4
- 20
1
vote
1 answer
JPA and Hibernate persisting @manytoOne relationship
I have this situation:
@Entity
@Table(name = "project_leader")
public class ProjectLeader {
@ManyToOne
@JoinColumn(name = "projectId")
@JsonBackReference(value = "project")
private Project project;
...
and related entity
@Entity
@Table(name =…

Aleksandar
- 119
- 2
- 13
1
vote
1 answer
hibernate - cascading type persist for many to many relationship
I have two classes Policy and Acl. They have a ManyToMany relationship in them.
// Policy
public class PolicyEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "POLICY_ID")
private int policyId;
…

sensitive_piece_of_horseflesh
- 909
- 4
- 16
- 40
1
vote
1 answer
Cannot delete detached child from collection in parent in Hibernate
I have the following entities with a parent-child relationship:
public class Parent {
@Id @GeneratedValue String id;
@Version Long version;
@OneToMany(mappedBy = "parent", orphanRemoval = true)
@Cascade({CascadeType.ALL})
Set…

restassured
- 1,008
- 2
- 9
- 12
1
vote
1 answer
Hibernate One to Many add new children
I have read a lot of articles and answers on similar questions, but i still can not understand.
Here my parent class:
@Entity
@Table(name = "users")
public class User implements Serializable, Annotation {
@Id
@GeneratedValue(generator =…

dikkini
- 1,184
- 1
- 23
- 52