firstname
2 つの列とlastname
文字列データ型を持つ 1 つのテーブルがあるとします。通常、hqlクエリを次のように記述します
"select firstname,lastname from contact"
両方のプロパティを連結する hql クエリを記述できますか?
多分何かのような"select firstname+lastname as fullname from Contact"
firstname
2 つの列とlastname
文字列データ型を持つ 1 つのテーブルがあるとします。通常、hqlクエリを次のように記述します
"select firstname,lastname from contact"
両方のプロパティを連結する hql クエリを記述できますか?
多分何かのような"select firstname+lastname as fullname from Contact"
select concat(c.firstname, c.lastname) as fullname from Contact c
または、セパレーターが必要な場合:
select concat(c.firstname, ' ', c.lastname) as fullname from Contact c
ドキュメントを参照してください。
エンティティに計算列を作成できます。
@Formula(value = " concat(first_name, ' ', last_name) ")
private String fullName;
HQL では、他のフィールドと同じように、このフィールドを参照するだけです。
あなたの場合、次のことができます:
"select fullName from Contact"
|| も使用できます。連結演算子:
"select c.firstName || ' ' || c.lastName as fullName from Contact"
読みにくいかもしれませんが。