Announcement Announcement Module
Collapse
No announcement yet.
Crazy Database Error... please help out... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Crazy Database Error... please help out...

    I am using Spring 3, hibernate etc. I am trying to update a counter col in my table.. I do a select of the row, copy the data from the row to a new object and then try to do a saveOrUpdate with the new object and I get the following error:

    My source code:
    Code:
    public void updateSerialNumber(SerialNumber sn) {
    		SerialNumber MySN = new SerialNumber();
    		log.debug("sn:" + sn.toString());
    		MySN.setName(sn.getName());
    		MySN.setValue(sn.getValue());
    		MySN.setSerialNumberId(sn.getSerialNumberId());
    		log.debug("MySN:" + MySN.toString());
    		sessionFactory.getCurrentSession().saveOrUpdate(MySN);				
    }

    My Error:
    Code:
    2012-07-25 13:46:30,725 [http-8080-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
    org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.uftwf.model.SerialNumber#CERT]
    	at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:590)

  • #2
    Your logic is flawed.

    I am trying to update a counter col in my table
    but you do

    I do a select of the row, copy the data from the row to a new object and then try to do a saveOrUpdate with the new object
    So you are creating a new instance instead of updating the counter. SImply do as you say update the counter don't mess around with new objects simply update the one you have.

    Comment

    Working...
    X