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.  [ 3 posts ] 
Author Message
 Post subject: Lightweight objects using dynamic instantiation
PostPosted: Sat Oct 09, 2004 10:29 am 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
A recommendation we found in Hibenate forum is that in most cases returning all the properties does not decrease performance. In our case we work with Swing applications and detached objects which we serialize to client apps. These objects must be lightweight and we avoid serializing properties we won't use.

Many messages in Hibernate forum recommends projection and lightweight pattern as solutions to the lightweight object issue.
We think another alternative is to use "select new" feature.
We prefer to instatiate an object according to our needs instead of doing a projection for further filling an object. This way we can get lightweight objects from the query, without having to create additional hibernate mappings or java classes (lightweight pattern). So if we have 40 properties in Store class and just want 2 of them in some situation (remember we will serialize the object and transmit it over the network), we just do:

Code:
select new Store(store.id, store.description) from Store store


That's nice. Hibernate allows it. This feature is really wonderful!!!

Now we submit some sugestions to your appreciation:

1. If we want a lightweight Section object inside Store, we would have to do a nested dynamic instatiation like this:

Code:
select new Store(store.id, store.description, new Section(store.section.id, store.section.name)) from Store store


That code is not allowed in Hibernate, since it does not support nested dynamic instantiation.
So our first sugestion is to include this feature in future Hibernate releases.


2. Another code that does not work in Hibernate is:

Code:
select new Store(store.id, store.description, elements(store.subsections)) from Store store


Hibernate "select new" does not allow use of collections. It searches for the constructor Store(int id, String description, Subsection subsection) and not Store(int id, String description, Collection subsections).

That feature would be nice, since the properties of type Collection inside the new Store object are null and they cannot benefit from Hibernate Lazy Collection feature.

Hibernate is a fantastic persistence framework which is becoming even better.
We would like to hear from Hibernate team and from community about our sugestions. What is your opinion about them?

_________________
Regis Pires


Top
 Profile  
 
 Post subject: Re: Lightweight objects using dynamic instantiation
PostPosted: Sun Oct 10, 2004 1:36 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It must be possible to use "nested projection" without this scripting too.

Code:
select new Store(store.id, store.description, store.section.id, store.section.name) from Store store


Code:

Store(int id,  String description, int selectionId,  String selectionName) {

this(id,description);
this.selection = new Selection(selectionId, selectionName );

}


Top
 Profile  
 
 Post subject: does the same feature existing for Criteria Projection?
PostPosted: Fri Jan 26, 2007 12:26 pm 
Newbie

Joined: Fri Apr 29, 2005 10:43 am
Posts: 2
Does this feature exist for Projection in Criteria?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.