Literal Strings - same value, same object?

I've read that if two literal Strings contain the same value, they reference the same object to save memory. Is this guaranteed? And is the same thing true of primitive wrappers with literal values like Integer(42)?
The reason I ask is because I'm thinking of using a Map as a sparse array indexed by Integers... or, if not that, then Strings representing integer values.

Ok so you put a string into the map using one of the Integer references as a key and took it out using the other one.
The problem here is how a Map works when you get() something. (Including HashMap).
"Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
"More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)"
http://java.sun.com/javase/6/docs/api/java/util/Map.html#get(java.lang.Object)
The important bit is the second paragraph. Do you see where for non-null keys it checks key.equals(k)? In your case the two 666 Integers were checked for equality of value using equals(), not for identity of reference (using ==). They are different objects, but they represent the same integer value so they compare true with equals(). Hence the map finds a match even when you use a different key.
A more straightforward test is to simply print:
{code}
Integer i1 = new Integer(666);
Integer i2 = new Integer(666);
if(i1 == i2) {
System.out.println("Same");
} else {
System.out.println("Different");
{code}
You'll find the same behaviour - +different+ key objects returning the same value from a Map - even when you use small Integer objects like new Integer(66).

Similar Messages

  • Two string references pointing to the same object

    Look at the following code snippet         String   s1 = "hello";
            String   s2 = "world";
            String   s3 = "welcome";
            String   s4 = "here";
            String   s5 = "hello";
      They say that references s1 and s5 point to the same object "hello".
    At run time after creating objects from s1 to s4 how the Java run time knows that there is already an object "hello" and assigns a differernt reference.

    When the jvm load the class file, all suchconstants
    found in the class are loaded in a global constant
    pool. when you assign the constant to a variable,it
    uses the same one from the constant pool.Suppose I intialize a string by getiing input
    nput from the console which already exists, in that
    case a new object will be created or the existing one
    be used.A new object will always be created in that case, but you can get a reference to the string in the pool by calling intern. See the javadoc for intern in the String class.
    Kaj

  • Finalize() method being called multiple times for same object?

    I got a dilly of a pickle here.
    Looks like according to the Tomcat output log file that the finalize method of class User is being called MANY more times than is being constructed.
    Here is the User class:
    package com.db.multi;
    import java.io.*;
    import com.db.ui.*;
    import java.util.*;
    * @author DBriscoe
    public class User implements Serializable {
        private String userName = null;
        private int score = 0;
        private SocketImage img = null;
        private boolean gflag = false;
        private Calendar timeStamp = Calendar.getInstance();
        private static int counter = 0;
        /** Creates a new instance of User */
        public User() { counter++;     
        public User(String userName) {
            this.userName = userName;
            counter++;
        public void setGflag(boolean gflag) {
            this.gflag = gflag;
        public boolean getGflag() {
            return gflag;
        public void setScore(int score) {
            this.score = score;
        public int getScore() {
            return score;
        public void setUserName(String userName) {
            this.userName = userName;
        public String getUserName() {
            return userName;
        public void setImage(SocketImage img) {
            this.img = img;
        public SocketImage getImage() {
            return img;
        public void setTimeStamp(Calendar c) {
            this.timeStamp = c;
        public Calendar getTimeStamp() {
            return this.timeStamp;
        public boolean equals(Object obj) {
            try {
                if (obj instanceof User) {
                    User comp = (User)obj;
                    return comp.getUserName().equals(userName);
                } else {
                    return false;
            } catch (NullPointerException npe) {
                return false;
        public void finalize() {
            if (userName != null && !userName.startsWith("OUTOFDATE"))
                System.out.println("User " + userName + " destroyed. " + counter);
        }As you can see...
    Every time a User object is created, a static counter variable is incremented and then when an object is destroyed it appends the current value of that static member to the Tomcat log file (via System.out.println being executed on server side).
    Below is the log file from an example run in my webapp.
    Dustin
    User Queue Empty, Adding User: com.db.multi.User@1a5af9f
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    Joe
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin pulled from Queue, Game created: Joe
    User Already Placed: Dustin with Joe
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    INSIDE METHOD: false
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    User Dustin destroyed. 9
    User Joe destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    It really does seem to me like finalize is being called multiple times for the same object.
    That number should incremement for every instantiated User, and finalize can only be called once for each User object.
    I thought this was impossible?
    Any help is appreciated!

    Thanks...
    I am already thinking of ideas to limit the number of threads.
    Unfortunately there are two threads of execution in the servlet handler, one handles requests and the other parses the collection of User objects to check for out of date timestamps, and then eliminates them if they are out of date.
    The collection parsing thread is currently a javax.swing.Timer thread (Bad design I know...) so I believe that I can routinely check for timestamps in another way and fix that problem.
    Just found out too that Tomcat was throwing me a ConcurrentModificationException as well, which may help explain the slew of mysterious behavior from my servlet!
    The Timer thread has to go. I got to think of a better way to routinely weed out User objects from the collection.
    Or perhaps, maybe I can attempt to make it thread safe???
    Eg. make my User collection volatile?
    Any opinions on the best approach are well appreciated.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • Adding same object(jtextfield) to different cards in card layout

    Have a combo box with 3 items which changes cards in a cardLayout.
    Have 3 panels as card in a cardLayout.
    Want to reuse the field txtName, lblName in pnlName and reuse txtAge, lblAge in pnlAge in all the cards.
    It only appears in the last card3 panel(i.e the last panel referenced)
    Is there a way I can show the same object(pnlName, pnlAge) in all the cards,
    Below is the code, any solution is welcome.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CardLayoutTest implements ItemListener {
    JPanel cards; //a panel that uses CardLayout
    public void addComponentToPane(Container pane) {
    //Put the JComboBox in a JPanel to get a nicer look.
    JPanel comboBoxPane = new JPanel(); //use FlowLayout
    String comboBoxItems[] = { "Name", "ShortDetail","FullDetail"};
    JComboBox cb = new JComboBox(comboBoxItems);
    cb.setEditable(false);
    cb.addItemListener(this);
    comboBoxPane.add(cb);
              JLabel lblName, lblAddress, lblAge;
              JCheckBox chkMarried;
              JRadioButton rdbMale, rdbFemale;
              JTextField txtName, txtAddress, txtAge, txtSex;
              JPanel pnlName = new JPanel(new FlowLayout(FlowLayout.LEFT));
              pnlName.add(lblName = new JLabel("Name"));
              pnlName.add(txtName = new JTextField(10));
              JPanel pnlAddress = new JPanel(new FlowLayout(FlowLayout.LEFT));
              pnlAddress.add(lblAddress = new JLabel("Address"));
              pnlAddress.add(txtAddress = new JTextField(10));
              JPanel pnlAge = new JPanel(new FlowLayout(FlowLayout.LEFT));
              pnlAge.add(lblAge = new JLabel("Age"));
              pnlAge.add(txtAge = new JTextField(3));
              JPanel pnlSex = new JPanel(new FlowLayout(FlowLayout.LEFT));
              pnlSex.add(rdbMale = new JRadioButton("Male"));
              pnlSex.add(rdbFemale = new JRadioButton("Female"));
              JPanel pnlMarried = new JPanel(new FlowLayout(FlowLayout.LEFT));
              pnlMarried.add(chkMarried = new JCheckBox("Married"));
              //pnl3.add(lblName = new JTextField(10));
              JPanel card1 = new JPanel(new GridLayout(0,1));
              card1.add(new JLabel("Card1"));
              card1.add(pnlName);
              card1.add(pnlAge);
              JPanel card2 = new JPanel(new GridLayout(0,1));
              card2.add(new JLabel("Card2"));
              card2.add(pnlName);
              card2.add(pnlAge);
              card2.add(pnlAddress);
              JPanel card3 = new JPanel(new GridLayout(0,1));
              card3.add(new JLabel("Card3"));
              card3.add(pnlName);
              card3.add(pnlAge);
              card3.add(pnlSex);
              card3.add(pnlMarried);
    //Create the "cards".
    JPanel card1 = new JPanel();
    card1.add(new JButton("Button 1"));
    card1.add(new JButton("Button 2"));
    card1.add(new JButton("Button 3"));
    JPanel card2 = new JPanel();
    card2.add(new JTextField("TextField", 20));
         JPanel card3 = new JPanel();
    card3.add(new JLabel("Label"));
         JPanel card4 = new JPanel();
    card4.add(new JCheckBox("Hello Holla"));
    JPanel card5 = new JPanel();
              cards.add();
    //Create the panel that contains the "cards".
    cards = new JPanel(new CardLayout());
    cards.add(card1, "Name");
    cards.add(card2, "ShortDetail");
    cards.add(card3, "FullDetail");
    pane.add(comboBoxPane, BorderLayout.PAGE_START);
    pane.add(cards, BorderLayout.CENTER);
    public void itemStateChanged(ItemEvent evt) {
    CardLayout cl = (CardLayout)(cards.getLayout());
    cl.show(cards, (String)evt.getItem());
    private static void createAndShowGUI() {
    JFrame frame = new JFrame("CardLayoutTest");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    CardLayoutTest demo = new CardLayoutTest();
    demo.addComponentToPane(frame.getContentPane());
         frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    I'm 99% sure that you cannot have the same txtfields/combos in different JPanels at the same time, which explains why they only appear in the last panel they are added to... but I guess you already knew that.
    You could add these components to the panel you wish to show each time you change panels.
    Or
    you could have a panel which contains these components and add it to each of the 3 panels that you show on your cardLayout.
    Or
    you could store the values selected in the components in globals to your class and replicate each of the components with this data in each of your three panels.

  • Two Threads Sharing the Same Object

    I am learning Java multithreading recently and I really hit the wall when I came to synchronizing data using the synchronized keyword. According to the explanation, synchronized will only work when 2 or more threads are accessing the same object. If there are accessing 2 different objects, they can run the synchronized method in parallel.
    My question now is how to make sure for synchronized method to work, I am actually working with the same and only one object??
    Imagine this:
    Two person with the same account number are trying to access the very ONE account at the same time.
    I suppose the logic will be:
    Two different socket objects will be created. When it comes to the login or authentication class or method, how can I make sure in term of object that the login/authentication class or method will return them only ONE object (because they share the same account), so that they will be qualified for using the synchronized method further down the road?
    Thanks in advance!

    Actually your understanding is wrong. Consider:
    public class MyClass {
      private int someInt;
      private float someFloat;
      private synchronized void someMethod(final int value) {
        if (value > 2000) someInt = 2000;
      private synchronized void someOtherMethod(final float value) {
        if (value > 2.0) someFloat = 1.999f;
    }YOu might think that two different threads can enter this code, one can enter in someOtherMethod() while one is in someMethod(). That is wrong. The fact is that synchronization works by obtaining synchronization locks on a target object. In this case by putting it on the method declaration you are asking for the lock on the 'this' object. This means that only one of these methods may enter at a time. This code would be better written like so ...
    public class MyClass {
      private int someInt;
      private float someFloat;
      private void someMethod(final int value) {�
        synchronized(someInt) {
          if (value > 2000) someInt = 2000;
      private void someOtherMethod(final float value) {
        synchronized(someFloat) {
          if (value > 2.0) someFloat = 1.999f;
    }In this manner you are only locking on the pertinent objects to the method and not on 'this'. This means that both methods can be entered simultaneously by two different threads. However watch out for one little problem.
    public class MyClass {
      private int someInt;
      private float someFloat;
      private void someMethod(final int value) {�
        synchronized(someInt) {
          if (value > 2000) {
            someInt = 2000;
            synchronized (someFloat) {
              someFloat = 0.0f;
      private void someOtherMethod(final float value) {
        synchronized(someFloat) {
          if (value > 2.0) {
            someFloat = 1.99999f;
            synchronized (someInt) {
              someInt = 0;
    }In this case you can have a deadlock. If two threads enter one of these methods at the same time one would be waiting on the lock for someInt and the other on the lock for someFloat. Neither would proceed. The solution to the problem is simple. Acquire all locks in alphabetical order before you use the first.
    public class MyClass {
      private int someInt;
      private float someFloat;
      private void someMethod(final int value) {�
        synchronized (someFloat) {
          synchronized(someInt) {
            if (value > 2000) {
              someInt = 2000;
              someFloat = 0.0f;
      private void someOtherMethod(final float value) {
        synchronized(someFloat) {
          if (value > 2.0) {
            someFloat = 1.99999f;
            synchronized (someInt) {
              someInt = 0;
    }In this manner one thread will block waiting on someFloat and there can be no deadlock.

  • Make sure 2 threads share the same object

    I have been thinking about this for quite some time. However, I really couldn't figure it out due lack of experience and knowledge.
    I just needed to know how can I make sure that 2 or more threads (after certain checkings that they should share a same common object) will really share the same object.
    For example (to UlrikaJ if you are reading this):
    How can I achieve the following?? Thanks!
    "When James and Ada separately want to access their shared account,two transactions are started that accesses the object associated with that account number."

    Thanks for the answer. You are welcome :-)
    public class Account
       public Account getAccount(String userInput)
         // Some processes to verify the userInput go here.
         return account;
    }//End of Account class
    public UserThread implements Runnable
       private String name;
       private Semaphore s;
       private Account userAccount; //Reference for the Account class
       public UserThread(String name, Semaphore s)
          this.name = name;
          this.s = s;
       }//End of constructor
       public void run()
          for(;;)
              getUserInput(); //Ofcourse the implementation will depend on what you are doing
              s.lock(); //obtain a lock on Semaphore object
              //Entering critical section of the code
              this.userAccount = accountObject.getAccount(userInput);
              //End of critical section of the code.
              s.signal(); //Release the lock so that other thread
              //can access the getAccount() method...irrespective of the
              //variable or the object being used or referred to.
          }//End of for() loop
       }//End of run() method
    } //End of UserThread class
    public class AccountApplication
       public static void main(String args[])
          Semaphore sem = new Semaphore(0);
          //Always initialize the Semaphore with 0 when you create it.
          UserThread user1 = new UserThread("User Number 1",sem);
          UserThread user2 = new UserThread("User Number 2",sem);
          //All threads share the same Semaphore object
          Thread userThread1 = new Thread(user1);
          Thread userThread2 = new Thread(user2);
          userThread1.start();
          userThread2.start();
       }//End of main() method
    }//End of classWell, I have given the outline of the code. I have not compiled or run the program so it might have errors in its syntax.
    Obviously, you will definitely have to change it to suit your requirements. I have just shown you how to protect yur codes' critical section.
    Hope this clears your doubts.
    Vijay :-)

  • Different change request about the same object

    Hi Gurus,
    I have some doubts about CR (change request) from one system to another, such as from development system to quality or quality to production.
    If I have 2 or more CUSTOMIZING CR about the same object Can I say that they are however identical (they contain the same information)?
    For example on the customizing table:
    record1 contains value 'A' --> CR number 1 is opened
    record1 contains value 'B' --> CR number 2 is opened
    If now I transport CR number 1 I transport value 'B'. 
    And the same if I transport CR number 2.
    Is it correct? Both CR points to the actual value of the record?
    Instead if I have 2 or more WORKBENCH CR I know they "remember" the history of the modifications:
    For example on a program with only 1 istruction:
    data: x.
    --> CR number 1
    data: x,y.
    --> CR number 2
    What happen If I transport the 2 CR simultaneously (selecting both from STMS) ?
    What will be the result in quality/production system? Which CR "wins"?
    Thanks in advance
    Guido

    At time of release from DEV, the current object version or table content is written into the transport data file, thus "detached" from further changes in DEV.
    Now if two transport requests 1 and 2 contain the same object in two versions (older and newer) and are being imported into QA, the following scenarios are possible:
    - 1 is imported first, then 2: newer version will be in QA -> OK
    - 2 is imported first, then 1: older version will be in QA -> not OK
    - both are imported at same time: newer version will be in QA -> OK (STMS checks when the requests were added to the import queue and sorts accordingly)
    Thomas

  • How do I use multiple classes to access the same object?

    This should be staightforward. I have and object and I have multiple GUIs which operate on the same object. Do all the classes creating the GUIs need to be inner classes of the data class? I hope this question makes sense.
    Thanks,
    Mike

    public final class SingletonClass {
    private static SingletonClass instance;
    private int lastIndex = 10;
    public final static SingletonClass getInstance()
    if (instance == null) instance = new SingletoClass();
    return instance;
    public int getLastIndex() {
    return lastIndex;
    }1) This won't work since one could create a new SingletonClass. You need to add a private constructor. Also, because the constructor is private the class doesn't have to be final.
    2) Your design isn't thread-safe. You need to synchronize the access to the shared variable instance.
    public class SingletonClass {
        private static SingletonClass instance;
        private static Object mutex = new Object( );
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            synchronized (mutex) {
                if (instance == null) {
                    instance = new SingletonClass();
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }if you are going to create an instance of SingletonClass anyway then I suggest you do it when the class is loaded. This way you don't need synchronization.
    public class SingletonClass {
        private static SingletonClass instance=new SingletonClass();
        private int lastIndex = 10;
        private SingletonClass() { }
        public static SingletonClass getInstance() {
            return instance;
        public int getLastIndex() {
            return lastIndex;
    }If you don't really need an object, then you could just make getLastIndex() and lastIndex static and not use the singleton pattern at all.
    public class SingletonClass {
        private static int lastIndex = 10;
        private SingletonClass() { }
        public static int getLastIndex() {
            return lastIndex;
    }- Marcus

  • How can I use the same object in the different jsp files?

    I am doing a project. I have finished my jave source files and compiled them successfully. And I also wrote a main method to test my classes, they also worked well. Now I am trying to use my jave code in the jsp files. But I meet a problem, in my method of java source file, I can generate a object of a class, and use it in the whole main method. But in the different jsp files, how can I do same thing?
    For example, in the .java file,
    Vector vl = new Vector();
    While ...{
    vl.add(...)
    In each of my .jsp file I want to do one loop of the above, meanwhile I want to do that in the same object.
    I hope you can understand what I mean. Really need your help!

    put your object into a session and you can the use it in all the jsps as long as the session is valid. Or you could create a static variable in the class that only creates one instance off an object and then create a static method to return this object.

  • The same Object Version Number for the same person id multiple times

    Hello all,
    I am currently facing an issue with HRMS tables and the object version number for employees. I am trying to write a report but due to the same object version number for the same person appearing in several row i am getting duplicate information. For example,
    person id 91 object version number 32 is on 4 rows and i have no idea why...help please guys, I'm at a lost so far 50 people are facing the same issue.

    Hi Baal666bobo,
    The person table is date-tracked, so the PK has effective start and end dates as well.
    Get the correct record with sysdate(or any particular date) and then check the OVN.
    Cheers,
    Vignesh

  • Multiple Transports for the Same Object.

    I have ABAP program 123 and I make a change, create transport A and release the transport. I do not request transport A go to production.
    I then modify ABAP program 123 again, create transport B and release the transport. I do not request transport B go to production.
    Now I request transport A go to production.
    Can someone explain to me why the changes in transport B are included when transport A is moved to production?
    I thought each transport would be at its own change level.
    Thank-you.

    I can guarantee all of you that when Transport A was moved, it contained changes that were made in Transport B.
    Surely you understand that Thomas is correct and that there's a logical reason, not related to transport layer configuration, for the issue?   You CAN have multiple transports open for the same object without a lock by forcing it but check the dates as already suggested...

  • Can we have multiple transports for the same object.

    Hi guys,
    Can we have multiple transports for same object in dev system. Can anyone tell me how can this be done.
    Thanks

    Its not possible for the same development object. Only 1 person can access an object at a time and if mutiple users modify an object new TASKs are created under the same TRANSPORT.
    Only after releasing the tr you can create a new tr on the same object.
    Message was edited by:
            Abhishek Jolly

  • Multiple inserts for the same object

    We have observed that in certain cases, the same object is attempted to be inserted twice, resulting in Primary Key violation.
    Here is one example -
    A(1->1)B, unidirectional, A has the foreign key to B
    new B
    copyB = register(B) (also assign sequence number)
    new A1, A2
    A1.set(copyB), A2.set(copyB)
    register(A1), register(A2)(also assign sequence number)
    commit
    it tries to insert the same B twice.
    any clues whats wrong here?
    thanks

    Any chance your 1:1 from A to B is marked as privately-owned?
    This would indicate to TopLink that the object in each relationship is unique and should be inserted.
    Doug

  • Accesing same object from different servlets

    Hello all!
    I am developing a web control project. I am using a simulator of a factory (with java). The engineers are supposed to be able to change some variables from the web.
    I am using servlets to change this variables. My problem is that, to be able to change variables, I need to create an instance of this FactorySimulator object.
    If each servlet ( there are many servlets) calls an instance, they will be updating different FactorySimulator objects.
    How can I make reference, or have acces to the SAME object, from any servlet?
    Thanks! I hope my question is clear =)

    package com.yourcompany.somepackage;
    public class TheFactory
        private static FactorySimulator factory = new FactorySimulator();
        private TheFactory() {} // Static methods only, do not instantiate TheFactory
        public FactorySimulator instance()
            return factory;
    }From each of your servlets you can call TheFactory.instance().doWhataver(). Methods in FactorySimulator need to be suitably synchronized of course.

Maybe you are looking for

  • Help! iOS 4 giving my iPhone 3G problems...

    Hi, so ever since I upgraded to iOS 4, my iPhone 3G has been "lagging", and it is rather sluggish starting up apps. Also, the Safari app is not working. It brings me to the History, etc. menu on Safari, but freezes. It may crash too. I've not had pro

  • Adding a field from a catalogue in 'create shopping cart' display screen

    Hi all, I am new to SRM and i am faced with the following situation: I need to add a field called 'supplier part number' to the 'create shopping cart' screen from the MDM catalogue. Once the entries for the field 'supplier part number' are fetched fr

  • Reading Input

    I'm having a bit of trouble reading two forms of input. The input is essentially the components of a directed graph. The first method of input is through a text file. The file is to be formatted like this: 10 15 2 4 3 5 4 8 1 2 The first number is th

  • ABAP Objects-attribute accessability issue

    Hi, Let me introduce the problem. I have a class c1 which has a public attribute a1. a1 is of table type which refers to a class c2. c2 has an attribute a2 which is public. With the object o1 of class c1 I need to access a2. Please help me solve the

  • No radio in menu of iTunes 7.5?

    So I have downloaded iTunes 7.5 and would like to listen to streaming radio programs. However, all the Support instructions say to just click on the radio icon that's in the left hand nav and I do not see any icon. It is just not there. Is there some