How to get lightweight objects from Hibernate without using proxy and/or lazy initialization?
I want to use some properties from a class in some situations and other properties in other situations, so my intetion was to instantiate the apropriate object in a query using "select new".
The following HQL statement works fine:
select new Store(store.id, store.description) from Store store
However I found that I could not do a nested instantiation like:
select new Store(store.id, store.description, new Section(store.section.id, store.section.name)) from Store store
I have the constructors to allow the instantiation, but the following Query Exception occurs:
net.sf.hibernate.QueryException: ( expected before ) in select [select new Store(store.id, store.description, new Section(store.section.id, store.section.name)) from Store store]
How can I solve this? It would be nice if we could have custom queries to fill the object according to our needs. In some cases I really do not want to get some properties and in other moments I need them. And we work disconnected from Hibernate session.
Thanks.
_________________ Regis Pires
|