Clarification regarding deep cloning/deep copy

Hi,
While performing deep copy of an object should all the subobject that the parent object constitute also constitute the clone method.
For Eg:
I have a class called Document and a class called Field. Document constitutes of List<Field> fields. Field class has a String fieldName as its member variable.
I need to perform a deep copy of Document object. Should Field class also implement the clone method or can I create field objects in the documents clone method and fill these fields with values from the existing field list to form a new Document with these new fields.
Or do I call clone() method on each field to get a new field object and
add it to the new Document object that I am creating in the clone() method .
//First approach
public Document clone(){
Document doc = new Document();
List<Field> fields = doc.getFields()
Field newField = null;
for(Field f: fields){
    newField = new Field();
    newField.setName(f.getName());
   doc.addField(newField);
return doc;
//Second Approach
public Document clone(){
Document doc = new Document();
List<Field> fields = doc.getFields()
Field newField = null;
for(Field f: fields){
    newField = f.clone()
   doc.addField(newField);
return doc;
}Please let me know which is a better approach and the standard coding
practise.
Thanks

the second method is better, because it lets you the possibility to create a subclass of Field with a specific clone method, integrate some instances in a Document object; without changing the Document.clone method.

Similar Messages

  • Problem in deep cloning

    Hai Friends,
    I am trying to use deep cloneing for copying objects and then setting the appropriate values to the properties of copied object. When we make deep clone copy, it is supposed to retain original property values. But in the example I tried, it shows only zeros. The source code and the output is given below. i seek your expertise and my advance thanks for any help to resolve my problem.
    * This class extends the class of Javas Point2D.Double
    import java.awt.geom.Point2D;
    import java.awt.Rectangle;
    import java.io.Serializable;
    import java.awt.Graphics2D;
    import javax.swing.JFrame;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.geom.AffineTransform;
    import java.util.ArrayList;
    import java.io.Serializable;
    import java.io.ObjectInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.ObjectOutputStream;
    import java.io.ByteArrayInputStream;
    import java.lang.ClassNotFoundException;
    import java.io.IOException;
    public class point2D extends Point2D.Double implements Cloneable, Serializable{
    // Properties
         Color drawColor =Color.red;
    * Constructor
    point2D(){ }
    point2D( double xx, double yy){ super(xx,yy); }
    public void setLocation( double xx, double yy){
         super.setLocation(xx,yy);}
    public void setDrawColor( Color drawColor){
         drawColor = this.drawColor;}
    * Draw a rectangle around through point.
    public Rectangle getPointRect(){
    int width = 4;
    return new Rectangle( (int)x-width/2,(int)y-width/2, width, width);
    * Check for a given point coinciding with point2D
    * location check is true, if it contains the point
    public boolean locationCheck( double x, double y){
         return getPointRect().contains((int)x,(int)y);
    * Draw method.
    public void draw( Graphics2D g2d ){
         g2d.setColor(drawColor);
    g2d.fill( getPointRect());
    public Object deepClone()
    try{
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(b);
    out.writeObject(this);
    out.close();
    ByteArrayInputStream bIn = new ByteArrayInputStream(b.toByteArray());
    ObjectInputStream oi = new ObjectInputStream(bIn);
    oi.close();
    return oi.readObject();
    catch (IOException e)
    { System.out.println("exception:"+e.getMessage());
    e.printStackTrace();
    return null;
    catch( ClassNotFoundException cnfe){
    System.out.println("exception:"+ cnfe.getMessage());
    cnfe.printStackTrace();
    return null;}          
    public static void main( String[] args){
         point2D pp = new point2D();
         pp.setLocation( 100.,150.);
         System.out.println( pp.locationCheck(100.5, 149.5));
    System.out.println( pp.getX() + " " + pp.getY());
         point2D ppp = (point2D)pp.deepClone();
    System.out.println( ppp.getX() + " " + ppp.getY());
    The output:
    true
    100.0 150.0
    0.0 0.0

    Hai sztejkat,
    I tried with adding methods to save and restore the state of the non-serializable class and it works.
    What is the reason to implement deep clone in point2D - this class does not contain any references >except Color, which is an immutable class and can be safely shared by multiple objects. In this case the >shallow copy will work fine. In my opinion the method you have choosen to implement deep copy is one >of the worst possible, looking from performance point of view. Shallow copy makes a new reference but pointing to the same object. My intension of deep copying was to create a new object. However, I fully agree with you that for simple instances of Point2D.Double, it is better to create a new onject using " new" operator than deepcopying.
    With best regards,
    Chinnaswamy

  • Deep Cloning problem

    I am having problems deep cloning a LinkedList object which contains serializable objects. I have tried using hand coded deep cloning and using the byteArray output and input streams.
    But nothing is working :(.
    My code currently looks like this:
    public LinkedList clones(LinkedList list){
       LinkedList deepCopy = new LinkedList();
       for(int x = 0; x < list.size(); x++){
          myClasstemp = new myClass((materials)list.get(x));
          deepCopy.add(new myClass(temp));
       return deepCopy;
    }cloning using just new myClass works when I am using individual objects, but when I try applying this to the new linkedlist, nothing happens. Is my error in the fact I am using .get? Or is it somewhere else in my code?
    My problem is that when I remove an object from the original LinkedList, the deepclone is changed as well.
    Message was edited by:
    DocterJ0208

    to be as detailed as possible, my problem is that I actually have 2 classes. One class is a structure object which contains basic properties like doubles and strings. And the other has doubles and strings as well and includes a LinkedList containing objects from the first class. To for an example, I have a student and School class where a School object contains a LinkedList holding all the students at the school.
    What I am trying to do is make a Cancel button. So, what I want is to make a copy of the original school, so if while editing the school, I decide I want to revert back to my original settings, I can by pressing the cancel button. So far, I can only accomplish this with the student class but not the School class. Does that make sense?

  • Deep Cloning of resultset object

    Hi, Is it possinble? Deep Cloning of resultset object?
    Resltset rs = pstmt.execute()
    Anyway to assign rs2 = rs1
    Because I am passing my resulset to a legacy application's method, that does a rs.close(). I need to use the same resultset later. JDK 1.4

    Write a dynamic proxy to the ResultSet where theclose() method does >nothing.
    What if the OP discovers that the app does a rs=null
    as well?How can that affect your code? Presumably the ResultSet is passed as an argument to a legacy method so the legacy method might set it's local reference to null it will not affect the reference held by the caller of the method.
    The op then runs thru hoops to get permission to
    modify a line in legacy code and is too distressed to
    post.He does not need to! You need to learn about Java argument passing.
    Anyway, thanks for the classrom solution. but i cant
    create another class file for extending rs.You have not presented any reason why not! This can be an inner class in the code you are writing and has no influence what so ever on the legacy application.
    >
    If you are too distressed by the posts here, you are
    under no obligation to reply to every one. Anyway , i
    found the postI replied because I had a viable solution to a problem you were having. Nothing you have said so far stops it being viable. Look at my posting history - I do not try to reply to everyone.
    >
    A Resultset is mainly a Java front end for adatabase
    cursor (which exists on the database server). When
    the ResultSet is closed, the cursor will be closed
    too so, even if you could copy everything in the
    ResultSet object, the handle for the cursor wouldno
    longer be valid.
    Which is why you use a Proxy so that you can control exactly what happens.
    >>
    To truely "deep copy" a resultset the depth would
    have to extend accros the database connection to
    cloning the cursor.I still don't see why you need to clone the ResultSet rather than use a proxy!
    >
    very much useful than the self pity expressed by
    you.No self pity! I just expressed annoyance at the lack of feedback from you and many others.
    No offence, none taken and none dealt.I still find it offensive when people don't bother with a simple acknowledgement. I don't ask many questions myself but when I do I make sure I track the responses and acknowledge those who try to help.
    I still think you should re-think your solution but you are free to totally ignore my very simple solution. I expect you will ignore it so the best of luck.

  • Generic class for deep cloning

    How can I write generic class for deep cloning instead of implementing cloneable for each and every object

    Yes, probably you'd need to use reflection. Though, generic deep copy brings up some issues not readily resolvable at run-time, such as, for example, does the object you want to copy refer to a shared or synchronized resource, such as a db connection? If so, by making a new, say, DBConnection object, you then take up a db connection that you really don't need or want to take up (db conns being scarce in many I.T. shops that own a limited number of Oracle or SQL Server, etc. db conn. licenses). Also, many classes these days are getting written that use "obj = classname.newInstance()" (with their constructors made private so you can't use "new SomeObject()") instead of the more commonsense and traditional "obj = new SomeObject()". [Hey, can anyone explain why it might be preferable to use "classname.newInstance()" at times over "new SomeObject()"?  I can't to this day tell why it might be better or why some hacks have started doing this.]
    I am not saying either that you couldn't do it or that you shouldn't. In fact, if you wrote a really good generic deep copy class, it may very well suit your needs 95+% of the time. It'd be a great programming exercise that would likely result in something very useful to someone somewhere (yourself included), and would get you to really learn the reflect package, time generally well-spent. I also can see how it'd be a great exercise in writing recursive calls (if for example you'd like no limit to the depth of objects created within your deep-copied object). You may need to supply a few caveats for use, such as that there's no guarantee that objects within the object to be copied that don't have public constructors can be copied, and that objects that hold other objects that are limited in availablity due to their very natures, such as db connections, may not get fully copied. Another one may be that no object can be copied as long as a thread created and run from it is executing at the time the copy is done (because you couldn't guarantee the to-be-copied object instance's data or object reference state), or that perhaps in some cases, certain kinds of method-level (ie, what's officially called by Sun, "automatic") variables declared and used within, for example, blocks of code within methods, may not have their values copied correctly if they are not visible to the reflect pkg objects (though I'd have to look into that one myself to be sure it would be an issue).
    Doing a search on "deep copy" or "deep clone" on java.sun.com as well as on the 'net reveals surprisingly little except suggestions for using object serialization to do all the dirty work for you.
    I am surprised there isn't a kind of virtual working group trading ideas on the topic and trying collaboratively to come up with a good, solid generic deep copy class as a public service for all the Java brethren. Does anyone know of one? And if not, wanna start one?

  • Deep cloning

    Hi i need to know how can I make deep cloning of own created array which will store the same array as well as other objects like Integer class and then array at element of array will again store another array or some other objects and then again at any element store array can store objects or array . I need to know how should i make deep cloning recuresively . and how should i write hash code and equals method for that class . please help me. I m feeling fustrated

    As a supplementary issue on this subject I am interested how to choose between the Arrays and the
    ArrayList classes. This thread suggests that Arrays is more versatile, although I usually use an
    ArrayList. Should I review this practice?Sorry. You read the thread incorrectly. :-)
    Arrays and ArrayList are completely different. java.util.Arrays has static methods for dealing with arrays. java.util.ArrayList is like a resizable array. java.util.Collections has static methods that can be used on java.util.ArrayList. Read the APIs, and you will see the difference.

  • Clarification regarding Shadow Table

    Hi All,
    Clarification regarding Shadow Table. FKK_GPSHAD is a shadow table that belongs to Business Partner. The doubts that i have is
    What is Shadow Table?
    What is the purpose of Shadow table?
    Is it correct way to update Shadow table Manually(Not using any BAPi etc....)?
    Is any BAPI available to update The above mentioned Shadow table.
    Thanks in Advance..

    Reclustering InfoCubes:
    With reclustering, the InfoCube fact tables are always completely converted. The system createsshadow tables with a new clustering schema and copies all of the data from the original tables into the shadow tables. As soon as the data is copied, the system creates indexes and the original table replaces the shadow table. After the reclustering request has been successfully completed, both fact tables exist in their original state (name of shadow table) as well as in their modified state with the new clustering schema (name of original table).
    You can only use reclustering for InfoCubes. Reclustering deactivates the active aggregates of the InfoCubes; they are reactivated after the conversion.
    Reclustering DataStore Objects
    Reclustering completely converts the active table of the DataStore object. The system creates a shadow table with a new clustering schema and copies all of the data from the original table into the shadow table. As soon as the data is copied, the system creates indexes and the original table replaces the shadow table. After the reclustering request has been successfully completed, both active tables exist in their original state (name of shadow table) as well as in their modified state with the new clustering schema (name of original table).
    You can only use reclustering for standard DataStore objects and DataStore objects for direct update. You cannot use reclustering for write-optimized DataStore objects. User-defined multidimensional clustering is not available for write-optimized DataStore objects.
    Pls chk this thread:
    Shadow Table?
    http://help.sap.com/saphelp_nw2004s/helpdata/en/47/5cf74153b6ca17e10000000a155106/content.htm
    Hope this helps,
    Reward points...

  • Needs Clarification Regarding Listener.ora file

    I want a clarification regarding listener.ora file I've Listener.ora file and its content look like as:
    # listener.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\listener.ora
    # Generated by Oracle configuration tools.
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
    (PROGRAM = extproc)
    (SID_DESC =
    (GLOBAL_DBNAME = Oracle8)
    (SID_NAME = ORCL)
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1521))
    I can understand every entry in this file accept the following
    *(SID_DESC =*
    *(SID_NAME = PLSExtProc)*
    *(ORACLE_HOME = C:\oracle\product\10.2.0\db_1)*
    *(PROGRAM = extproc)*
    *(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))*
    Although rest of entries refer to network services(Database name) and host address and protocol etc.
    what these above refere to.
    Please clarify me in this.
    Regards,
    D.Abbasi

    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
    (PROGRAM = extproc)
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    that about External Procedure, If you don't use "External Procedure" you can remove it, by the way you should avoid default configure.
    http://download.oracle.com/docs/cd/B19306_01/network.102/b14212/advcfg.htm#sthref1331
    http://download.oracle.com/docs/cd/B19306_01/network.102/b14212/advcfg.htm#NETAG0132
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_extern_proc.htm#sthref1658
    Sample create External Procedure:
    http://surachartopun.com/2008/07/create-and-run-sample-external.html

  • Some clarifications regarding Aironet settings

    Hi,
    i need some clarifications regarding configuring Aironet stand-alone AP (in this case AIR-LAP1131AG).
    Under Security->SSID Manager:
    what is the purpose of Network ID?
    Under Guest Mode/Infrastructure SSID Settings - what is the purpose of Set Infrastructure SSID?
    and Force Infrastructure Devices to associate only to this SSID?
    Cheers,

    Assign a Service Set Identifier (SSID) to each VLAN configured on the AP. SSIDs enable endpoints to select the wireless VLAN they will use for sending and receiving traffic. These wireless VLANs and SSIDs map to wired VLANs. For voice endpoints, this mapping ensures priority queuing treatment and access to the voice VLAN on the wired network
    For further information click this link,
    http://www.cisco.com/en/US/docs/voice_ip_comm/cucm/srnd/4x/42nstrct.html#wp1098806

  • Needs Clarification Regarding Segments and Datafiles

    Hi,
    I want clarification regarding Segments, Datafiles and extents.
    As we know that A segment is made of one or more extents and extents are composed of one or more datablocks in the HD.
    Since all data are store in Datafiles which are composed of extents and datablocks. I want to know weather a table(Segment) can span to multiple datafiles or in a sigle datafile.
    Regards,
    D.Abbasi

    And an easy way to check it by yourself :
    SQL> create tablespace abbasi_tbs
      2  datafile 'E:\ORADATA\DEMO111P\abbasi_01.dbf' size 1m autoextend off,
      3           'E:\ORADATA\DEMO111P\abbasi_02.dbf' size 1m autoextend off;
    Tablespace created.
    SQL> create table abbasi_tbl (id number)
      2  tablespace abbasi_tbs;
    Table created.
    SQL> insert into abbasi_tbl
      2  select rownum as rn
      3  from   dual
      4  connect by level <=10000;
    10000 rows created.
    SQL> commit;
    Commit complete.
    SQL> select distinct file_id
      2  from   dba_extents
      3  where  segment_name ='ABBASI_TBL';
       FILE_ID
             6
             7
    or...
    SQL> select distinct DBMS_ROWID.ROWID_RELATIVE_FNO(rowid)
      2  from   abbasi_tbl;
    DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID)
                                       6
                                       7
    SQL> select file_name from dba_data_files where file_id in (6,7);
    FILE_NAME
    E:\ORADATA\DEMO111P\ABBASI_01.DBF
    E:\ORADATA\DEMO111P\ABBASI_02.DBF
    SQL>Nicolas.
    added the ROWID function usage
    Edited by: N. Gasparotto on Jun 21, 2009 11:02 AM

  • Deep cloning a Binary Tree

    Hi, I have a class called DigitalTree that acts like a binary tree, storing nodes that each have a "key" which is a long value, and then puts each node into the tree in its correct place, binary tree style. I am trying to deep clone the tree, but for some reason my recursive cloning method isn't working. If anyone can see a problem in my code or has any tips for me, it would be greatly appreciated. Thanks.
    public Object clone()
           DigitalTree<E> treeClone = null;
           try
               treeClone = (DigitalTree<E>)super.clone();
           catch(CloneNotSupportedException e)
               throw new Error(e.toString());
           cloneNodes(treeClone, this.root, treeClone.root);
           return treeClone;
       private void cloneNodes(DigitalTree treeClone, Node currentNode, Node cloneNode)
           if(treeClone.size == 0)
               cloneNode = null;
               cloneNodes(treeClone, currentNode.left, cloneNode.left);
               cloneNodes(treeClone, currentNode.right, cloneNode.right);
           else if(currentNode != null)
               cloneNode = (Node<E>)currentNode.clone();
               cloneNodes(treeClone, currentNode.left, cloneNode.left);
               cloneNodes(treeClone, currentNode.right, cloneNode.right);
       }In the Node class:
    public Object clone()
              Node<E> nodeClone = null;
              try
                   nodeClone = (Node<E>)super.clone();
              catch(CloneNotSupportedException e)
                   throw new Error(e.toString());
              return nodeClone;
           }

    Hello jssutton
    Your question inspired me to try my own binary tree and cloning. My cloning algorithm is similar to yours but with one difference.
    In my class Tree defined as:
    class Tree<T extends Comparable>
    I have:
        private void deepCopyLeft(TreeNode<T> src, TreeNode<T> dest) {
            if (src == null) return;
            dest.mLeft = new TreeNode<T>(src.mValue);
            deepCopyLeft(src.mLeft, dest.mLeft);
            deepCopyRight(src.mRight, dest.mLeft);
        private void deepCopyRight(TreeNode<T> src, TreeNode<T> dest) {
            if (src == null) return;
            dest.mRight = new TreeNode<T>(src.mValue);
            deepCopyLeft(src.mLeft, dest.mRight);
            deepCopyRight(src.mRight, dest.mRight);
        public Tree<T> deepCopy() {
            if (root == null) return new Tree<T>();
            TreeNode<T> newRoot = new TreeNode<T>(root.mValue);
            deepCopyLeft(root.mLeft, newRoot);
            deepCopyRight(root.mRight, newRoot);
            return new Tree<T>(newRoot);
        }Its a similar recursive idea, but with 2 extra functions. I hope that helps. I don't have time right now to pinpoint the problem in your routine. Good luck.

  • Clarification Regarding Asset Accounting Chart of Depreciation Copy

    Hi,
    We have a company code called ACT
    For that we have a chart of depreciation assigned is ACT
    Number Ranges are 1000000-1999999 (For Example)
    Now we configured one more company code called RNC by Copying ACT company code and other settings from ACT company code only.
    Clarification required - In Asset Accounting for Company code RNC we are plannint to assign chart of depreciation ACT as it is.
    If we do like that - System will take the number ranges from the above ACT number ranges 1000000-1999999 ? or else system will take 1000000-1999999  number ranges from RNC company code? This is my doubt?
    I think system will share the 1000000-1999999  number ranges in Asset accounting for both company codes ACT & RNC as we are using Same ACT chart of depreciation for Both company codes.
    If we assign Same chart of Depreciation to both ACT and RNC company codes - Is it necessary to do any other configuration or no need to do any?
    Kindly clarify my doubt
    Thanks
    Supriya

    Hello,
    Make sure that the both the company codes are in a single country before assigning the same chart of depreciation.
    The number range of assets are defined at company code level. Meaning that you can have the same asset number in different company codes. The system will not share the number ranges across company codes.
    Regards,
    Ravi

  • InvalidClassException thrown in deep cloning

    We are trying to deep-clone an object by using serialization. We want to read the object bytes to create a String ( using new String(byte[]) ), store that String in a memory cache for later retrieving, get its bytes (using string.getBytes() ) and rebuild the original object with an ObjectInputStream.
    We are using ByteArrayInput/Output Streams to read and write the bytes from and to byte arrays, but when we call objectInputStream.readObject() we get an IllegalClassException. We have found that the byte arrays have in fact a couple of different elements after and before the retrieval. Here is the code we are using:
    public class ObjectCloner {
    public ObjectCloner(){}
    static public Object deepCopy(Object oldObj) throws Exception
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    oos = new ObjectOutputStream(bos);
    // serialize and pass the object
    oos.writeObject(oldObj);
    byte[] b = bos.toByteArray();
    oos.flush();
    String s = new String(b); //turn byte array into String
    byte[] b2 = s.getBytes(); //read bytes again
    ByteArrayInputStream bin = new ByteArrayInputStream(b2);
    ois = new ObjectInputStream(bin);
    catch(Exception e){
    System.out.println("Exception in ObjectCloner = " + e);
    finally{
    oos.close();
    ois.close();
    return ois.readObject(); //recreate the object
    We make a call from a client class, like this:
    Integer inte = (Integer)ObjectCloner.deepCopy(new Integer(7));
    Any comments will be very helpful. Thanks.

    The reason is this, you create a new String with the byte array and use getBytes() to get a new byte array using the default encoding. First I don't understand why you use these two statements, because you can apply the bytearray b directly to your ByteArrayOutputStream.
    If you want to make a copy of b, then use System.arraycopy instead of creating a String and extract the bytes from that.
    It would have worked if you used getBytes("8859_1"), that is the ISO 8859-1 encoding, which maps characters 0-255 to the same values. But UTF-8 will only map 0-127 to 0-127, and 128-255 will be mapped to at least two bytes.
    One more comment, you shouldnt try to read from your ObjectInputStream after you closed it. Move that line to just before you exit the try block, and in your exception block you should return null or throw an exception. The finally block will still be executed, so dont worry about that (remove the return statement from finally).

  • Deep Cloning of Arrays

    Hello, I am stuck with this problem...
    I am trying to clone an Array object of type MajorCat. Each MajorCat contains another Array of type MinorCat.
    MajorCat[] contains n MajorCat
    MajorCat[0] contains MinorCat[], of length m
    I wanna clone MajorCat[], which will in turn clone MinorCat[] embedded within it.
    Tried the method given in Section "CloneDemo5" within:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0306.html
    The result is strange, and I need a solution...
    Result:
    1) MajorCat[] after cloning gives another copy
    2) MinorCat[] after cloning gives another copy
    3) the orginal MajorCat[] remains the same Object
    4) BUT THE ORIGINAL MinorCat[] points to the Object at 2) !!!!!!!
    Please see this System.out:
    Original MAJORCAT starting off is [LMajorCat;@59ac7b [LMinorCat;@e2ae8   <--- 1)
    Minor Cat before cloning: [LMinorCat;@e2ae8
    Minor Cat after cloning:  [LMinorCat;@489bb6
    New MAJORCAT afterward is  [LMajorCat;@487a3a [LMinorCat;@489bb6
    Original MAJORCAT is   [LMajorCat;@59ac7b [LMinorCat;@489bb6
    Here is the code:
    MajorCat[] tempcat = (MajorCat[])(majorcat.clone());
    for ( int i=0; i<majorcat.length; i++ ) {
    if ( majorcat.minorcat != null ) {
    tempcat.minorcat = (MinorCat[])(majorcat.minorcat.clone());
    What have I done wrong? A million thanks in advance!!!!

    Hello, I put the overloading clone() method back into MajorCat and MinorCat. Again, they are never called...
    Here is the code:
    public class CatelogueSingleton extends ConnectionBase {
        protected MajorCat[] majorcat = null;
        public MajorCat[] getCatelogue() {
            if ( majorcat == null ) {
                renewAllObjects();
                System.out.println("majorcat erased!");
            MajorCat[] tempcat = (MajorCat[])(majorcat.clone());
            System.out.println("original object is   " + majorcat + " " + majorcat[0].minorcat + " " + majorcat[0].minorcat[0].itemgroup + " " + majorcat[0].minorcat[0].itemgroup[0].item);
    // clone each Object in majorcat[]
            for ( int i=0; i<majorcat.length; i++ ) {
                if ( majorcat.minorcat != null ) {
    tempcat[i].minorcat = (MinorCat[])(majorcat[i].minorcat.clone());
    for ( int j=0; j<majorcat[i].minorcat.length; j++ ) {
    if ( majorcat[i].minorcat[j].itemgroup != null ) {
    tempcat[i].minorcat[j].itemgroup = (ItemGroup[])(majorcat[i].minorcat[j].itemgroup.clone());
    for ( int k=0; k<majorcat[i].minorcat[j].itemgroup.length; k++ ) {
    if ( majorcat[i].minorcat[j].itemgroup[k].item != null ) {
    tempcat[i].minorcat[j].itemgroup[k].item = (Item[])(majorcat[i].minorcat[j].itemgroup[k].item.clone());
    System.out.println("cloned object is " + tempcat + " " + tempcat[0].minorcat);
    System.out.println("after cloning the original object is " + majorcat + " " + majorcat[0].minorcat);
    return tempcat;
    Here is the code for MajorCat...
    public class MajorCat extends ConnectionBase implements java.io.Serializable, Cloneable {
        public MinorCat[] minorcat = null;
        public Object clone() {
            try {
                System.out.println("Cloning majorcat");
                MajorCat aobj = (MajorCat)super.clone();
                aobj.minorcat = (MinorCat[])(this.minorcat.clone());
                return aobj;
            catch (CloneNotSupportedException e) {
                throw new InternalError(e.toString());
        public MajorCat() {
    }here is the code for MinorCat...
    public class MinorCat extends ConnectionBase  implements java.io.Serializable, Cloneable {
        public ItemGroup[] itemgroup = null;
        public Object clone() {
            try {
                MinorCat aobj = (MinorCat)super.clone();
                aobj.itemgroup = (ItemGroup[])(this.itemgroup.clone());
                return aobj;
            catch (CloneNotSupportedException e) {
                throw new InternalError(e.toString());
        public MinorCat() {
    }The result is:
    original object is [LMajorCat;@572085 [LMinorCat;@180b94
    cloned object is     [LMajorCat;@148656 [LMinorCat;@180b94
    after cloning the original object is  [LMajorCat;@572085 [LMinorCat;@180b94
    The original MinorCat within MajorCat now points to the new clone, and the clone() within MajorCat and MinorCat aren't called.... as there is no System.out statements.
    What have I done wrong in clone() within MajorCat and MinorCat?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Regarding Purchase Order Screen - Copy From

    Hi friends,
    In purchase order screen <b>Copy From</b> Button was in disable mode.i want to enable that button . i am using SAP Business One 2005 A(6.80.317) SP:01 version.
    expecting reply soon ......
    Thanks & Regards
    SARAN

    Hi,
    You cannot enable the Copy From button on the purchase order window. This is because there is no originating document for a purchase order (which is the first document in the chain on the purchasing side).
    Perhaps if you explain your reasons for needing this functionality someone can come up with a suitable workaround.
    Kind Regards,
    Owen

Maybe you are looking for