开发者

Unmapped POJO used as class type in a native query's result exception

Given a class:

class MyClass {
    private String a;
    private String b;
    private String c;
}

and code like so:

Query q = getEntityManager()
          .createNativeQuery('select a, b from table', MyClass.class);

It throws an exception. My solution is to add

'' as c 

in the sql. However, the c in MyClass 开发者_StackOverflow中文版is a variable that I intend to put some calculated value into, and that c does not have any real mapping to the table, so the solution just puts the c with a blank value...

My question is, are there any alternatives?


You need to mark c as @Transient so that it is not mapped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜