D
D
detected_pro2017-03-21 14:37:37
Java
detected_pro, 2017-03-21 14:37:37

How to select custom field from Hibernate?

Good time of the day. Interested in one question about the ORM Hibernate:
How can I pull out an arbitrary field goodField?
Let's say I have a query like this

select mytable.*, (select * from mytable2) as goodField from mytable;

mytable is an entity, but there is no goodFIeld field/property in this entity and there shouldn't be. I would not like to add this arbitrary (dynamic) field to the entity, as well as create a new one with this field.
This code works, but of course, I can't reach goodField.
(List<MyTable>) session.createSQLQuery("select mytable.*, (select * from mytable2) as goodField from mytable").addEntity(MyTable.class).list();

Tried different options, didn't work. Thanks for the answer.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question