This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NonUniqueObjectException:  RSS feed

 
Brian Oleksa
Greenhorn
Posts: 15
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!