This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NonUniqueObjectException:

 
Brian Oleksa
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic