This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes NonUniqueObjectException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NonUniqueObjectException:" Watch "NonUniqueObjectException:" New topic
Author

NonUniqueObjectException:

Brian Oleksa
Greenhorn

Joined: Jun 05, 2007
Posts: 15
I get this error when I try to persist to the DB an arraylist of beans

11:19:16,375 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:[com.darcorner.mina.beans.WindowBean#0]


Here is my code...


public void save(ArrayList<WindowBean> beans) {

try {

int size = beans.size();
System.out.println("this is the size .." + size);

for (int i = 0; i < beans.size(); i++) {


String name = beans.get(i).getName();
int startTime = beans.get(i).getStartTime();
int stopTime = beans.get(i).getStopTime();

System.out.println("this is what is in thename .." + name);
System.out.println("this is what is in the starttime .."+ startTime);
System.out.println("this is what is in the stoptime .."+ stopTime);

WindowBean windowbean = new WindowBean();

windowbean.setStartTime(startTime);
windowbean.setStopTime(stopTime);
windowbean.setName(name);

em.persist(windowbean);
}

} catch (Exception e) {
e.printStackTrace();
}
}

I have the data that the user entered in. I know this for a fact because it loops through my system.out's and gives me the data.

So all I want to do is insert all the data in each bean into the DB.
The code works great if there is only one bean in the ArrayList, but if there is more than one, I get the above error.

Any thoughts...???

Thanks

Brian
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: NonUniqueObjectException:
 
Similar Threads
TreeSet Problem
Implementing Comparable Interface with TreeSets
Stop Watch
oddness while question.
Separate GUI Code from Back End Code