• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NonUniqueObjectException:

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic