Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8291551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:10:05+00:00 2026-06-08T13:10:05+00:00

I am using Spring 3, hibernate etc. I am trying to update a counter

  • 0

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:

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:

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:10:06+00:00Added an answer on June 8, 2026 at 1:10 pm

    if you only want to update the counter why are you copying the Object? You cannot have two different objects with the same id (@Id in your Entity) assosiated with the hibernate session. I guess you’re using one of the properties you are setting on MySN as the ID. I’d suggest using a surrogate ID (and afaik this is als what is recommended in hibernate documentation) which can be e.g. assigned by a db-sequence (if you’re using oracle DB) and if you have to copy the object just leave this surrogate id null and you’ll be able to save it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring with Hibernate as a JPA provider and are trying to get
I'm trying to make a project using struts 2, spring 3 and hibernate, but
I'm trying to build a spring roo project using hibernate and an oracle database.
I'm trying to configure a Spring+Hibernate web application using JNDI instead of a properties
im using spring+hibernate for a desktop application. I'm trying to build it with a
I am using hibernate annotations with spring MVC. Now i always create table using
I am using spring/hibernate stand alone application. if i dont configure Transactions i am
I'm using Spring and Hibernate. I'm uploading images using commons-fileupload-1.2.2 as follows. String itemName
I am using Spring with Hibernate in my project.There are many methods written in
I'm uploading images using Spring and Hibernate. I'm saving images on the server as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.