2

I have the following two entities:

1- Deal

@OneToMany(cascade=CascadeType.ALL,mappedBy = "deal", fetch = FetchType.EAGER)
@Fetch( FetchMode.SELECT)
private List<DealCheckList> dealCheckList;

2- DealCheckList

@JoinColumn(name = "DEAL_ID", referencedColumnName = "DEAL_ID", insertable = false, updatable = false)
@ManyToOne(fetch = FetchType.LAZY)  
private Deal deal;

While deleting child object i.e. DealCheckList using

.......
.......  
transaction = session.beginTransaction();

Deal deal = (Deal) session.createCriteria(Deal.class)
                          .add(Restrictions.eq("dealId",  dealId)).uniqueResult();         

for(DealCheckList checklist : deal.getDealCheckList()){                        
            session.delete(checklist);
 }
transaction.commit();

I am getting the below error

Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations):

Please help.

Anand
  • 20,708
  • 48
  • 131
  • 198

1 Answers1

1

You need to remove the checklist object from the dealCheckList. Your list of DealCheckList has "cascade all" , so if it has an object in it will automatically be save it.

The error message is pretty clear "remove deleted object from associations"

Stéphane
  • 867
  • 4
  • 7