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".
我正在Java项目中使用RMI + Hibernate,我遇到了与NotUniqueException相关的问题,错误是“具有相同标识符的不同对象”。
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?
我很遗憾,我不会复制也不会创建具有相同标识符的新对象。当我使用它时,RMI是否可能从另一个创建一个新对象?
-
Which method is using Hibernate to know that two objects are the same? equals?
哪种方法使用Hibernate知道两个对象是一样的?等于?
-
I know that Serializable is related to Hibernate but I don't know in what way?
我知道Serializable与Hibernate有关,但我不知道以什么方式?
-
How can I solve the "Differents objects error" using RMI at the same time?
如何同时使用RMI解决“差异对象错误”?
-
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.
提前致谢。
1 个解决方案
#1
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?).
如果你正在做一些事情,比如从RMI方法返回一个hibernate对象,然后将它传回另一个,那么你可能需要将对象重新连接到会话。 (请参阅在Hibernate中重新附加分离对象的正确方法是什么?)。
Perhaps give some more info on what you're attempting if this doesn't help.
如果这没有帮助,或许可以提供一些关于你正在尝试的更多信息。
#1
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?).
如果你正在做一些事情,比如从RMI方法返回一个hibernate对象,然后将它传回另一个,那么你可能需要将对象重新连接到会话。 (请参阅在Hibernate中重新附加分离对象的正确方法是什么?)。
Perhaps give some more info on what you're attempting if this doesn't help.
如果这没有帮助,或许可以提供一些关于你正在尝试的更多信息。