0

I have a SQL query and the mapping of the classes. Using openJPA, if the query is made as a @NamedNativeQuery it works fine, returning the correspondent class and the expected result. If it is transformed into a JPQL @NamedQuery it always returns a NoResultException for the getSingleResult method. I tried also the JPA Criteria but it is just not working, at least not in all environments. I cannot reproduce the problem locally, it only occurs in the test system. Locally all of the approaches work ok.

I think that it is a configuration problem, but I haven't found anything.

SQL: SELECT * FROM MY_REL_TABLE map WHERE map.TYPE = ?1 AND map.REGION_ID = ?2

JPQL: SELECT m FROM MyRelationClass m WHERE m.type= :type AND m.region = :region

Does anyone have an idea what could be wrong?

IBM openJPA, Websphere 8.0

4

1 回答 1

1

我无法在本地重现该问题,它仅发生在测试系统中。

您是否在两种环境中都连接到同一个数据库?如果没有,您的本地数据库是否可能没有正确的数据?

您可以启用 OpenJPA SQL 跟踪以查看 JPQL 正在被翻译成什么:

openjpa.Log=SQL=trace

此外,设置以下属性以查看参数值:

openjpa.ConnectionFactoryProperties=PrintParameters=true
于 2013-04-25T15:14:13.757 回答