4

I'm using in a Java project RMI + Hibernate and I'm experiencing problems related to NotUniqueException with the error "Different objects with the same identifier".

I've got several doubts:

  • I'm pretty surre that I don't copy nor create new objects with the same ide ntifiers. Is it possible that RMI creates a new object from another one when I use it?

  • Which method is using Hibernate to know that two objects are the same? equals?

  • I know that Serializable is related to Hibernate but I don't know in what way?

  • How can I solve the "Differents objects error" using RMI at the same time?

  • Is it correct every time I use delete or save over an object use merge before?

The stack traces is:

org.orm.PersistentException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [dcl.Administrador#10]
    at org.orm.PersistentSession.saveOrUpdate(PersistentSession.java:648)
    at org.orm.PersistentManager.saveObject(PersistentManager.java:274)
    at dcl.AdministradorDAO.save(AdministradorDAO.java:240)
    at dcl.BdAdministrador.guardarAdministrador(BdAdministrador.java:62)
    at dcl.BdAdministrador.actualizarAdministrador(BdAdministrador.java:109)
    at dcl.BdPrincipal.actualizarAdministrador(BdPrincipal.java:555)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Thanks in advance.

user207421
  • 305,947
  • 44
  • 307
  • 483
Jonás
  • 1,459
  • 4
  • 27
  • 43
  • @EJP I've posted the stack trace. The exception is referred to an object "Adminsitrador" which I get from the database and I try to update because I've modified a property which links to a "Publicidad" object – Jonás Aug 29 '12 at 17:32
  • OK well it's a Hibernate issue, nothing to do with RMI, so I am adjusting your tags. – user207421 Aug 29 '12 at 23:38
  • Could you please post the hibernate mapping for your Administrator object. – Ian Dallas Aug 29 '12 at 23:42

1 Answers1

0

If you're doing something like returning a hibernate object from an RMI method, then passing it back into another one, then you'll potentially need to reattach the object to the session. (see What is the proper way to re-attach detached objects in Hibernate?).

Perhaps give some more info on what you're attempting if this doesn't help.

Community
  • 1
  • 1
Phasmal
  • 3,840
  • 2
  • 16
  • 11