Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何映射具有比表更多列的本机查询?_Java_Hibernate_Xml Configuration - Fatal编程技术网

Java 如何映射具有比表更多列的本机查询?

Java 如何映射具有比表更多列的本机查询?,java,hibernate,xml-configuration,Java,Hibernate,Xml Configuration,我有一个包含4个字段的类,一个包含2列的表和一个返回4列的本机查询。 比如说: a类: 一张桌子: foo --------- id | name 和映射: <class name="Foo" table="foo"> <id name=id/> <property name="name"/> <property name="stat"/> <property name="statName"/> <

我有一个包含4个字段的类,一个包含2列的表和一个返回4列的本机查询。 比如说: a类:

一张桌子:

foo
---------
id | name
和映射:

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


但在这个映射中,我不能使用基本实体,因为表中没有
stat
statName
的列。我应该如何将查询中的这些额外字段映射到我的类中?

是来自其他实体类的stat和statName字段吗?@PoojaAggarwal否,它是在查询中计算的(其他表中的一些字段的串联和聚合)。但这不是暂时的,我希望查询的结果映射到那里。但是,我不希望在持久化或从表中获取实体时映射这些属性(因为它们不存在)
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;
}
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;
}