Hibernate HQL只提取表值? [英] Hibernate HQL fetch only table value?

查看:111
本文介绍了Hibernate HQL只提取表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

是否可以获取唯一的表值而无需获取所有invese集合pesent ni其他关联表?

  ------------------- 
用户
---------- ---------
id int主键
名称varchar
-------------------

-------------------
客户
------------------ -
id int主键
名称varchar
id_user int外键 - > User.id
---------------- ---

在HQL查询from User中,我想只提取用户而不是整个客户端。

解决方案

有可能要求HQL中的特定字段,但它需要有一个匹配的构造函数来启用对象创建。

 
class用户{
// ...方法,字段

用户(Long id,字符串名称){
//设置字段
}
}

你的HQL看起来像:
select new(i d,name)来自用户


Is possible fetch only table value without fetch all the invese collection pesent ni others correlate tables?

example:

-------------------
User
-------------------
id int primary key
name varchar 
-------------------

-------------------
Client
-------------------
id int primary key
name varchar
id_user int foreign-key ->User.id
-------------------

In HQL query "from User" I want to fetch only users not the entire set of Client.

解决方案

it's possible to ask for specific fields in HQL, but it requires to have a matching constructor to enable object creation.

class User {
    // ... methods, fields

    User(Long id, String name) {
        // set fields
    }
}

and your HQL will look like: select new(id, name) from User

这篇关于Hibernate HQL只提取表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆