NamedQuery:外部化实体后出现 IllegalArgumentException(未找到查询)
我已成功地将 javax.persistence.NamedQuery 与 JPA2 结合使用。命名查询在实体类文件的顶部定义,并在无状态 EJB(实体外观)中使用。
现在我必须将实体类文件提取到一个单独的 Jar 文件中(这样我们就可以从 Google Web Toolkit 项目中使用它们)。显然我仍然包含 jar,但现在门面 bean 不再找到查询:
java.lang.IllegalArgumentException: NamedQuery of name: Store.findByExternalId not found.
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:533)
at com.skalio.bonusapp.server.StoreFacade.getByExternalId(StoreFacade.java:43)
...
这里有什么问题?我不能在外部 Jar 中定义 NamedQueries 吗?
我刚刚发现这个链接,建议将NamedQueries放在XML文件中,而不是作为实体文件中的注释。这可能是解决我的问题的一个想法,但没有回答我的问题......;)
I have successfully used javax.persistence.NamedQuery
in combination with JPA2. The named queries are defined at the top of the entity class files, and are used from Stateless EJBs (entity facade).
Now I had to extract the entity class files into a separate Jar file (so we can use them from a Google Web Toolkit project). Obviously I still incude the jar, but now the facade bean does not find the query anymore:
java.lang.IllegalArgumentException: NamedQuery of name: Store.findByExternalId not found.
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:533)
at com.skalio.bonusapp.server.StoreFacade.getByExternalId(StoreFacade.java:43)
...
What is the problem here? Can I not define NamedQueries in an external Jar?
I just found this link, suggesting to put the NamedQueries in XML files, not as annotations in the entity files. This could be an idea to solve my problem, but doesn't answer my question... ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是在 persistence.xml 文件中指定包含 JPA 实体的类:
背景是需要告诉 JPA 在哪里扫描注释。另一个选项是使用
节点。The solution is to specify the classes containing JPA Entities in the persistence.xml file:
Background is that JPA needs to be told where to scan for annotations. The other option is to use the
<jar-file></jar-file>
node.