I think this scenario is interesting and I would assume is used in many applications so it would be nice to hear some opinions...
1.
Using Hibernate 3.2.2 (latest as of this writing), we have an application that does only read-only retrieval of data and has absolutely no persistent requirements at all. What I'd like to do is retrieve an array of various DTO objects (for type safety as we're not on EE 5 yet and hence can't utilize generics yet) through named queries (each sql statement is already done and has over 10 various inner and left outer joins) and simply populate the DTO objects with necessay information to be used by the views. The sql needs to be a native sql and not HQL/JP.
One way is to simply use:
<sql-query name="getSomething">
<return alias="s" class="Something"/>
Although I'm not sure how you tell Hibernate that these are not persistent entities and thus I don't need any dirty checking...class Something is merely a DTO.
Another way is to may be use the reporting queries although it seems that it's only supported by HQL queries using the NEW keyword in the sql.
2.
If anyone also has any thoughts on how to easily transform a collection (List) that you get back from a named query into an array of DTO objects as in Something[], that would be great. I looked into implementing the ResultTransformer, but can't seem to find information without hardcoding the DTO class name. Each query needs to transform into a specific DTO array. I have over 10 various DTO types.
If anyone has any opinions on the two aforementioned issues, I'd be greatful and I'm sure others will be as well.
|