Problem controlling the order of deletes

Hello,
I built a very simple example that uses two Java classes (Department and Employee) with a one-to-many relationship. The property "name" of class Employee maps to the primary key column of the EMPLOYEE table in the database. Now if I remove all employees from a department and then insert one employee who happens to have the same name as one of ex-employees, the things go wrong:
[TopLink Info]: DatabaseSession(101)--acquire unit of work: 216
[TopLink Info]: DatabaseSession(101)--Connection(102)--SELECT NAME FROM MACIEJ.DEPARTMENT WHERE (NAME = 'IT')
[TopLink Info]: UnitOfWork(216)--begin unit of work commit
[TopLink Info]: DatabaseSession(101)--Connection(102)--begin transaction
[TopLink Info]: UnitOfWork(216)--Connection(102)--INSERT INTO MACIEJ.EMPLOYEE (NAME, FIRST_NAME, DEPARTMENT_NAME) VALUES ('Schinzel', 'Dieter', 'IT')
[TopLink Info]: UnitOfWork(216)--Connection(102)--DELETE FROM MACIEJ.EMPLOYEE WHERE (NAME = 'Marczukajtis')
[TopLink Info]: UnitOfWork(216)--Connection(102)--DELETE FROM MACIEJ.EMPLOYEE WHERE (NAME = 'Schinzel')
[TopLink Info]: DatabaseSession(101)--Connection(102)--commit transaction
[TopLink Info]: UnitOfWork(216)--end unit of work commit
[TopLink Info]: UnitOfWork(216)--release unit of work
This happens also when I am using the method setShouldPerformDeletesFirst(true). The deletes are still executed after the insert. The code follows.
ExpressionBuilder builder = new ExpressionBuilder(Department.class);
Expression constraint = builder.get("name").equal("IT");
UnitOfWork uow = this.session.acquireUnitOfWork();
uow.setShouldPerformDeletesFirst(true);
Department dep = (Department) uow.readAllObjects(Department.class, constraint).get(0);
uow.logMessages();
dep.removeAllEmployees();
// Employee emp = new Employee();
Employee emp = (Employee) uow.registerObject(new Employee());
emp.setName("Schinzel");
emp.setFirstName("Dieter");
dep.addEmployee(emp);
uow.commit();
Another problem I encountered is that I have to use registerObject() on the new Employee (still if the value of "name" is identical to one of the employee's names that I am removing), because otherwise I am getting this:
Local Exception Stack:
Exception [TOPLINK-6004] (OracleAS TopLink - 10g (9.0.4) (Build 031126)): oracle.toplink.exceptions.QueryException
Exception Description: The object [cern.toplink.try1.Employee@ec[ name: Schinzel ; 1st name: Dieter ; dep: IT ]], of class [class cern.toplink.try1.Employee], with identity hashcode (System.identityHashCode()) [236],
is not from this UnitOfWork object space, but the parent session's. The object was never registered in this UnitOfWork,
but read from the parent session and related to an object registered in the UnitOfWork. Ensure that you are correctly
registering your objects. If you are still having problems, you can use the UnitOfWork.validateObjectSpace() method to
help debug where the error occurred. For more information, see the manual or FAQ.
I would appreciate any hints how I can force the deletes to happen before the insert.
Cheers,
Maciej

You cannot have two different objects in the same unit of work with different primary keys.
You must either update the object instead of deleting and inserting it, or split the operation across two units of work.
The setShouldPerformDeletesFirst only applies to publicly deleted objects, not objects that are deleted through private owned relationships. If you did not mark the relationship as private-owned and deleted the objects through uow.deleteObject then the deletes would be processed first. However you should still try to avoid having two different objects with the same primary key in the same unit of work.

Similar Messages

  • ADF: controlling the order in which VO records are inserted

    All,
    in an ADF BC project, we have some complex MD insert pages that add records to master and detail tables at the same time. The application sits on top of CDM RuleFrame, which exposes the datamodel as DB views with instead-of triggers and adds (Designer) a few nifty things like auto-populated PK fields. Sad enough, we can't use these auto-generated PKs as the 'refresh after insert' settings in an EO work with a RETURNING clause, which is not supported for instead-of triggers. This means we'll have to find the PK sequences ourselves from the EOs and populate these fields ourselves, before committing to the database. So far so good, but things go wrong when we want to insert master and detail at the same time. The PK and FK of the child record are already filled in at insert time (which is nice) but for some reason the child records get inserted before the parents, resulting in an error on the FK as the parent record does not yet exist (which is not nice).
    So, here's the question: is there a way to control the order in which new VO records are inserted ? On what is the default order based (maybe a little renaming could help us out to get the alphabet our way) ?
    We know defining the FKs as 'initially deferred' will make sure they are only checked at commit time, but our DBA prefers to not use that solution unless strictly necessary. (is there anything bad about deferred keys why we should believe him? ;o) )
    And additionally, is there a way around all this manual PK-fetching ? We've tried using the refresh(int refreshMode) method of EntityImpl, but it didn't seem to work.
    Many thanks in advance for your tips, suggestions and solutiosn !
    Best regards,
    Benjamin De Boe

    Benjamin,
    To handle the problem with the child/parent records being inserted in the wrong order - have a read of the Oracle ADF Developer's Guide for Forms/4GL developers, section 26.7. I use that technique with great success.
    John

  • I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    In landscape mode, the mailbox list is automatically displayed (in portrait mode, you will need to tap the button to,show it).
    To edit the list, tap edit as shown below.

  • How do I control the order of all day events in iCal?

    How do I control the order of all day events in iCal?  Even if I painstakingly try to
    re-order the events the way I want them, when they print, they are in a different order.
    I have searched other forums and no one seems to have an answer to this.  Has
    anyone found the solution?  Thanks!

    I also have this issue, where the events in iCal change when viewing in print preview or printing. I even notice they will switch if I try to print again??!!! I am using different calendars to show different colours. and they are setup on iCloud not on my mac.
    it is becomign frustrating when I print 2 months worth and ssome events are correct in order and alas some will change when I print again!
    Can anyone help please?
    thanks

  • How can I control the order of playback on MuVu Mix (USB 2.

    What determines the order of playback of music files stored on the MuVu Mix (USB 2.0)? How can I control the order?
    Apparently it is not name order. The music titles are prefixed by sequential numbers. But that is not the order that the files play back.
    I tried erasing all contents, then copying the files one by one to the MuVo Mix in the order that I want them to play back (name order). But that is not the order that the files play back.
    By the way, in both case, I removed the ".dat" file first. (I also tried keeping the ".dat" file, to no avail.)

    SSR wrote:
    > on the newer MuVos (which I would have thought included the Mix)
    > it's filename order. Other than that it's hard to know, but it sounds
    > like you ought to contact Support to check.
    I did, and they confirmed (very quickly; kudos!) what you and I both expect: the play order is determined by the alphabetical order of the file names. The mistake was mine. I ass-u-me-d that the MSWin folder "Name ^" order was correct. I did not realize that it is not exactly alphabetical when the file name begins with a number (e.g, the track number). I had renumbered songs from a second CD by simply adding 00 to the track number. Thus, songs and 2 of the first CD are played after songs 08 and 09 of the second CD, as they should alphabetically, even though they appear in the order , 2, 08, 09 in the "Name ^" list. Klunk! Mea cupla!

  • In Photos, how can one control the order of pictures in an album?

    Is there any way, in Photos, to control the order of pictures in an album? Is there any way to sort, or order things manually?

    Thanks. Let me refine my question as follows: is there a way to keep the manual order in albums that I had in iPhoto when transferring to Photos?

  • Since I upgraded to IOS5, my Smart Playlists are in a random order. Since I use it for listening to Talking Books this makes it useless. How can I control the order of a Smart Playlist?

    Since I upgraded to IOS5, my Smart Playlists are in a random order. Since I use it for listening to Talking Books this makes it useless. How can I control the order of a Smart Playlist?

    It may be best to recreate the folder and the smart playlists from scratch.
    tt2

  • How can I control the order of iDVD menu items using the Arrow keys?

    I have a submenu screen containing 10 selectable buttons plus the Return Arrow button.  I have ordered all the slideshows in the correct order in the DVD map.  However, when I run the program, the arrow keys jump the selection focus in an apparently random sequence.  How can I control the order of the selection focus?
    I'm using iDVD v 7.1.2
    TIA.
    Ron

    Hi
    There is one thing You might miss in iDVD - So do I - the ability to re-arrange in the DVD map (block diagram)
    The order things will be pplayed or addrssed is same as the order each item is introduced into iDVD.
    To my knowledge ther is no way around this.
    Yours Bengt W

  • How to control the order in which records get indexed

    Hi,
    I like to control the order in which the ATG (10.1.2) product records get indexed in Endeca (3.1.1). I like the products/categories to be indexed in the order in which they are sequenced in BCC (in otherwords baseed on the sequence num they have). How to do this? Please help

    If you want TopLink to set the values in a particular order you can order the mappings on a descriptor by setting their ‘weight’ (DatabaseMapping.setWeight(int). All DirectToField type mappings are defaulted to a weight of 1 and all relationship mappings are defaulted to a weight of MAX_INTEGER. Mappings with a lower weight value will be processed first by TopLink.
    --Gordon

  • Problems with the order

    once more I have problems with the order in iTunes:
    Titel number 8 is on top and the first one is on place 10. The only difference in the information is
    Titel number 8 has titel number 8 and the titel on place 10 has the titelnumber 1, all the other informations are eqaul..
    See the screenshots:

    applewoi wrote:
    the album has got 17 files in 2 CDs. Shall I write therefore
    Titelnummer
    1 von 17
    2 von 17
    and so on?
    all in 1 CD
    I suggest you set
    CD-Nummer
    1 von 2
    2 von 2
    Then the tracks
    CD-Nummer 1
    Titelnummer
    1 von 9 (or however many tracks there are per CD)
    2 von 9
    CD-Nummer 2
    Titelnummer
    1 von 8
    2 von 8

  • How do I control the order of files as written to the LST file of FileNameGet command with multiple files

    The UseFileCommand is not loading my files in alphabetical order...nor in timestamp order...nor in the order I select them in the FileNameGet dialog box.
    How do I control this?
    It appears that the LST file created is where the problem lies.  The UseFileList variable, it appears, reads from the last entry, and works forward.
    So I need a way to manage this..so that my data is processed according to the timestamp (earliest first) OR filename (alphanumeric sort, ascending)
    Thanks

    Hmm, seems I did a better search this morning...and came across the following....
    Previous sort request
    Maybe an enhancement? 
    In my case, the issue is I'm trying to process multtiple data files collected over 6 months of durability testing.  Out of the risk of losing data, our DAQ team has elected to open a new file every hour.  So, I end up with thousands of files.
    I parse through these files, calculating time between various events.  Its CRITICAL that the calculations are in time-order.  The files each 1 Gb in size, so I prefer to utilize the filename (date/time sortable) or original timestamp.
    If processed out of order, the durability data will likley imply something quite wierd (like improvement over time).  Of course, that would be great for a management review...but not so good when warranty starts coming back
    I can write/copy any number of sort routines...I just thought the file order should be intuitive (either forward or reverse...not last, first, middle, etc...
    Anyhow...I'd like to formally request an enhacement in the next ve.  rsion of Diadem; one that provides an additional parameter to be passed...SortField.  Useful options would include FileNameForward, FilenameReverse, TimeForward, TimeReverse, etc...

  • Problem with the order of inserted PDFs...

    I work with archiving records in chronological order and am having problems getting the files to insert correctly. When I go to insert files, everything is fine when only one file is being inserted. Also what works fine is if I'm trying to insert multiple files that are already in order (by using the Shift key to select them all at the same time) - i.e. file1, file2, file3 - and I know that I can select the last one first to invert the order - i.e. file3, file2, file1. The problem I'm having is if I'm trying to insert file3, file1, then file2 without having to do multiple insertions. Obviously this isn't a issue when dealing w/ 3 out of order, but not 10+. I have tried using the Control key to select them in order but the order is ALWAYS messed up when I hit OK.
    Thanks to anyone that can solve my problem.
    -Lance

    Don't think there is anything you can do about that, unless you write a script or something. The ordering is typically set by the way they appear, not the order you select them. Some people have more success dragging from Explorer into Acrobat, rather than using insert pages. However, you are still stuck with the order the of the files in the window, not the order you select them. To the best of my knowledge, there is no way to change this behavior. Using a script are such is the only way I can think that what you want might be done.

  • Any way to control the order in which data is exported?

    I found it surprisingly easy to set up a form to submit its contents via a formmail script -- perhaps too easy...
    Using Acrobat 9 (and the demo version of Acrobat X), I've modified a form that students fill out so that when they hit the submit button it pushes the form contents to a script which relays it to an e-mail address specified on the form -- no problems there.
    But the order in which those fields are listed in the e-mail bears no relation to the order the fields appear in the form -- or alphabetical order of the field names or data values or the tab order. It's the same order every time. And as far as I can tell the mailing script isn't doing anything to change the order of the data.
    This is mostly an issue of making the e-mail friendly for the supervisor who has to look at the e-mails as they come in. (I've done a number of searches on Google and here in the forums before posting and haven't found any references to similar problems, so maybe I do have a funky script.)
    I'm wondering if a) there's something native to the form that could change the order of the data and b) there's some straightforward way of controlling that. (I imagine I could write some JavaScript to control the output I had to, but it seems like a needless step.)
    Thanks for any insight anyone can provide.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    A solution would be to modify the server script to output in the order you want, as opposed to just looping over the collection of fields present in the incoming data as formmail type scripts typically do.
    That is what I wound up doing -- making a copy of the mailing script and reformatting the message body string to contain just the data responses my colleage wanted in the order he wanted. It beats the old method of requiring users to fill out the PDF, save the document and then e-mail in the PDF as an attachment.

  • How can you control the order of video tracks?

    I have an iDVD project with an intro movie (movie played when the disc is first inserted), 5 20 minutes videos (each of which is an individual iMovie project with chapter markers, but the videos are meant to be watched in order 1, 2, 3, 4, then 5), and an addition 5 minute video. When I created the disk image, I noticed it started encoding the last of the 20 minute videos and then seemed to encode the rest of the videos in random order.
    I burned the disk image to DVD and started watching it in my DVD player. When you watch the first 20 minute video, when it finishes you return to the menu so you can choose the second 20 minute video. But, if you scene skip through a 20 minute video on the last scene, it takes you to the next track. The problem is the tracks are all in random order. So instead of scene skipping to the next 20 minute video, it takes me to the intro video, then to 20 minute video, ect. It's all out of order.
    My question is does anyone know how to control track order? Is the track order the order in which the videos are encoded? (It seems to that is the case.) I tried inserting the videos into the iDVD project in the order I wanted them, but I don't know if that will work or not. The assets all appear in random order in the Project Info window.

    I would like to know also. I have made many DVDs, but the number order does seem to be random. For presentation purposes I want to play a specific clip by hitting it's corresponding number on the DVD player remote when the DVD is at a complete stop (so if I put the movie clip in the 2 spot and hit the number 2 on the remote, then the 2 movie clip will play). I can get this to work from the menu by dropping them in iDVD in the order I want and waiting for each to encode before dropping the next, but at a complete stop I cannot ensure number 2 on the remote will play number 2 on the DVD. To me it looks like iDVD gives those numbers in the order in which the audio is encoded when burning, with the shorter clips first and longer ones last.
    Can anyone help me?

  • How can I control the order of photos in a Ravel slideshow?

    I'm using the web version.  After I uploaded my photos, I discovered that Ravel does not display them in alphanumeric file name order.  Instead it appears to order them by file date.  Unfortunately, I have always altered the file name to set up the order of my photos.  In the future, if I use PhotoShop to manually alter the date of the jpeg files, and then upload them, will Ravel "see" the altered date and change the order?  I've used up my upload limit, so I can't just try it and see.
    On a slide note, I tried the method of sharing an album on PC as described in the Adobe FAQ, and it worked pretty well.  Two minor things I'd add:  (1) You have to first click the URL field before the copy, and (2) the URL includes two non-functional characters at the end (#!) that can be deleted from the e-mail.

    Yes, as you noticed, the only option for Revel is to sort by date.  If you change the date that the photo was taken, it will indeed change the order.  This is something you can also do within the Revel app, though not currently with the web version you are using.

Maybe you are looking for