NamedQuery:外部化实体后,IllegalArgumentException(查询未找到) [英] NamedQuery: IllegalArgumentException (Query not found) after externalizing entities

查看:126
本文介绍了NamedQuery:外部化实体后,IllegalArgumentException(查询未找到)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与JPA2结合使用了 javax.persistence.NamedQuery 。命名查询在实体类文件的顶部定义,并且用于无状态EJB(实体立面)。

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).

现在我不得不将实体类文件一个单独的Jar文件(所以我们可以从Google Web Toolkit项目中使用它们)。显然,我仍然inc inc的jar,但现在外观bean找不到查询了:

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)
    ...

这里有什么问题?我不能在外部Jar中定义NamedQueries?

What is the problem here? Can I not define NamedQueries in an external Jar?

我刚刚发现这个链接,建议将NamedQueries放在XML文件中,而不是实体文件中的注释。这可能是一个解决我的问题的想法,但不回答我的问题...;)

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... ;)

推荐答案

解决方案是在persistence.xml文件中指定包含JPA实体的类:

The solution is to specify the classes containing JPA Entities in the persistence.xml file:

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="bonusAppServerPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/someDB</jta-data-source>
        <class>com.skalio.bonusapp.core.Store</class>
    </persistence-unit>
</persistence>

背景是JPA需要被告知在哪里扫描注释。另一个选项是使用< jar-file>< / jar-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.

这篇关于NamedQuery:外部化实体后,IllegalArgumentException(查询未找到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆