Answer the question
In order to leave comments, you need to log in
Hibernete: How to create an Entity for SQL queries with mixed fields?
It is necessary to make a selection from the table. As a result, the values of the fields of one table, the value of the 1st field of another table, and 1 calculated field should be obtained.
When sending a request, you must specify the entity class. But I don't have such an entity with such (additional fields) fields. There are only such entities, where each contains only those fields that are inherent in 1 specific table.
How to be in such a situation? What do you advise?
Query query = session.createSQLQuery("SELECT shops.id, localities.id,
COS(?) AS cosinus,
SIN(?) AS sinus
FROM shops, localities
WHERE localities.name = ?
AND localities.id = shops.locality_id;")
.addEntity(ShopsPlus.class)
.setString(0, a.toString())
.setString(1, a.toString())
.setString(2, cityName);
Answer the question
In order to leave comments, you need to log in
And in what object you were going to write down result of request? Some kind of POJO is still needed.
In general, look at QueryDsl
www.querydsl.com
and specifically at ConstructorExpression - a very handy thing (especially if you use maven)
www.querydsl.com/static/querydsl/3.2.2/apidocs/com...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question