Deleting parent entity of oneToMany does not delete children first,

I have two entities related with a bi-rdirectional OneToMany relationship. When I delete the parent, I want eclipseLink to automatically delete the child entities first before deleting the parent entity. I have implemented what I understand all the documents are telling me I should implement, but I can not get it working.
When I try and delete the parent I get an SQLException as the foreign key constraint has been violated as there are child records for the parent I am trying to delete. It was my understanding, that if you have all the annotations correct on my Entities, then all i have to do is delete the parent and eclipseLink will delete the children first and therefore i should never get the SQL exception.
Here is some snippets of my code.
Entities
@Entity(name = "PARENTS")
public class ParentEntity {
     @Id
     @Column(name = "PARENT_ID", nullable = false)
     private String parentID;
     @Column(name = "DISPLAY_NAME", nullable = false)
     private String displayName;
     @OneToMany(mappedBy="parent", orphanRemoval=true, cascade=CascadeType.ALL)
     private Collection<ChildEntity> childEntities;     
@Entity(name = "CHILDREN")
@IdClass(ChildIdentifier.class)
public class ChildEntity {
     @Id
     @Column(name="ITEM_ID", nullable=false)
     private String itemID;
     @Id
     @ManyToOne()
     @JoinColumn(name="PARENT_ID", nullable=false)
     private ParentEntity parent;
public class ChildIdentifier implements Serializable {
     private String itemID;
private String parent;
Tables created from these entities
PARENTS
Name Null? Type
PARENT_ID NOT NULL VARCHAR2(36)
DISPLAY_NAME NOT NULL VARCHAR2(255)
PrimaryKey = PARENT_ID
CHILDREN
Name Null? Type
ITEM_ID NOT NULL VARCHAR2(36)
PARENT_ID NOT NULL VARCHAR2(255)
PrimaryKey = ITEM_ID,PARENT_ID
ForeignKey = PARENTID = PARENTS.PARENT_ID
Code to delete a parent
     public void deleteParent(String id)
          ParentEntity e= em.find(ParentEntity .class, id);
          if (e!= null)
               em.remove(e);
Exception seen
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120119-r10715): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (MYSCHEMA.CHILDREN_FK_P_PARENTS) violated - child record found
Error Code: 2292
Call: DELETE FROM PARENTS WHERE (PARENT_ID = ?)
I have added eclipse logging entries in my persistence.xml to try and see what is going on
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
And in my jdev console when running my test, i do not see any queries of CHILDREN before it tries to delete from PARENTS.
Am I missing something really obvious?
Thanks in advance.
Edited by: smaslin on Feb 20, 2012 9:20 AM
Edited by: smaslin on Feb 21, 2012 5:26 AM

"optional=false" only affects DDL generation, not runtime JPA behavior. PrivateOwned is similar to orphanRemoval in that it should cause the removal of child entities when they are dereferenced from the parent (ie remove them from the parent's collection). Cascade remove or cascade all should be all you need, but PrivateOwned+orphanRemoval should still cause the collection to be removed, as long as there are entities within the Parent's list of children to remove.
The only case where I can see this not occuring is if you have not been maintaining the bidirectional relationship. That is, if you have added Child entities and set a parent, but not updated the Parent's collection of children to reflect that change. A simple test is to refresh the parent before removal - call em.refresh(e); right before the em.remove(e);. If this works, then you will need to change your application so that when you add parents to a child you also add the child to the parent's list of children - JPA does not maintain relationships for you and not doing so will keep the cache inconsistent with what is in the database.
Best Regards,
Chris

Similar Messages

  • Deleting mail on pop server does not delete mail on phone

    I have two Andoid phones:
    1. My Personal Samsung Galaxy Note/AT&T
    2. My Employers Motorola Droid RAZR/Verizon
    They are both running Android 4.0.4. I have set up pop mail on both. My personal ISP is X/O and a pop3 account. I typically have it deliver mail to Outlook at my home and turn off Outlook to read mail when away. The first phone correctly reconciles the delete of the mails delivered to Outlook and no longer on the server. The Verizon Droid does not delete the mail from the phone when it is gone from the server. I deleted and readded the pop account and experience the same behavior. How do I get the phone to delete the mail that has been removed from the server?
    Since it is a company phone but a personal e-mail account I am not sure where to get support.

    I found that there was a slight time lapse from when I managed a message on my iPhone (with .Mac) to when it showed the same status on my Mail.app (.Mac). For example, I deleted a message directly from my Inbox (iPhone) and it moved to trash. But it took about 2 minutes for that same message to show up in my trash on my machine. It just sat as a new, unread message on my laptop and then suddenly during the next send/receive interval it was put into the trash (still marked as unread, though).
    Have you allowed any sort of time lapse? Or are you viewing the webmail view of your .Mac account simultaneously as your actions on the iPhone?

  • Deleted Mail on the iPhone does not delete on .Mac

    I've noticed that when I delete mail on my iPone in my .Mac account that it does not show as deleted when going to webmail.mac.com. I see the messages still in my inbox AND in the trash.
    Any ideas why this is not synching?
    Thanks.

    I found that there was a slight time lapse from when I managed a message on my iPhone (with .Mac) to when it showed the same status on my Mail.app (.Mac). For example, I deleted a message directly from my Inbox (iPhone) and it moved to trash. But it took about 2 minutes for that same message to show up in my trash on my machine. It just sat as a new, unread message on my laptop and then suddenly during the next send/receive interval it was put into the trash (still marked as unread, though).
    Have you allowed any sort of time lapse? Or are you viewing the webmail view of your .Mac account simultaneously as your actions on the iPhone?

  • Deleting e-mail in iOS7 does not delete message in MBP mailbox

    Since updating to Mavericks, I am not able to have my inbox on my MBP update as a result of actions taken on my iPhone 5S. If I delete an e-mail message on my Mac, it will also be deleted on my phone. If I delete a message on my phone, it wil NOT be deleted on my Mac. Calendar updates work fine in both directions so it doesn't appear to be an iClooud issue. Is anyone aware of a bug (or a fix) that would prohibit my mail account on the MBP from updating what has happened on my iPhone?

    A MobileMe account is a separate email account from the POP account or from any other email accounts that you access with Outlook.
    A MobileMe account is an IMAP account. With an IMAP account, all server stored mailboxes for the account will be kept synchronized with the server automatically with all email clients used to access the account. In this case, with the iPhone's Mail client and with Outlook.
    A POP account is designed to be accessed with a single email client only and mailboxes with a POP account cannot be kept synchronized with multiple email clients used to access the account.
    RIM provides a dedicated email delivery service for Blackberrys which Apple does not provide for the iPhone. You access email accounts with the iPhone's Mail client as you do with Outlook on your computer.

  • Deleting Voicemail from Landline Call Does not Delete Voicemail from iPhone

    I am a Verizon subscriber with an iPhone 4S, if that matters to this issue.
    I wanted to cleanup my voicemail and not use any of my minutes.  So, I called my iPhone from a landline at the office and entered the voicemail system.  As a test, I deleted the first 3 voicemail messages.  Then I went to the voicemail on my iPhone and checked for messages--the three I had deleted while on the landline phone were still on my iPhone and could still be played.
    Why don't the messages that are deleted from a landline, or another incoming call to the voicemail center, get deleted on the iPhone?
    Thanks in advance.

    Thanks for your reply.
    So will deleting the voicemail message on the iPhone delete it from the call-in Verizon system?
    With two ways of accessing voicemail, on the iPhone Visual Voicemail and from a call-in line to your phone number to Verizon's system, it would seem that the two could get seriously out of sync.  Isn't this a big problem?
    Which is the "master" system.  Don't they ever resync together?

  • HT1495 I delete emails on my Iphone 4s but it does not delete the email when I open my Ipad. Any help would be appreciated

    When I delete an email from my Yahoo account on my Iphone 4s, it does not delete it from my computer or my IPAD. I am forced to delete every message three times. Any ideas?

    You may well have a POP Yahoo account, in which case deleting emails on one device does not delete them everywhere else.  POP accounts do not provide sync services like IMAP accounts (e.g. Apple mail).  Usually, a POP account offers settings so that when you delete an email locally, that will also delete it from the server; however, if this email has already copied down to another device, that email will not delete from that other device.  Or you can set a POP account so that deleting on a device will not delete from the server, thus all other devices will eventually get the email as well.

  • My new iphone 5 email is synched with my home office computer Outlook email using a POP account, but deleting an email on my computer does not delete it on my phone and vice versa.  Is there any way to get a true synch?.

    My new iPhone 5 email is synched with my home office computer Outlook email using a POP account, but deleting an email on my computer does not delete the email on my phone and vice versa.  Is there any way to get a true synch?.

    POP does not support synchronization between the server and clients. You will need to use IMAP or Exchange Active Sync if your email provider supports it.

  • After delete iSCSI LUN vacant space does not become available

    px12-400r, one pool on RAID10 (5,42TB).
    Pool divided into 4 iSCSI LUN (2TB+2TB+1TB+0,42TB).
    After deleteting one of them (on 2TB), this vacant space in tab "System Status" (over Web Interface) shown in the diagram as the free and "Amount of available space" on Status Bar 2TB (on Device Home Page over Web Interface),
    but in tab "Disk Management" shows "Allocated/Available" - "5,42TB/0B" , and new volume or iSCSI LUN can not be added ("In any storage pool does not have enough space to add an iSCSI drive"
        Storage in AD. Deleting iSCSI LUN over Web Interface under AD user with storage admin rights.
     Rebooting storage did not help. What to do? How to return control of this free disk space?

    Hello gusev67
    To be certain that the iSCSI LUN was actually delete, please try this alternate method to check if the LUN is present and if so, deleted.
    Go to Drive Management and click on the "volumes" section of your storage pool
    Navigate to the iSCSI LUN that should have been deleted/removed
    If it is present there, please click on the iSCSI LUN name to show the iSCSI information overview for the LUN, there click on the "delete" option.
    If that does not seem to resolve the issue  I recommend contacting LenovoEMC support regarding the problem.
    LenovoEMC Contact Information is region specific. Please select the correct link then access the Contact Us at the top right:
    US and Canada: https://lenovo-na-en.custhelp.com/
    Latin America and Mexico: https://lenovo-la-es.custhelp.com/
    EU: https://lenovo-eu-en.custhelp.com/
    India/Asia Pacific: https://lenovo-ap-en.custhelp.com/
    http://support.lenovoemc.com/

  • Please i want to remove the old version of itune, the new version does not delete it for some reason , what i should do?

    please i want to remove the old version of itune, the new version does not delete it for some reason , what i should do?

    See https://support.mozilla.org/en-US/kb/firefox-no-longer-works-mac-os-10-4-or-powerpc
    Since you have a Intel Mac, if you can upgrade to OSX 10.5.x then you may be able to use more current releases.
    jscher2000, You should link to http://www.mozilla.org/en-US/firefox/all-older.html for 3.6.28 since the ftp is not mirrored.

  • When I upload photos to iPhoto from my iPhone and then press delete from iPhone it does not delete them, how do I fix this?

    When I upload photos to iPhoto from my iPhone and then press delete from iPhone it does not delete them, how do I fix this?

    I am having the same problems as this person. I see that someone said there is no way to retrieve the pictures once it gets stuck in recovery mode.
    Then further along someone said that there are data retrieval methods except they have something to do with jail breaking a phone.
    My phone is already jail broken. It was kind of a gift from the company I work for- it was a fellow employees before. He jail broke it and then it was given to me. After I got it I activated the 4 and tried to back up everything. It didn't work and "Springboard" forced the phone into safety mode. So I could use it with the old dude's apps and my contacts. I made the mistake of using the phone for wedding dress shopping with a friend. I took tons of pictures.
    After this I found out the messages I was seeing meant it was jail broken. At&t said to force restore the phone - iTunes wouldn't recognize it in safety mode. I'm an idiot and didn't realize what this meant for my pictures. It didn't work (error 1611) - thankfully. Now it is stuck in recovery mode (iTunes icon and USB cable picture).
    Can I access that media in any way? It never suceeded restoring itself so is it still there? The phone is jail broken already so is there a method I can use?

  • Emptying trash securely does not delete all files? Any ideas?

    When I try and empty trash (securely) it does not delete all files, so I am left with files in the Trash?  Any ideas?

    Select one of the items in the Trash and open the Info window. What does it show for Where?

  • Once I accept a calendar invite on my iPhone, I cannot delete or otherwise modify it.  Even when it is updated or deleted by the invitor, it does not change on my iPhone.  Is there a fix for this?

    Once I accept a calendar invite on my iPhone, I cannot delete or otherwise modify it.  Even when it is updated or deleted by the invitor, it does not change on my iPhone.

    My husband and I both have iphone 4's and we both have this same problem.  I have an open ticket with apple, but so far they haven't been able to figure this out.  First, they told me the problem was the mail server I was using.  So, I tried sending/receiving invites from gmail and yahoo which they told me should work.  Neither did.  It doesn't matter whether the original invite was created in iCal or in Outlook or Google, once I open the invite in my mail and hit "add to calendar" the event is locked into my calendar.  If the originator sends an update or cancels the meeting, I will receive an email with the new info, but the event doesn't change in my iphone calendar.  This is completely lame.  Why bother putting a calendar app on the phone if it can't handle basic functions?
    Did you ever get a response from anyone or figure out a workaround?  I'll post if I hear back from Apple with a fix.

  • An infopackage does not delete privious requests though its set to

    Hi experts.
    An infopackage is set to delete repeating requests, but it does not work when it in a process chain. If i run infopackage itself it does, but in chain it does not delete requsts. Why?
    Regards Tigr_Z

    Hi,
    I think that If you want to use this option while loading the data through process chains, you would need to Add a Process Variant u201CDelete Overlapping Request From InfoCubeu201D to the process chain, position of this variant will be after the data load (Execute InfoPackage). For more detailed procedure refer to this document ::
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e0431c48-5ba4-2c10-eab6-fc91a5fc2719?QuickLink=index&overridelayout=true
    Regards,
    APK

  • CSAP_MAT_BOM_MAINTAIN does not delete BOM

    Hi Friends,
    FM CSAP_MAT_BOM_MAINTAIN does not delete BOM when we use DELETE_IND = X
    in STKO_API01 in import parameters of this FM.  Do you have any idea ?
    Regards,
    Gaurav

    Hi,
    you should use instead CSAP_MAT_BOM_DELETE.
    Regards,
    Andrea

  • Uninstall the application does not delete all new files and folders.

    If the user decides to uninstall my Air app, it does not delete the created folders with files in AppData. Another problem is that if the application creates new files in the folder Program Files/AirAppFolder, then uninstall of the app are not deleted these files.
    How to solve these problems, help please?

    Hi,
    AIR shouldn't be creating additional files in your program files folder, is this something you're doing programmatically?  If so, you might want to consider using File.applicationStorageDirectory instead given permission problems you'll have on newer operating systems.
    As to uninstalling all files (even the data created in the user's storage folder) this is something you might consider using a native installer to take care of.  Since the AIR installer is unaware of this data, it won't know to delete it on uninstall.  Instead, you'll want to create a custom function in a native installer that deletes these folders/files and then sub launches the AIR install/uninstall.
    Thanks,
    Chris

Maybe you are looking for

  • Mac mini restarts on its own after shut-down.

    The Mac mini will restart by itself about 10 minutes after shut down. I turned off all the restart options in energy saver. Funning 10.4.8 with the latest firmware instalation. Any suggestions how to stop this?

  • Lost apple recovery key fire vault on

    forgot new password

  • Writing to DVD

    OK, here's the problem. I produced my first 40 minute long presentation of still pictures, mixed with six short movie clips. There is a soundtrack running in sync with the pictures, going to mute when the movies run. I finished the presentation and c

  • JDeveloper 10.1.3.1 - injection works partiin embedded OC4J

    Hi, there are a few simple examples which do not work under embedded OC4J: Example #1: public class ContextListener implements ServletContextListener { @PersistenceUnit(unitName="myUnitName") private EntityManagerFactory emf; public ContextListener()

  • Changing DB_NAME after database installation

    Hi, I installed Oracle10g on linux server. now I want to change the database name DB_NAME for security reasons. How can i do this? and where all i need to the changes for the database and EM to come back up successfully. Thanks in advance.