java - JPQL 会话 bean 导致的 java.lang.ClassCastException
问题描述
我正在尝试创建一个包含 JPQL 的远程服务,但是对于最简单的查询,我收到了这个错误。
在我的身份验证服务中:
@Override
public Users checkDatabase(String email) {
Query query = entityManager.createQuery("SELECT u from Users u WHERE u.nom = :email", Users.class)
.setParameter("email", email);
Users user = (Users) query.getSingleResult();
return user;
}
我的客户端代码如下所示:
String jndiName = "Petroca-ear/Petroca-ejb/AuthenticationServices!com.esprit.services.AuthenticationServicesRemote";
Context context = new InitialContext();
AuthenticationServicesRemote proxy = (AuthenticationServicesRemote) context.lookup(jndiName);
System.out.println(proxy.checkEmail("test@s"));
Users user = (Users) proxy.checkDatabase("peter");
在执行此操作时,我收到此错误:
false
Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
at org.jboss.ejb.client.remoting.ProtocolMessageHandler.readAttachments(ProtocolMessageHandler.java:55)
at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:82)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:276)
at org.jboss.ejb.client.EJBObjectInterceptor.handleInvocationResult(EJBObjectInterceptor.java:64)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.EJBHomeInterceptor.handleInvocationResult(EJBHomeInterceptor.java:88)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:46)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:129)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:265)
at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:453)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:202)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy2.checkDatabase(Unknown Source)
at TEST.testPetroca.main(testPetroca.java:23)
解决方案
推荐阅读
- javascript - 将threejs网格包裹在另一个网格上
- webpack - JSON 文件包含在包中
- java - 应用程序在 AWT 线程进行本机调用以更新游标时崩溃
- react-native - 在 React Native 中使用 Paytm 支付导致问题
- c++ - 在给定的字符串集中查找常见字符的数量?
- javascript - 如何在threejs中计算3d对象位置并将对象放置在场景中以使多个3d对象不相互重叠
- github - 本地 Jekyll 无法生成正确的 RSS 提要
- php - 如何在 Html 表中用第二行的第二列减去第一行的第一列
- react-native - React Native 更改图片来源
- python - 蟒蛇新手。想知道是否有人可以检查我的代码是否解决了问题