I've got a simple pojo which is filled thanks to hibernate. I would like to see a variable from this pojo being mapped to a very specific SQL query and I wonder if this is possible to create such a mapping in the hibernate.xml file ?
Thanks a lot
There's no easy way in pure JPA to do that. The best would be to use Hibernate's @Formula annotation, on which you can specify a "SQL Fragment" that should be used to get the field's data.
Are you looking for some thing like this
String sql = "SELECT a.id As id, CONCAT(a.firstName,' ',a.lastName) AS advisorName from tableAdvis";
List<CollectionReport> collectionList = (List<CollectionReport>) getSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(CollectionReport.class)).list();
Here is my CollectionReport POJO looks like
public class CollectionReport {
private BigInteger id;
private String advisorCode;
private String advisorName;
//Getter & Setter
}
ResultTransformer will get query result and based on property name in POJO, it assigns values to it.