-->
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.  [ 6 posts ] 
Author Message
 Post subject: Making lightweight objects for GUI dropdowns
PostPosted: Mon Sep 06, 2004 6:14 am 
Hi All,
I'm having a few problems working out what to do and how to do it. I've been reading the docs and the new Hibernate in Action, and have come a long way with that, but now I am at an impasse trying to work out the best solution for dropdowns.

I want to keep the dropdown handling and the editing of my one-to-many and many-to-many related objects all in the front-end.

I am using the Hibernate managed relationships framework, so my Hibernate objects have no foreign key getters and setters.

I want to cache dropdown lists in the application scope of my servlet container. Then I can easily retrieve a Hibernate object out of this list when the user selects from the dropdown. Then I can allocate it to the object being edited via its setRelatedThingObject() setter.

Obviously though I want really lightweight objects, but I can't figure out how to tell Hibernate to give me them.

At least, I can't stop Hibernate from populating my objects with the parent objects of one-to-many relationships, although I managed to disable the many-to-many relationships.

Should I set up individual queries for these dropdown objects then, specifying exactly which fields I want populating via HQL?

Also, is my strategy sensible?

Thanks
Adam


Hibernate version: 2.1.6 integrated through Spring

Mapping documents:

haven't got that far yet

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

MS Sql Server

Debug level Hibernate log excerpt:


Top
  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 11:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
to prevent loading a parent object
<many-to-one> : set the one side class as lazy="true"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 5:38 am 
Right, I got that. But also need to disconnect the objects, so lazy-loading isn't appropriate for me.

Also, in some cases I do want to have all the related objects instantiated automatically, e.g. when I am editing them.

But in this case for dropdown lists, I only want to have the object on its own without any of its related parents or children.

As far as I understand, since I don't want to use lazy-load, I can only have one mapping file for the object, then I can only have one or the other (with related objects, or without).

So it seems the best solution for me is to set up a query to provide the lists of dropdowns I require, and to instantiate them with the variables I choose:


Code:
<query>
  select new Country(c.countryId, c.name) from Country c
</query>


I'm going to try this but I'd appreciate it if anyone can tell me how orthodox this method is.

Thanks!


Top
  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
treehugger wrote:
Right, I got that. But also need to disconnect the objects, so lazy-loading isn't appropriate for me.

Eh? You can use lazy loading and dettached object. You just have to be sure not to access non id property on a lazy entity.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Nested instantiation using "select new"
PostPosted: Wed Oct 06, 2004 11:30 am 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
I am with the same problem: how to get lightweight objects from Hibernate?

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 also work disconnected from Hibernate session.

Thanks.

_________________
Regis Pires


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please read the wiki area (Tech design patterns -> Lightweight Pattern)

_________________
Emmanuel


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