Results 1 to 2 of 2

Thread: Crazy Database Error... please help out...

  1. #1
    Join Date
    Mar 2011
    Posts
    166

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •