Questions tagged [hibernate-cascade]

87 questions
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
17
votes
2 answers

Can Hibernate delete orphaned collections when updating a detached object?

I know that deleting orphaned child objects is a common question on SO and a common problem for people new to Hibernate, and that the fairly standard answer is to ensure that you have some variation of cascade=all,delete-orphan or…
matt b
  • 138,234
  • 66
  • 282
  • 345
6
votes
1 answer

Difference between JPA Cascade annotations and Hibernate Cascade annotation

I was trying some hands on with Hibernate annotations. When I tried to use Cascading then I get two options in the Eclipse intellisense : javax.persistence.CascadeType and org.hibernate.annotations.CascadeType In hibernate CascadeType, there…
Anand
  • 20,708
  • 48
  • 131
  • 198
6
votes
1 answer

Hibernate merge loses data

I am getting a strange problem with Hibernate and merge. The structure of the classes in question is like this: Project --> CaseWorkerA --|> CaseWorker --|> User So basically I have a Project class, which contains a reference to a CaseWorkerA,…
Tobb
  • 11,850
  • 6
  • 52
  • 77
5
votes
1 answer

Hibernate OnDelete Cascade not working for MySql but Works on postgres and Ms-Sql

I'm having 2 Entities. Thread entity and Post entity using OnetoOne mapping from Post->Thread. A Thread entity contains Numerous Posts. I know i should have used OnetoMany instead of OnetoOne, but for avoiding all the Collections problems i'm using…
Rakz
  • 156
  • 1
  • 3
  • 11
4
votes
1 answer

Why doesn't Hibernate set the child's reference to the parent?

Consider class Parent: { ... @OneToMany(cascade=CascadeType.ALL,mappedBy = "parent") Set children; ... } And class Child: { ... @ManyToOne @JoinColumn(name="parentID") Parent parent; ... } If I create a…
user42768
  • 1,951
  • 11
  • 22
3
votes
2 answers

In Hibernate when using CascadeType.ALL saving top entity causes uneccssary updates to related entities

Have an entity class (Song) with a @OneToMany mapping to another entity (CoverArt), and cascade set to ALL because it seemed easier to just have to save the main entiy and let it take care of persisting the cover art @Audited @Entity public class…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
3
votes
1 answer

Trying to understand difference in CascadeType.ALL vs. @OnDelete!

Let me get my question straight, using the @OnDelete here will delete this and any other InventoryPreference entities if the Inventory entity is deleted? I just can't understand a thing from Hibernate's annotations reference.. so I need your help to…
Rihards
  • 10,241
  • 14
  • 58
  • 78
3
votes
1 answer

Grails many-to-many associations and preventing cascade

So, we have a many-to-many relationship between Customer and Role, set up as: Customer { static hasMany = [roles: Role] } Role { static hasMany = [customer: Customer] static belongsTo = Customer } The Role object has only a name and a set of…
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77
3
votes
0 answers

Cascade soft-delete with @MappedSuperclass in hibernate

I am working on a huge application with a complex database schema. I am using Spring and Hibernate for the development. I wanted to know how to soft-delete an entity(where the active field is there in a superclass rather than having in all the…
Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80
3
votes
2 answers

Unidirectional ManyToOne: Why transient instance saved with CascadeType.ALL but not CascadeType.PERSIST

I am getting org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: safu.Publisher exception when I try to run the following code: public class SafuClient { public…
skip
  • 12,193
  • 32
  • 113
  • 153
3
votes
0 answers

Hibernate generic composite key and cascade saving

I have a problem with writting a generic class for composite keys that I use in my db. All tables that are using composite key have relation ManyToOne and use 2 FK. I have written following class: import java.io.Serializable; import…
jmac
  • 688
  • 3
  • 15
2
votes
1 answer

Hibernate: bidirectional one-to-many foreign key constraint fails

I want to implement a one-to-many relation using Hibernate (in Java). I have two entities: Experiment ExperimentGroup Experiment has many ExperimentGroups. I tried to configure this one-to-many relation, the way the official Hibernate document…
sockeqwe
  • 15,574
  • 24
  • 88
  • 144
2
votes
1 answer

Hibernate @OnDelete cascade same table

I am trying to create a table which captures parent child relationships, like a tree. I would like to maintain only two columns to capture this structure "id" and "parent". I want the database to be able to cascade delete all children when a row is…
2
votes
1 answer

How to setup Hibernate cascade correctly

I have following setup A -> B -> C A-Mapping:
Jeremy S.
  • 6,423
  • 13
  • 48
  • 67
1
2 3 4 5 6