1

I have a class with 4 fields, a table with 2 columns and a native query, that return 4 columns. let's say: a class:

class Foo{
    int id;
    String name;
    int stat;
    String statName;
}

a table:

foo
---------
id | name

and mapping:

<class name="Foo" table="foo">
    <id name=id/>
    <property name="name"/>
    <property name="stat"/>
    <property name="statName"/>
</class>
<sql-query name="getWithStat">
    <return class="Foo"/>
    <!--stat and statName calculated as aggregation and concatenation from other table-->
</sql-query>

But with this mapping, I can't use basic entity, because table hasn't columns for stat and statName. How shoul I map this extra fields from my query into my class?

TEXHIK
  • 1,369
  • 1
  • 11
  • 34

1 Answers1

1
you can use Transient annotation of JPA to ignore property at time of persist.

class Foo{
    int id;
    String name;
    @Transient
    int stat;
    @Transient
    String statName;
}
samji
  • 31
  • 6
  • But it is **not** transient, I want result from my query to be mapped there. However, I don't want this properties to be mapped when persisting or getting an entity from the table (because they are **not** exist there) – TEXHIK Nov 23 '18 at 14:14