Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we concatenate two properties in Hibernate HQL query?

Tags:

hibernate

Lets say I have one table with two columns firstname and lastname with String datatype. Normally I write my hql query like

"select firstname,lastname from contact"

Can I write a hql query which concatenates both property ?

Maybe something like "select firstname+lastname as fullname from Contact"

like image 371
abiieez Avatar asked Sep 05 '25 03:09

abiieez


1 Answers

select concat(c.firstname, c.lastname) as fullname from Contact c

or, if you want a separator:

select concat(c.firstname, ' ', c.lastname) as fullname from Contact c

See the documentation.

like image 87
JB Nizet Avatar answered Sep 07 '25 23:09

JB Nizet