CascadeType « Delete « JPA Q&A





1. JPA CascadeType.ALL does not delete orphans    stackoverflow.com

I am having trouble deleting orphan nodes using JPA with the following mapping

@OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner")
private List<Bikes> bikes;
I am having the issue of the orphaned ...

2. Hibernate CascadeType.PERSIST and DELETE_ORPHAN    coderanch.com

Hello, When i use these settings everything works fine : @OneToMany(mappedBy="user",fetch=FetchType.EAGER,cascade = {CascadeType.PERSIST,CascadeType.MERGE}) @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN}) but when i delete the CascadeType.PERSIST and for example delete a member of my Collection it doesn't update the Database anymore when i synchronize it with merge. I don't understand this why do i have to set PERSIST too, that DELETE_ORPHAN works correctly? thanks for your help ...

3. org.hibernate.annotations.CascadeType.DELETE_ORPHAN    coderanch.com

rani vini wrote:I know that what is "CascadeType.DELETE_ORPHAN" -- if a child is dereferenced by a persistent parent and if DELETE_ORPHAN is used, the "orphaned" child is deleted. But I want to know the real time scenario, where this will be useful. Can anyone explain with small example code? Thanks in advance. Order Header to Order Details. I have an order ...

4. Database ON DELETE/UPDATE CASCADE to CascadeType.?    forum.hibernate.org

Hello, I'm not talking about generating DDL or anything. I just want to find out what the JPA/Hibernate equivalents of ON DELETE CASCADE and ON UPDATE CASCADE are in terms of the CascadeType's REMOVE, PERSIST, MERGE, and REFRESH (if translatable at all). Is it: ON DELETE CASCADE -> CascadeType.REMOVE and ON UPDATE CASCADE -> {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH} Note I'm relatively new ...

5. CascadeType.DELETE    forum.hibernate.org

Lets say in an entity you have a field thats another entity. Basically a join. In the entity if you supply cascade=CascadeType.DELETE implying that deletes will be cascaded which under some scenarios may be a good idea in some cases if used carefully. The same thing can also be done at the database level itself. When defining the Foreign key one ...

6. Custom Hibernate CascadeType.DELETE    forum.hibernate.org

Hello, I am interested is there any way to perform custom DELETE in Hibernate. Here is situation: I defined many-to-many relation between Album and Artist, so Album can have ONE or MANY Artists and Artist can have ONE or MANY Albums. Here is mapping in Artist: @ManyToMany(targetEntity=Album.class, fetch=FetchType.LAZY) @Cascade({ org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE }) @JoinTable(name="album_artist", joinColumns={@JoinColumn(name="ArtistID")}, inverseJoinColumns={@JoinColumn(name="AlbumID")}) private Set albums = new HashSet(); ...

7. CascadeType.ALL and DELETE_ORPHAN doesnt work    forum.hibernate.org

I have the following one to many bidirectional relationship defined. @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "journal") @Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @OrderBy(value = "sequence") public List getJournalLines() { return this.journalLines; } If i execute the following: beginTransaction(); Journal found = DAOFactory.DEFAULT.getJournalDAO().findById(new Long(187007),false); found.getJournalLines().clear(); found.setJournalStatus(JournalStatus.DELTED); endTransaction(); It fails with: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping ...

8. HELP! -> CascadeType.DELETE_ORPHAN -> BatchUpdateExcep    forum.hibernate.org

I am getting a problem when removing an item from a OneToMany list. I can add users without any problem but cannot remove them. I am basically, removing a user from the list and doing saveOrUpdate(account). My AccountDO has a list of UserDO as follows @OneToMany(mappedBy = "account", cascade = CascadeType.ALL) @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) public List getUsers() { return ...

9. CascadeType.ALL does not work when deleting    forum.hibernate.org

@Entity @Table(name="edges") @SequenceGenerator(name="SEQ_EDGE", sequenceName="edges_id_seq") public class Edge extends EWorldElement implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_EDGE") private int id; @OneToMany(fetch=FetchType.EAGER) @JoinColumn(name="edge") @Cascade({org.hibernate.annotations.CascadeType.ALL}) @IndexColumn(name = "indexinlist", base=0) private List lanes; [...] ...





10. Problem with CascadeType.DELETE_ORPHAN annotation    forum.hibernate.org

Hello!! I'm using Hibernate 3 with annotations and I use it with Spring's Hibernate Template. Here are two classes I use: public class Car{ ... } public class Driver{ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="driver") @Cascade(value=CascadeType.DELETE_ORPHAN) @JoinColumn(name = "driver_id") protected List cars; } Well, I've omitted some code, that doesn't have to do with my problem (as far as I ...

11. CascadeType.REMOVE => ON DELETE NO ACTION?    forum.hibernate.org

I'm using Hibernate, JPA, and Postgres. In my entity class ProductLocale, I have a @ManyToOne(cascade = cascadeType.REMOVE) private Locale locale; I have no OneToMany relationships define in my Locale entity class. Why does the locale column foreign key in my product_locales table get created with "ON DELETE NO ACTION"? I want this record being deleted when this id gets removed from ...