对JPQL感到困惑 [英] Confusing about JPQL

查看:96
本文介绍了对JPQL感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让JPQL喜欢以下示例:

I want to JPQL likes following example:

让酒店"对象具有客户"和组织"两个对象.如果客户不为空,则组织将为空.并且如果Customer为null,则组织不会为null.所以

Let Hotel object has two objects of Customer and Organization. If Customer is not null, organization will be null. And if the Customer is null , organization will not be null. So

我JPQL喜欢这个;

I JPQL likes this;

从酒店h中选择h.customer.name.firstName和h.organization.name

Select h.customer.name.firstName, h.organization.name from Hotel h

我只想将这两个结果之一分配给一个变量,因为一个总是为空. 谢谢你,我的英语很抱歉.

i want to assign one of these two result only to one variable because one is always null. Thanks and Sorry for my english.

推荐答案

可能您正在寻找COALESCE()函数.请尝试以下操作:

Probably, you are looking for COALESCE() function. Try the following:

SELECT COALESCE(h.customer.name.firstName, h.organization.name) FROM Hotel h

如果需要,还可以使用CASE表达式.

You also can use CASE expression if you want.

更多详细信息: http://docs.jboss.org/hibernate/orm/4.2/devguide/zh-CN/html/ch11.html#d5e3257

这篇关于对JPQL感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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