javax.persistence.Persistenceexception (no security manager: RMI class Loader disabled)

Asked

Viewed 486 times

5

I created a policy file that gives permission for my machine to run both the client and the server, I also passed the ports to them. Inside the server I prompt RMI Security (since if I remove it the policy does not work)

Started server works ok. Client starts working ok. I finish inserting the last field to create a new user in the database and comes these errors.

Client:

java.rmi.Unmarshalexception: Error unmarshaling Return; nested Exception is: java.lang.Classnotfoundexception: javax.persistence.Persistenceexception (no security manager: RMI class Loader disabled) at sun.rmi.transport.StreamRemoteCall.executeCall(Streamremotecall.java:247) at sun.rmi.server.UnicastRef.invoke(Unicastref.java:162) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Remoteobjectinvocationhandler.java:194) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Remoteobjectinvocationhandler.java:148) at com.sun.proxy. $Proxy0.insert(Unknown Source) at rmi.cliente.Servicos.addirUsuario(Servicos.java:42) at rmi.cliente.Rmicliente.main(Rmicliente.java:16) Caused by: java.lang.Classnotfoundexception: javax.persistence.Persistenceexception (no security manager: RMI class Loader disabled) at sun.rmi.server.LoaderHandler.loadClass(Loaderhandler.java:396) at sun.rmi.server.LoaderHandler.loadClass(Loaderhandler.java:186) at java.rmi.server.Rmiclassloader$2.loadClass(Rmiclassloader.java:637) at java.rmi.server.RMIClassLoader.loadClass(Rmiclassloader.java:264) at sun.rmi.server.MarshalInputStream.resolveClass(Marshalinputstream.java:214) at java.io.Objectinputstream.readNonProxyDesc(Objectinputstream.java:1613) at java.io.Objectinputstream.readClassDesc(Objectinputstream.java:1518) at java.io.Objectinputstream.readOrdinaryObject(Objectinputstream.java:1774) at java.io.Objectinputstream.readObject0(Objectinputstream.java:1351) at java.io.Objectinputstream.readObject(Objectinputstream.java:371) at sun.rmi.transport.StreamRemoteCall.executeCall(Streamremotecall.java:245) ... 6 more

Note: The server stopped giving error, now it is only the client.

1 answer

1

Your problem seems to be classpath, as notice from here:

java.lang.Classnotfoundexception: javax.persistence.Persistenceexception (no security manager: RMI class Loader disabled) at rmi.cliente.Servicos.addirUsuario(Servicos.java:42)

That is, in your class Servicos that is on the client’s side, there was an attempt to access the class PersistenceException. This class probably does not exist on the client side as it should not make sense to have the JPA JAR on the client side.

It occurs that when the javax.persistence.PersistenceException is serialized from server to client, client cannot deserialize, because the exception does not exist there. The result is an error in deserialization.

So what’s happening is this:

  1. There was an error in the server persistence.
  2. The error was serialized and sent to the client.
  3. The customer failed to deserialize the exception and this caused another exception.

And you might be able to see the PersistenceException on the server side with all the information that caused it to be launched.

To correct this, here are some possibilities:

  • Add the JPA JAR to the client’s classpath.
  • Add class javax.persistence.PersistenceException separately in the client’s classpath.
  • On the server side, do not leave the PersistenceException be serialized for the customer never. To do this, use the blocks try...catch in a way that avoids this. It is important to ensure that the PersistenceException does not leak even as being the cause of a higher level exception.
  • Victor, I put in the JAR, and then the mistake changed! Exception in thread "main" javax.persistence.Persistenceexception: No Persistence Provider for Entitymanager named Servidorpu at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)

  • @Joana Esse is probably the error that happened on the server. This error is saying that the file persistence.xml was not found on the server side with a persistence-Unit called Servorpu.

  • "Add the class javax.persistence.Persistenceexception separately in the client’s classpath." as I do this?

  • Yeah, except he’s in the server code... rs

  • @Joana, in the latter, create a JAR with only this class. However, I do not guarantee that it works. And it will only work if the first alternative also works (but the opposite is not necessarily true).

  • @Joana, maybe the persistence.xml is in the wrong folder.

  • Strange is that when I give Grant all no policy everything works =( haha

  • @Joana So this is probably the server error. There were two errors, one on the server and one on the client. The server error is this policy. Customer error was the problem of serialization of PersistenceException.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.