OpenJPA 1.2.2、WebSphere 7 (Java EE 5)
我正在尝试使用 orm.xml 中定义的命名本机查询将表映射到 POJO(不是实体!):
<named-native-query name="myNativeQuery" result-class="foo.bar.PojoBean">
<query>
SELECT col_one AS colOne, col_two AS colTwo, col_three AS colThree
FROM myTable WHERE id = 42
</query>
</named-native-query>
PojoBean 是具有 String getter/setter 和空参数构造函数的最终类:
public final class PojoBean implements java.io.Serializable {
public PojoBean() {
}
public String getColOne() { ... }
public void setColOne(String colOne) { ... }
...
}
当我创建查询时:
EntityManager myEntityManager = ...
myEntityManager.createNamedQuery("myNativeQuery");
我有一个例外(为便于阅读而格式化):
<openjpa-1.2.2-r422266:898935 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException:
Result type "class foo.bar.PojoBean" does not have any public fields or setter methods for the projection or aggregate result element "null",
nor does it have a generic put(Object,Object) method that can be used,
nor does it have a public constructor that takes the types null.
这是什么意思 ?
更多信息:
- PojoBean 的实现不能更改,并且作为 final 类也不能扩展。
- 使用 EntityManager.createNativeQuery(...) 从 java 运行查询是可行的,但这不是一个选项。
谢谢,