openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Himadri <>
Subject How to specifiy Cascase None for OneToMany
Date Wed, 20 Jan 2010 12:00:47 GMT


My application is an EJb3.0 running on WL10.3

My requirement is that in OneToMany Relationship , if the <One> Entity is
deleted , <Many> Entity should not be deleted and should be set to null .
When I try to delete One , I get integrity constraint violation exception.

I used to get the same behaviour with ManyToMany relations and I had the
same requirement i.e do not delete the other association end. I solved that
problem by not specifying any cascade which is equivalent to CascadeType =
None . @ManyToMany(targetEntity=Image.class ,fetch=FetchType.LAZY)

But this trick is not working for @OneToMany. How to do i tell Open JPA that
do not delete the association end, Just set the child records to null and
delete this entity ? 

This is my code  for OneToMany (Campaign to CampaignTarget

@OneToMany(targetEntity=CampaignTarget.class, mappedBy = "campaign",

@ManyToOne(targetEntity=Campaign.class,  fetch = FetchType.LAZY)

One of the solution provided on Google is to 
"If we try to delete a parent record without deleting the child records, we
must set the foreign-key field for all children to NULL before removing the
parent. "

Why should I do this extra <set null > when I have set cascade to none ? It
worked with manytomany .. Is this the only appropiate solution available to
handle such problem ?

Thanks !

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message