Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. If you have a question for a future Hibernate Tip, please post a comment below.
Last week, one of my coaching clients asked an interesting question:
He used the InheritanceType.SINGLE_TABLE to map an inheritance hierarchy to one database table. In one of his queries, he wanted to return the same DTO projection for different subentities of the hierarchy. Depending on the subentity class, he wanted to initialize different properties of the DTO object.
The question was: How do you implement a query that adapts the constructor call to different subentities?