-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Nested instantiation using "select new"
PostPosted: Wed Oct 06, 2004 11:36 am 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 1:25 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
I don't think HQL supports nested new's.


Top
 Profile  
 
 Post subject: Suggestion of nested instantiation using HQL "select ne
PostPosted: Wed Nov 10, 2004 10:04 am 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
We wanted to use nested new's feature, but as Hibernate didn't support it, we have done some custom changes in our Hibernate 2.1.6 source code in order to support it.

The changed classes were:
net.sf.hibernate.hql.QueryTranslator
net.sf.hibernate.hql.SelectParser
net.sf.hibernate.impl.IteratorImpl
net.sf.hibernate.impl.ScrollableResultsImpl

I would like to know if Hibernate Team has some interest to analyse this little contribution and maybe add this feature to future versions of Hibernate.
And if you want to see the code, how could we send it for your analysis?

_________________
Regis Pires


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 10, 2004 10:11 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please post a JIRA issue and attach any files you might have. Thanks!

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.