Don't clone list objects, just parent

I have a need to create an object and add it to the parent list. I am currently doing it like this.
UnitOfWork uow = session.acquireUnitOfWork();
MyChild newChildClone = uow.newInstance(MyChild.class);
MyParent parentClone = uow.registerObject(parent);
newChildClone.setParent(parentClone);
parentClone.getChildren().add(newChildClone);
uow.commit();This clones all of the existing children of the parent, because they are loaded from the parentClone. How can I add the new child to the list without cloning all of the existing children?

Probably best to not worry that much about it.
If the collection is really large you may consider,
- If you use weaving (such as when using JPA and an agent, but also usable in the native API with some effort), and use attribute change tracking (default with weaving) and lazy,
then the add() will not trigger the collection to be instantiated. (must be using EclipseLink for this)
- Otherwise, you could just not add it, and either assume the collection is not instantiated, or refresh the object or invalidate the object after the commit.
- Or just don't map the OneToMany relationship if you really never want to instantiate it, just query for it if you really need it.
James : http://www.eclipselink.org : http://en.wikibooks.org/wiki/Java_Persistence

Similar Messages

  • List Object or Just List which is better ?

    Hi Guys,
    List<Object> list1 = new ArrayList<Object>();
    List list2 = new ArrayList();Logically speaking, both looks similiar. But which one is better to use ?
    I can do something like
    list1 = list2; OR
    list2 = list1; but if List<String> list3 = new ArrayList<String>();Why I can not do this list1 = list3; // throws compilation error Thanks,
    javaCrazy

    javaCrazy wrote:
    List<Object> list1 = new ArrayList<Object>(); This is senseless. Inside the braces an appropriate Interface should be used.
    but if List<String> list3 = new ArrayList<String>(); Why I can not do this list1 = list3; // throws compilation error
    If you declare <tt>List<String> list3 = new ArrayList<String>();</tt> you explicity state that the List will only contain Strings (or types that inherit from the declared type, but String cannot be subclassed), list1 is declared to contain objects of a different kind. Usually the interface of the type list1 is declare will not match with the interface declared for the elements in list3. Since Object is the root of all classes this is a weird exception... Thats why the compiler prohibits this assignment. If you really need such assignment look for the use of wildcards.
    bye
    TPD

  • Nested list object setters

    I have a <nested:iterate> tag for a List of objects to provide table-like editing capabilities to their attributes (all within a <html:form> tag), which works fine. Some of those attributes are other objects though and while the getters work fine, when submitting the form the setters don't take (no errors, just doesn't set). Code looks something like this:
    <nested:iterate id="idproperty" property="sampleproperty">
    <nested:text name="idproperty" indexed="true" property="property1" />
    <nested:nest property="property2" >
    <nested:text property="nestedproperty" />
    </nested:nest>
    </nested:iterate>
    So here property1 gets and sets fine and property2.nestedproperty gets fine, but any changes are ignored. Anyone do deep sets on properties in objects that are part of a List? Thanks.

    Hi ,
    I found solution be Searching SDN
    Untill you do this the FM wont know which internal table is getting displayed, when it does not find anythinG , it defaults it to 1. thats why it works.
    Make Sure the field catalog fieldcat-tabname         = '1'.
    You can see it in debugging mode.
    Thanks
    David

  • An alert messarge i don't underdant: insane object at BDHP + 83ACC in "VI name's":{graphics} (0x80):Front Panel Terminal (Term)

    Hello!
    I don't know why in just yesterday appear in one of my VI an alert message or error message when i want to close oer save the VI.
    The message is like the following one:
    Insane object at BDHP + 93ACC in "Vi name's": {graphics} (0x80}: Front Panel Terminal   (Term)
    I don't know why now it appears this message because i have no modify the Vi.
    I want to ask you why it appears this message and the most important......how can i solve it?
    Thank you very much
    Larson

    Hi!!! I copy and paste from an NI engineer post asking about what is the "insane object" problem:
    This message means that an object in LabVIEW such as a wire or a loop tunnel does not pass an internal test known as a sanity check. If the errors are serious enough, LabVIEW exits because something has become very corrupted. Sanity checks occur before each save, to ensure that corrupted VIs are not written over good VIs. They also happen as part of the compile process. Thus, sanity checks happen frequently. Many insanities are actually fixed (made sane) after the dialog box appears and will not appear again, so the first thing you should do after receiving an insane object error is to try to make a backup copy of the VI, run it, and perform some additional editing to see if the problem was resolved automatically.
    VI corruptions do not happen often. They can happen because of disk corruption, but this will often lead to a file that can no longer be loaded. Corruptions can also happen because the programmer did something that corrupts a LabVIEW data type, perhaps as the result of a call to external code. The following are examples of insane object errors:
    Insane Object at BDHP+4D50 in 'sksks.vi': (graphics) (0x80):wire segment (WIRE)
    Insane Object at BDHP+5CA0 in "CAPL3.vi": (graphics) (0x80):loop tunnel (DCO)
    In the first example above, the error message itself gives information about which object is insane. BDHP means the offending object exists on the block diagram heap, as opposed to the FPHP for front panel heap. The +4D50 is the hex offset in the heap where the object is located. The "Wire Segment" text indicates that the object is a wire object. The "graphics" text indicates that the insanity is graphics-related, which means it is not serious and will most likely be repaired automatically.
    The second message above is similar, but refers to a loop tunnel (i.e., the tunnel formed where a wire crosses the edge of a loop) rather than a wire.
    Solution: If you receive an insane object message, it is best to delete and recreate the most recently created objects on either the front panel or block diagram, depending on whether the error message contains "FPHP" or "BDHP". Make use of the text in the error message in deciding which objects to rebuild. In the case of the second message above, it would be best to delete and recreate the most recently created loop tunnels.
    Another workaround that works best if the VI is small is to select the entire diagram and copy it to a new VI. After saving the new VI, there is a good chance the insane object error will no longer appear. If the VI is too large to cut and paste to a new VI and another computer with an identical version of LabVIEW is available, you can copy the VI to disk (or to your network if that is available) and open it on the second machine. If the insane object errors do not appear, save the VI (on the second machine) and transfer it back to the original PC (by disk or by network). The new, uncorrupted version of the VI should now run without generating the insane object error.
    Hope that helps you,
    Jaime
    Regards,
    Jaime Cabrera
    NI Applications Engineering Spain

  • Call Transaction from Excel VBA macro and download ALV list object results

    I have a situation that must be very common u2013 but I canu2019t find any clear information on how to get it done! 
    We frequently run SAP transactions, download the results (orders or inventory) into Excel, do some calculations and create a spreadsheet report. 
    I would like to automate this process using Excel VBA so that a macro will perform these steps:
    1. Run our custom SAP report "YSD033" that summarizes orders using the previous day as the [From Date] parameter.  (The user already has an active ECC 6 R3 session running.)   If possible, can the TC be run using a specific variant "G111BIZ" ?
    2. Download the list object that appears in an ALV grid as a table to an empty spreadsheet in the active workbook (export XXL list object)
    3. Save the resulting workbook and close Excel.
    Should the solution use u201Ccall transactionu201D or a GuiXT script?
    Any help would be much appreciated, and some sample VBA code would be great!
    Thanks.
    Glenn

    Good suggestion, but
    I get "permission denied" for   SapGuiAuto.GetScriptingEngine
    I also tried the method below, but received this RFC error message:
    User PPPPPPP  has no RFC authorization for function group SYST.
    Sub LoginCheck()
    If login = False Then
        ' Setting the necessary variables for R/3 connection
        Set objBAPICortrol = CreateObject("SAP.Functions")
        Set objConnection = objBAPICortrol.Connection
        ' Establish a connection
    If objConnection.Logon(0, False) Then
        login = True
        MsgBox "Connection Established"
        CommandButton1.Caption = "Disconnect"
    End If
    Else
        CommandButton1.Caption = "Connect 2 SAP"
        login = False
        objConnection.Logoff
        Set objConnection = Nothing
        Set objBAPICortrol = Nothing
    End If
    End Sub
    I was told that these kinds of authority open up too big of a window that can't be monitored adequately...
    I'm considering an approach like what is below if I can't convince security to grant me permissions...
        Application.Wait Now + TimeValue("00:00:01")
        SendKeys EnterKey, False
    Since blocked RFC security settings are preventing the solution from being installed, I am markgin this question as answered. 
    I will post different questions about 1. how to convince the security team that it will be safe to allow the use of RFC calls, and /or 2. how use some windows-level scripting code to run the SAP jobs.
    Thanks.
    Edited by: GlennWebster on Mar 1, 2010 4:34 PM

  • LINQ sorting on List Object - Various Object Type

    I try to sort a List<Object> where the Object are different classes but all share the same Property Name for instance.
    I got a Base Class where Class A and Class B inherit from the Base Class.
    So during the Linq query I cannot specify with object type this is.
    Problem here "from ?????Entry_Global?????? list in Entries"
    Thanks for helping.
    ////Entries is a List<Object> which consist of class object as following\\\\\
    public abstract class EntryBase<T>
    private string _Name;
    public string Name
    get { return this._Name; }
    set { this.SetProperty(ref this._Name, value); }
    public class Entry_Global : EntryBase<Entry_Global>
    public class Entry_CC : EntryBase<Entry_CC>
    private string _url; //Web url
    public string Url
    get { return this._url; }
    set { this.SetProperty(ref this._url, value.Contains("http") ? value : "http://" + value); }
    public List<Object> SortBy()
    IEnumerable<KeyedList<string, object>> groupedEntryList = null;
    //The proble reside in the fact that list is not only one type
    //so when comes in the orderby "Name" it doesn't know Name
    //or any other properties which are all common to all those class
    //It does not want to convert Entry_CC or Entry_Global to EntryBase
    groupedEntryList =
    from ?????Entry_Global?????? list in Entries
    orderby list.Name
    orderby list.CategoryRef.Name
    group list by list.CategoryRef.Name into listByGroup
    select new KeyedList<string, object>(listByGroup);
    return groupedEntryList.ToList<object>();

    Entry_Global and Entry_CC don't share the same base class since EntryBase<Entry_Global> and EntryBase<Entry_CC> are two totally different types so you cannot cast the objects in the List<object> to a common base class in this case.
    You could cast from object to dynamic though:
    public List<Object> SortBy()
    List<object> objects = new List<object>();
    objects.Add(new Entry_Global { Name = "K" });
    objects.Add(new Entry_CC { Name = "A" });
    objects.Add(new Entry_Global { Name = "I" });
    objects.Add(new Entry_CC { Name = "C" });
    var sortedObjectsByName = (from o in objects
    let t = (dynamic)o
    orderby t.Name
    select o).ToList();
    return sortedObjectsByName;
    The dynamic keyword makes a type bypass static type checking at compile-time:
    https://msdn.microsoft.com/en-us/library/dd264736.aspx. This basically means that a dynamic type is considered to have any property of any name at compile time. Of course you will get an exception at runtime if the type doesn't have a Name property but
    providied that all objects in the List<T> to be sorted are of type EntryBase<T> you will be safe as long as the EntryBase<T> type defines the Name property that you sort by.
    Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

  • Remove duplicates for list object

    Hi,
    I have retrieved all the xml node values in List<object>. Now, I want to remove all the duplicates objects from that list.
    Example:
    If the object has n properties, I should remove only duplicate objects that have same values in all the n properties not just one property as ID or name. Please let me know how to achieve this. Preferably using LINQ. 
    Thank you.
    Regards,
    Kiran

    You can use a GroupBy.  I took the code from last posting
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    using System.IO;
    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    string file1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
    "<Methods>" +
    "<Method>" +
    "<ID>1234</ID>" +
    "<Name>manager</Name>" +
    "<Path>path1</Path>" +
    "</Method>" +
    "<Method>" +
    "<ID>5678</ID>" +
    "<Name>manager</Name>" +
    "<Path>path2</Path>" +
    "</Method>" +
    "<Method>" +
    "<ID>5678</ID>" +
    "<Name>manager</Name>" +
    "<Path>path2</Path>" +
    "</Method>" +
    "</Methods>";
    string file2 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
    "<Methods>" +
    "<Method>" +
    "<Path>path1</Path>" +
    "<Description>text</Description>" +
    "</Method>" +
    "<Method>" +
    "<Path>path2</Path>" +
    "<Description>text</Description>" +
    "</Method>" +
    "</Methods>";
    string file3 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
    "<Methods>" +
    "</Methods>";
    StringReader reader = new StringReader(file1);
    XDocument doc1 = XDocument.Load(reader);
    reader = new StringReader(file2);
    XDocument doc2 = XDocument.Load(reader);
    reader = new StringReader(file3);
    XDocument newXDoc = XDocument.Load(reader);
    var results = from e1 in doc1.Descendants().Elements("Method")
    join e2 in doc2.Descendants().Elements("Method")
    on e1.Element("Path").Value equals e2.Element("Path").Value
    select new XElement("Method", new object[] { e1.Element("ID"), e1.Element("Name"), e2.Element("Description") });
    var results2 = results.AsEnumerable()
    .GroupBy(x => x.Element("ID").Value);
    var results3 = results2.AsEnumerable()
    .Select(x => x.Take(1));
    newXDoc.Descendants("Methods").Last().Add(results3);
    jdweng

  • Clone an Object

    Hey everyone,
    I just had a question about cloning an object.
    I have an object and within that object there is a field that holds a "date".
    I want to clone the object x number of times (x is user input) and each clone the "date" is the next day.
    So the second clone's "date" value would be the next day after the first clone's "date" value. I also want each clone stored into an array of that object.
    I have a date class and within that date class is a method called "nextDay" which changes the date to the next day.
    I hope that makes sense.
    Anyways, the way I went about it was this:
    Object original = new Object();
    drawCount = user input;
    Object[] array = new Object[drawCount];
    array[0] = original;
    if(drawCountInt > 1)
         for(int j = 1;j <= drawCountInt;j++)
            Object daClone = (Object) original.clone;
            daClone.date = daClone.date.nextDay();
    }Now that seems like it would work once.
    I am trying to figure out, how would I increment the date in a loop?
    I could not figure out a way to use the counter to maybe make the nextDay happen more often.
    I could not also find a way to make a clone of a clone inside a loop and just use the nextDay on that.
    How would I make a clone off the latest clone inside a for or while loop?
    Sorry if any of this seems a little unclear. Feel free to ask questions of course.

    So something like this then?
    if(drawCountInt > 1)
    {     Array[1] = (Object) original.clone;
             for(int j = 1;j <= drawCount;j++)
                       Array[j] = (Objectt) Array[j].clone;
                       Array[j].date = Array[j].date.nextDay();
    }

  • Save XXL list object in SAPoffice issue

    Hello,
    One of my user recently got a new laptop and after that, whenever she used KSB1 to do the export to excel as pivot, she is getting the below option "Save XXL list object in SAPoffice". She is not getting the pivot table option. I tried to find her entry in report "SALV_BS_ADMIN_MAINTAIN" to delete, but, I could not find her entry. Also, she tried to test the same on another laptop too, there also she is getting the same error. I am not sure if it a Profile issue or GUI issue. Please suggest. Also, she maintained her profile with parameter "SALV_BS_ADMIN_XXL". I am not sure if it is a problem.
    Thanks.

    It's not an authority issue that SAP_ALL/SAP_NEW would fix either.  That 'error' happens when the XXL code can't find the correct version of Excel that it expects from the registry.  It behaves as if Excel is not installed and pops the SAPOffice document prompt.  Debug the XXL code from the laptop and you'll see what I mean  (or just from your PC to view the logic).

  • Large Database read into a List Object Memory Problem

    Hi,
    Im building a new database, ive just imported over 50,000 rows into the database across a number of tables from existing csv files.
    I want to extract these rows into a List object. Once extracted i want to process them in a specific way. However when i try to read in over 20,000 rows i get an error which indicates the buffer is full
    java.lang.OutOfMemoryError: Java heap space
            at java.nio.ByteBuffer.wrap(ByteBuffer.java:350)Im currently using the DAO design pattern to read in the values. Could anyone provide me with some advise how i might read in so many rows without running out of memory. The current process is not only failing but is also extreamly slow.
    Thanks in advance

    h1400046 wrote:
    Hi,
    Thanks for your reply,
    This database is fully normalised. Five tables, no relations between them at all.
    The DAO design pattern was chosen so that each table may be selected individually. DAO usually means objects to me. What you're describing sounds more like Table Gateway.
    This means that i get the values from each table in turn. (there isnt a single query). No possibility to JOIN? None whatsoever?
    Five tables must be read for each select. Ouch.
    Therefore i am selecting 5 times for each of the 50,000 rows and some of the rows will bring back more than one record for each table. So it's one object that has references to five others.
    This OO object is tread back into a List object. Once i have this i want to then process this list as a whole. However this obejct gets to big and just kills the memoryYes, that's been clear all along.
    I have been told that jdbc supports a cursor type mechanism which enables you to read from a result set in manageable chunks which can then be processed chunk by chunk without killing the memory. But i dont know how to do that or even if that is advisable.Yes, you can process chunk by chunk with JDBC. Check setFetchSize(), or manage the chunk size yourself.
    I currently have primary keys in each table. I have indexs on both the primary and forigen keysSo there are relationships. I'll ask again - why not JOIN?
    Can the database do any of the processing? What about calling a stored proc to create a cursor and iterate through the data on the server? Just bring the result over via JDBC.
    %

  • How to Clone  inherited Object ?

    According to the rule of cloning a object can be cloned only if
    it implements Cloneable interface ? In the following example
    class B extends class A which does not implement Cloneable interface,class B does implement Cloneable interface.
    when I try to clone an object of class A in class B it is very
    allowing to be cloned which is a contradictary?Please go through the
    example and suggest what is wrong ?
    class A
    int v = 100;
    public Object Clone()
    return new A();
    class B extends A implements Cloneable
    public static void main(String args[])
    A a = new A();
    A b = null;
    b = (A)a.clone();
    System.out.println("Value of v1 :" +a.v1);
    System.out.println("Value of v1 :" +b.v1);
    Thanks for your valuable help

    According to the rule of cloning a object can be
    cloned only if
    it implements Cloneable interface ? In the following
    example
    class B extends class A which does not implement
    Cloneable interface,class B does implement Cloneable
    interface.
    when I try to clone an object of class A in class B it
    is very
    allowing to be cloned which is a contradictary?Please
    go through the
    example and suggest what is wrong ?
    class A
    int v = 100;
    public Object Clone()
    return new A();
    class B extends A implements Cloneable
    public static void main(String args[])
    A a = new A();
    A b = null;
    b = (A)a.clone();
    System.out.println("Value of v1 :" +a.v1);
    System.out.println("Value of v1 :" +b.v1);
    Thanks for your valuable helpApart the fact that like that program cannot function, you didn't clone anything. You've just created another instance of class A!
    Cloning means to create a copy of an existing object with aonother one having exact members (name, value, behaviour) like the first one!
    Try to replace this piece of code:
    A a = new A();
    a.v = 500;
    A b = null;
    b = (A)a.clone();
    System.out.println("Value of a.v :" +a.v);
    System.out.println("Value of b.v :" +b.v);
    and write "Clone" method like this: "clone". See that you'll obtain:
    Value of a.v :500
    Value of a.v :100
    good luck!
    m

  • HT204150 My contacts on my iphone haven't synchronised with my address book on my MAc. Have done every remedy listed and it still doesnt work. Any ideas?

    My contacts on my iphone haven't synchronised with my address book on my MAc. Have done every remedy listed and it still doesnt work. Any ideas?

    The way iCloud works is that it isn't actually 'syncing', though this is how it's often referred to. The data lives on the iCloud server and is read from there by the various devices (just like webmail). Therefore when you make a change on your iPhone you are actually changing the iCloud website (there is an internal procedure to allow you to make the changes while you are offline, and they are then changed on the site when you next connect).
    Therefore any device whose changes appear on the iCloud site, and who can read changes on the site made by other devices, is working: and any device whose changes do not appear, and which cannot receive changes made by other devices which have appeared on the site, is failing to connect. This appears to be the issue with your Mac.
    When this happens, sometimes signing out and in again resets the whole setup and corrects the problem. If another device such as your iPhone is connecting to the iCloud server correctly then nothing you do on it will affect your Mac. (In fact even if it isn't connecting it has no effect on your Mac, only on its own ability to transmit changes to the iCloud server).

  • I keep being asked to update my Safari but when I do a Software update it scans but never gives me a list and just says no new updates. Help please!

    I keep being asked to update my Safari but when I do a Software update it scans but never gives me a list and just says no new updates. Help please!

    There are no updates to either OS 10.5.8 or Safari 5.0.6.
    If you need a later version of Safari you must first upgrade your operating system to a later version of OS X.

  • I need a new power cord for my Mac book Pro its the T type mag connector. I don't need a Tech just a new cord. How do I buy one. The closest Aplle store is 75 miles away and I do not drive.

    I need a new power cord for my Mac book Pro its the T type mag connector. I don't need a Tech just a new cord. How do I buy one. The closest Aplle store is 75 miles away and I do not drive.

    Are you in the US? Order one from here:  http://store.apple.com/us/browse/home/shop_mac/mac_accessories/power?mco=MTM3NjU xNDg
    Or check out Best Buy.

  • I am trying to use the locate my macbook that was stolen. How do I know if it is set up on the service. It shows on the list but just says it is offline and doesn't say when or where it last was. I am trying to either locate it or erase it. HELP

    I am trying to use the locate my macbook that was stolen. How do I know if it is set up on the service. It shows on the list but just says it is offline and doesn't say when or where it last was. I am trying to either locate it or erase it. HELP

    Since you can see it in your device list it must have Find My Mac activated, but you're going to have to wait for them to take it online in order to either locate, lock or wipe it. Until it goes online you can't do anything. http://www.apple.com/support/icloud/find-my-device/
    iCloud: Locate your device

Maybe you are looking for