Announcement Announcement Module
Collapse
No announcement yet.
NonUniqueObjectException using Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NonUniqueObjectException using Hibernate

    Hi,

    Using a DAO that extends HibernateDAOSupport, I call a method "findByName" 2 times to load the same object (same id), but I get 2 different object (with same id, but different references).

    Then when I try to update, I receive this exception :
    org.springframework.orm.hibernate.HibernateSystemE xception: a different object with the same identifier value was already associated with the session: 242, of class: Library; nested exception is net.sf.hibernate.NonUniqueObjectException

    How to explain that behavior ? I think that the method "findByName" creates a new session each time it's called. Is it right ?

    What can I do to receive the same object reference when calling 2 times the method ?

    Thanks!

  • #2
    Are both calls spanned in the same transaction? Hibernate Will use the same Session as long as your calls are dones into the same transaction.
    HTH

    Comment


    • #3
      Thanks for the reply!

      I specify nothing about the transactions ... How can I say that both find and update are in the same transaction ?

      Comment


      • #4
        Search the forum for HibernateTransactionManager. You can also review jpetstore sample from Spring distribution. Spring reference documentation is also a good place to start.
        HTH

        Comment

        Working...
        X