Reputation: 2160
I'm new to Hibernate and I encountered a query today:
select new SomeClassDTO(r.id, r.name, r.description, u.id) from ClassA as u
inner join u.data as r where u.email !=?1 and r.name not like '%Blah%
Can you please explain how this query works?
Upvotes: 0
Views: 26
Reputation: 4643
This query takes several fields from a ClassA
entity with it's associated data
Entity(s) and passes those field values into the constructor for class SomeClassDTO
.
As the name of the created object implies, this is a way to take data from multiple associated database-mapped Entities, and construct a Data Transfer Object (DTO) to pass to your presentation layer.
You are essentially creating a 'view' of your database Entities and constructing new objects to hold the records of the result set of that view.
Upvotes: 2