Search code examples
javasqljpapojo

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 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?


Solution

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