Grouping columns within entity

195 views Asked by At

I have a table with 2 columns for phone number(area code and number). When I define entity, I can do it with 2 different variable to match column names. However, when i use it in jparepository, I want to search with a phone number (which will be a single string of area code and number).

Is ther a way to group area code and number while defining the entity to have a single variable to hold combined data of 2 columns?

@Entity public class Person{ private String areaCode; private String number; }
1

There are 1 answers

0
Alien On

You can use JPQL CONCAT method like below to achieve that.

CONCAT(p.areaCode, '', p.number)

Refer this