JPA: trouble removing a 1:M cascade ALL relationship from entity

I have an entity A, with a OneToMany relationship to entity B, and cascade set to ALL.  Entity B has a ManyToOne relationship to A.  In my scenario I create a new instance of B to a detached instance of A, and I add it to the 1:M of A and set the M:1 on B.
Then I'd like to merge the changes on A using EntityManager.merge(A).  However, before I do that I need to remove a different (old) instance of B from A, and then merge my changes so that my new instance of B is persisted.
I've tried a couple different scenarios and get different results (none favorable):
1.  First lookup the instance of B I want to remove via EntityManager.find(id), and then call EM.remove(B).  And then I call EM.merge(A) on the instance of A with my new B.  I get the following IllegalArgumentException during the merge:
java.lang.IllegalArgumentException: Cannot fulfill merge operation: Relationship >>outputElementInstances<< of the target entity {com.sap.eventus.wire.entity.EvtWireInstance(id=85e83543-45d1-49cd-bb90-8688699ca0d4)} has been modified
The relationship it's talking about is actually a different (but related) one that was affected when the old instance of B was removed.  It seems reasonable that JPA has determined that my instance of A with the new B is no longer in sync with the database and is complaining that a relationship has been changed.
Any ways around that?
2. I also tried simply removing B from A's 1:M, and setting B's M:1 to null, and then merging in hopes that would trigger a delete on the old B.  However the old B is not removed.
I was expecting this to trigger a delete, however, I realize that there are other relationships from B to other objects (such as a 1:M cascade ALL) that I did not remove which I suspect might cause JPA to not delete the old B.  Is this true?
3. And finally I tried 1 & 2 together, first calling EM.remove(old B), and then removing the old B from A and then merging, which yields the following IllegalStateException:
java.lang.IllegalStateException: Relationship >>wireInstance<< of entity {com.sap.eventus.wire.entity.EvtElementInstance(id=08ca6253-1385-45dd-9173-978ee298b55f)} contains the new entity {com.sap.eventus.wire.entity.EvtWireInstance(id=c9fbd4e7-5575-4cc9-9b7d-2a8549c43574)}
Which is another different (but related) relationship off of object B.
Basically, after all this, my question is: what is the correct way to remove a 1:M relationship and add a new one?  Simple enough, however I do not want to remove the old 1:M, re-query to get the new updated parent object and then add the new 1:M, as it's a fairly involved in creating and adding the new 1:M and it must be done BEFORE removing the old 1:M.
Thanks!

Hi Derek,
I understand your task as follows:
You are having three entities A, B_old and B_new. Within one transaction you want to do the following:
- remove B_old from the database
- remove B_old from the 1:n relationship A.bs
- persist the B_new
- add B_new to the 1:n relationship A.bs
- set the n:1 relationship B_new.a to refer to A
well, I suggest that you do this without a merge:
- em.remove(B_old)  // you have to do this explicitly as JPA 1 does not have automatic orphan removal
- A.bs.remove(B_old)
- em.persist(B_new) // also, you have to make sure that the entities related to B_new are managed upon commit
- A.bs.add(B_new)
- B_new.a = A
I hope this works.
Regarding your observations:
1. The error message is not self-explaining. We have got to improve it ;-).
2. You have to remove the B_old explicitly as JPA 1 does not have automatic orphan removal. 
3. This message should be self-explaining. Maybe there is one of the relationships EvtOutputElementInstance.wireInstance or EvtInputElementInstance.wireInstance still referring B_new. You'll surely find out.
Regards,
Adrian

Similar Messages

  • How can I sync my iPhone to my Mac so I can remove a few but no all audiobooks from my iPhone?

    I have lots of audiobooks on my iphone but not all are from iTunes.  Today the genius bar guy showed me how to add my purchased audiobooks on my Mac.  The problem is it's all or nothing.  I can't pick and choose the books I want to take off my iPhone.  I can't update my operating system until I remove a few audiobooks to make room.

    Syncing to a new iTunes library or computer will erase your phone. Only if you back up your phone manually before syncing, you can restore your phone from that backup again. A manual backup does not include the sync process.
    Set up your iTunes account, disable autosync in iTunes, connect your phone to your new computer and right click on it in the device list and choose backup. iTunes will backup your phone without syncing.
    Transfer your purchases the same way, choosing "transfer purchases" this time.
    When you connect your phone for the first time, all media content will be erased. But you can restore your settings and app data from your manual backup afterwards.
    Don't forget to set up at least one contact and event on your new computer to be able to merge calendars and contacts when you sync the phone for the first time.
    Music is one way only, from the computer to your device, unless you bought the songs in itunes and transferred your purchases.
    There is 3rd party software out there, but not supported by Apple, see this thread: http://discussions.apple.com/thread.jspa?threadID=2013615&tstart=0
    About backups and what's saved:http://support.apple.com/kb/HT1766
    How to back up and restore:http://support.apple.com/kb/HT1414
    How to download apps for free again:http://support.apple.com/kb/HT2519
    Saving other data is also described here. How to back up your data and set up as a new device
    Message was edited by: Ingo2711

  • I'm having trouble removing my Yahoo! e-mail account from my Motorola Razr!  HELP!

    I have not received any e-mails on my phone but my notification ringtone goes off every time.  I have entered my password to access my e-mail account, but it tells that I have invaild credentials.  I have also tried to remove and add the account again, but it says invalid credentials every time.  HELP!!

        Hi brittbritt21987,
    Not being able to remove your email account must be very inconvenient. When you get the INVALID CREDENTIALS error, the email needs to be authenticated online via a computer. Are you able to access your email account online?
    If you continue to experience this issue you may need to do a factory reset http://goo.gl/252lc to resolve the issue.
    AntonioC_VZWSupport
    Follow us on Twitter at www.twitter.com/vzwsupport

  • I am having trouble removing songs from my iPhone.  i have unchecked songs in the library on my mac, but they still show up on phone after syncing.  how do I remove them?

    I am having trouble removing songs from my iPhone.  i have unchecked songs in the library on my mac, but they still show up on phone after syncing.  how do I remove them?

    Hi asims01,
    Welcome to the Support Communities!
    The information below may be able to answer your questions about how to delete songs from your iPhone:
    Deleting songs downloaded to your device
    Tap the Music app.
    Tap More > Songs at the bottom.
    Scroll or search for the song you would like to delete from your device.
    Swipe right to left on the song, and then tap Delete.
    Note: You must be in Artists, Songs, or Albums view to delete songs from your device. Deleting from a playlist won't remove a song from your iOS device.
    Also, this information can be found on page 64 of the iPhone User Guide for iOS 7
    http://manuals.info.apple.com/MANUALS/1000/MA1565/en_US/iphone_user_guide.pdf
    Remove a song from iPhone. Tap Songs, swipe the song, then tap Delete. The song is deleted from iPhone, but not from your iTunes library on your Mac or PC, or from iCloud.
    If you have iOS 7, this will delete the song from local storage, but the song will still appear with a cloud symbol in the Music app, as you've noticed. To hide the iTunes in the Cloud purchases, navigate to Settings > iTunes & App Store, and disable "Show All: Music”
    There may be a few orphaned songs on your iPhone that were partially downloaded or corrupted in some way. If that is the case, you can erase all of the music from your phone.  Follow the instructions below and select the Music app under Usage:
    iPhone, iPad, and iPod: Understanding capacity
    http://support.apple.com/kb/ht1867
    I hope this information helps ....
    - Judy

  • Trouble removing photos from iPad

    I'm having trouble removing photos from my iPad2 running iOS 5.0.1. In iTunes I've told it not to sync ANY photos. When I first changed this it asked me if I wanted to remove the photos currently there, I said yes and they disappeared. But when it finished syncing they had reappeared despite the fact that it now claims I don't have it set to sync any photos. I don't have photostream enabled. I've tried syncing a couple of times, but no luck. Any ideas? (I searched the forums but everything I found was people who didn't understand how to use iTunes to manage iPad content...that's not my problem..) (also it is like 3 gigs of pics so I don't really want to delete them all by hand since there isn't a way to batch delete...)

    Try deleting the photo cache from your computer and then select and sync an empty folder to the iPad and see if that removes them - the location of the cache, and how to delete it, is on this page http://support.apple.com/kb/TS1314

  • TS3212 I am told that the ITunes will not download because it is having trouble removing the older version bonjour. What do I need to do?

    I am trying to sync my new IPhone 4 with ITunes. I have tried downloading the new version of ITunes on my pc like it told me to do but it stops in the middle of downloading and says that it is having trouble removing the old bonjour. It said I should contact support. What do I need to do?

    Download the Windows Installer CleanUp utility from the following page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    To install the utility, doubleclick the msicuu2.exe file you downloaded.
    Now run the utility ("Start > All Programs > Windows Install Clean Up"). In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    Quit out of CleanUp, restart the PC and try another install. Does it go through this time?

  • PLEASE HELP! - when i go to open up itunes this message appears "This copy if itunes is corrupted or not installed properly" If i remove itunes will i lose all my bac ups?

    when i go to open up itunes this message appears "This copy if itunes is corrupted or not installed properly" If i remove itunes will i lose all my bac ups?

    Let's try a repair install of iTunes first.
    Restart the PC. If you're using Vista or 7, now head into your Uninstall a program control panel, select "iTunes" and then click "Repair". If you're using XP, head into your Add or Remove Programs control panel, select "iTunes", click "Change" and then click "Repair".
    Can you launch your iTunes now?

  • Ipod 5 wasn't updating new playlists.  Removed all music from iPod and ended up with 34 GB of OTHER.  How do I remove this without doing a full restore?

    iPod 5 was not adding new playlists when synching (plenty of space remained in memory for it).  This happened around the time of the new update.  I removed all music from the iPod and when I went to resync the selected playlists, my OTHER portion of memory jumped up to 34GB and now there is not enough space on the iPod to put all my music back on.
    I've checked the usage of all the apps and photos, etc, it is pretty clear this is because of the music portion only.
    Is there anyway of removing this information?  Without doing a restore?  It is not jailbroken either.

    An "other" larger than about 1 1/2 GB indicates corrupted files.
    What is the Other on my iPhone and How to Remove It
    What is "Other" and What Can I Do About It?
    Next, usually restoring from backup eliminated the corrupted files. However, sometimes restoring to factory settings/new iPod is required.
    To restore from backup see:
    iOS: How to back up
    To restore to factory settings/new iPod see:
    iTunes: Restoring iOS software

  • How to make button to format a HardDrive or USB, How to remove all files from folder, and How to delete a process in listbox with a textbox?

    Hello!
    Here's the question with explaniation: How can i format the USB or Drive by clicking a button what's meant for it?
    and the second question what's also in vb.net: How can i remove all files from folder ? 
     Here's the Look of program: *
    Using the PC button, it will delete the free space of the PC, do you guys/girls know where it's location?

    Example Code:
    Imports System.Runtime.InteropServices
    Imports System.IO
    Public Class Form1
    Dim CBoxDrives As New ComboBox
    WithEvents FButton As New Button
    <DllImport("shell32.dll")> _
    Private Shared Function SHFormatDrive(ByVal hwnd As IntPtr, ByVal drive As UInteger, _
    ByVal fmtID As UInteger, ByVal options As UInteger) As ULong
    End Function
    Private Enum SHFormatFlags As Integer
    SHFMT_ID_DEFAULT = &HFFFF
    SHFMT_OPT_FULL = &H1
    SHFMT_OPT_SYSONLY = &H2
    SHFMT_ERROR = &HFFFFFFFF
    SHFMT_CANCEL = &HFFFFFFFE
    SHFMT_NOFORMAT = &HFFFFFFD
    SHFD_FORMAT_FULL = 0 ' full format
    SHFD_FORMAT_QUICK = 1 ' quick format
    End Enum
    Private Sub FButton_Click_1(sender As System.Object, e As System.EventArgs) Handles FButton.Click
    If CBoxDrives.Text = "" Then
    MsgBox("No Drive Selected")
    Exit Sub
    End If
    Dim Iresult As ULong = SHFormatDrive(CType(Me.Handle.ToInt32, IntPtr), CUInt(Asc(CBoxDrives.Text.Substring(0, 1)) - Asc("A")), CUInt(SHFormatFlags.SHFMT_ID_DEFAULT), 1)
    End Sub
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.Size = New Size(200, 100)
    With FButton
    .Size = New Size(50, 25)
    .Location = New Point(5, 5)
    .Text = "Format"
    End With
    Me.Controls.Add(FButton)
    With CBoxDrives
    .Size = New Size(50, 25)
    .Location = New Point(75, 5)
    .DropDownStyle = ComboBoxStyle.DropDown
    End With
    Me.Controls.Add(CBoxDrives)
    Dim DrivesFound As Integer = 0
    Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
    Dim d As DriveInfo
    For Each d In allDrives
    If ((d.DriveType = DriveType.Fixed) Or (d.DriveType = DriveType.Removable)) AndAlso Environment.GetEnvironmentVariable("SYSTEMROOT").StartsWith(d.Name) = False Then
    CBoxDrives.Items.Add(d.Name)
    DrivesFound += 1
    End If
    Next
    CBoxDrives.SelectedIndex = DrivesFound - 1
    End Sub
    End Class

  • How can I remove all photos from my iphone?

    How can I remove all photos from my iphone?

    Hi pjdemeo,
    I understand you want to delete all of the photos from your iPhone.  As a precaution, I would suggest importing the photos and videos from your iPhone into your computer.  This will give you a backup for the images, and after import you will be asked if you want to delete the photos.
    Import photos and videos from your iPhone, iPad, or iPod touch to your Mac or Windows PC - Apple Support
    https://support.apple.com/en-us/HT201302
    The iPhone User Guide has instructions for deleting photos directly from the device:
    Organize photos and videos - iPhone
    http://help.apple.com/iphone/8/#/iphf14943e
    Delete a photo or video from Photos. Tap the Photos tab, tap the photo or video, tap , then tap Delete Photo or Delete Video. Deleted photos and videos are kept in the Recently Deleted album on iPhone, with a badge showing the remaining days until the item is permanently removed from iPhone. To delete the photo or video permanently before the days expire, tap the item, tap Delete, then tap Delete Photo or Delete Video. If you use iCloud Photo Library beta, deleted photos and videos are permanently removed from all iOS 8.1 devices that use iCloud Photo Library beta with the same Apple ID.
    Cheers,
    - Judy

  • How do I remove all apps from my iPhone?

    How do I bulk remove all apps from my iPhone? There has to be a better way than removing each one manually. Thanks.

    It's easiest to plug it into the computer if you have a lot, and click on the Music tab of the iPhone. Then, either Control-A (Windows) or Command-A (Mac) to select all of the songs then press delete on your keyboard. If you have a few, it is easiest to swipe over the individual songs and press delete.

  • About three days ago my iphone5 stopped connecting to my home wifi. I've tried everything in the trouble shooting guides and everything in all the support comments here.Is there anything else it could be? my other devices connect no probs.

    About three days ago my iphone5 stopped connecting to my home wifi. I've tried everything in the trouble shooting guides and everything in all the support comments here.Ive reset network, reset all phone settings, turned wifi on and off, forgotten network. Nothing works. Is there anything else it could be? The wifi is fine as all my other devices connect to it no probs. appreciate any help?

    About three days ago my iphone5 stopped connecting to my home wifi. I've tried everything in the trouble shooting guides and everything in all the support comments here.Ive reset network, reset all phone settings, turned wifi on and off, forgotten network. Nothing works. Is there anything else it could be? The wifi is fine as all my other devices connect to it no probs. appreciate any help?

  • HT201365 Hi all, im from dubai. someone stolen my iphone5. i was trying to erase my data via find my iphone. in the end there was a notification that remove. i have click remove. then it never shows my device in find my iphone. how can i see my device in

    Hi all, im from dubai. someone stolen my iphone5. i was trying to erase my data via find my iphone. in the end there was a notification that remove. i have click remove. then it never shows my device in find my iphone. how can i see my device in my pc...?

    Here's an interesting bit: iTunes will let me restore my iPod touch from backup: it's still running iOS 4.3.3. I figured as much... there's backups showing in the Preferences -> Devices list for both devices (and even my old, long gone iPod touch 2G), but my iPhone (on iOS5) isn't giving me any such option. I remember I had to downgrade before to get the backup restored (something went haywire in the setup assistant, and I couldn't restore a backup from iTunes there)... If it was possible to go to iOS 5.0 rather than 5.0.1 I would just do the same thing again, but iOS 5.0.1 isn't an option. I attached a screenshot. Hopefully Apple can get this nonsense sorted out; I think iOS 5 might be the root of this, somehow.

  • Hello, I was trying to upgrade my iTunes for windows 7 PC, but because of invalid signature error I removed iTunes as well as all apple related applications. While reinstalling it , When I click link to install iTunes it immediately says '' thank you

    Hello, I was trying to upgrade my iTunes for windows 7 PC, but because of invalid signature error I removed iTunes as well as all apple related applications. While reinstalling it , When I click link to install iTunes it immediately says '' thank you for downloading iTunes'' but I don't find it in my system.
    I have tried all suggested option to solve it but all in vain. Please help me to get rid of this problem

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    The further information area has direct links to the current and recent builds in case you have problems downloading, need to revert to an older version or want to try the iTunes for Windows (64-bit - for older video cards) release as a workaround for installation or performance issues, or compatibility with QuickTime or third party software.
    Your library should be unaffected by these steps but there are also links to backup and recovery advice should it be needed.
    tt2

  • I previously had PS CS5 Trial installed but removed it using both Control Panel Programs and deleting all files from the CS5 directory on Program Files.  I then installed a purchased product from Adobe disc using the serial number on the case.  But when I

    I previously had PS CS5 Trial installed but removed it using both Control Panel Programs and deleting all files from the CS5 directory on Program Files.  I then installed a purchased product from Adobe disc using the serial number on the case.  But when I try to launch it, I get a screen headed Photoshop CS5 Extended Trial.  It asks for the serial number and says that my trial has expired.  It rejects the serial number from the Adobe case saying "This Serial Number is not valid for this product".  It thinks that I still have the expired Trial Version installed.  How do I convince it (the program) that the Trial Version is long gone and the currently installed product was installed with a valid and accepted serial number????

    Let me know how it goes. Go into your Adobe account and register your serial number asap.
    https://www.adobe.com/account/my-products-services.html
    That way, should you lose it or you need support, it is on record that it's yours and you can fetch your s/n it from anywhere.
    There are too may sad stories here, where people forgot and the box is buried or lost.
    Gene

Maybe you are looking for

  • Suite color management is not enabled

    I have Creative suite CS4 production premium.  I have downloaded the trial version of InDesign.   When I open InDesign go to open/ browse in bridge then in  bridge edit/Creative suite color settings  I get the following error message. Suite color man

  • How to pass a javascript variable to a query in BEx?

    Hi All, We're using BEx SAP BW 3.x I'm using portal eventing to pass a variable to a BW template.  While I can pick up this value using javascript, I do not know how to pass it to the query. Let me just say, I am new to BEx, so any guidance you could

  • Exchange 2003 SP2 messages stuck in queue

    HI I just inherited a exchange 2003 SP2 machine and next month we are migrating to 365.  But here is what happen so far and the issue 1.  The previous IT company had the emails flowing thru smart host via their own hosted spam filter. 2.  I came in a

  • Why is my HD not shown as a startup disk?

    My macbook pro died on me, since it has stopped going into safe sleep (hibernate). Only this time I couldnt start it up again, it only gave me the question mark. When I start up from the CD and check the drive with Disk Utility everything is ok. But

  • Why won't my macbook pro turn on after i reset it for the updates

    i did the new updates on my macbook pro and it was working fine the night before. It was going to take around five hours to get the new udates , but this moring i was using the computer and it stoped working. The updates showed a message that read an