-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: flyweight upcasting filter
PostPosted: Wed Sep 15, 2004 2:36 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Hibernate version:All versions

I've been working a lot with some fat objects recently and it has really got me thinking about a really cool feature that hibernate could do with ...

A flyweight upcasting filter.

Ok an example ....

IdAndTitleInterface {
Integer id;
String title;
}

MyFatClass implements IdAndTitleInterface {
Integer id;
String title;
100 other methods and variables.
}

IdAndTitleInterface idat = session.findWithInterfaceFilter("from MyFatClass",IdAndTitleInterface.class ) ......

So then hibernate wouldn't load up everything, just those 2 properties.

My idea is that this would only be used for read only objects.

The advantages would be ...

1) Faster for remote clients

2) Reduction of extraneous loading and would be simpler than lazy loading

3) Simpify stuff

4) You could have a couple of diffferent interfaces for the different users of your service/class

I'm not that experienced with hibernate but the only other way i could think
of doing it was something like this ....

select propertyimage.id,propertyimage.title from PropertyImage as
propertyimage where propertyimage.associatedProperty.id = ?
ORDER BY propertyimage.index ASC

Then iterating through the results and adding them into some DTO
class ... but that strikes me as not as elegant.

or I could do this ...

select propertyimage from PropertyImage as propertyimage where propertyimage.associatedProperty.id = ? ORDER BY propertyimage.index ASC

Then cast them to the shorter interface but this still hits the database a
lot where it isn't strictly necessary.

Perhaps I'm missing something but this seems like a good idea to me.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: my current code
PostPosted: Wed Sep 15, 2004 3:30 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
This is how I currently do it. This would be tedious to replicate in a
hundred or so functions.

public List getIImageIdAndTitleAssociatedWithProperty(Long propertyId) {

List list = getHibernateTemplate().findByNamedQuery("ImageIdIndexAndTitlesAssociatedWithAProperty",propertyId);
List propList = new ArrayList();
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Object object[] = (Object[]) iterator.next();
Long id = (Long) object[0];
String title = (String) object[1];
Integer index = (Integer) object[2];

ImageIndexAndTitlePropertyImageDTO obj = new ImageIndexAndTitlePropertyImageDTO(id,title,index);
propList.add(obj);
}
return propList;
}

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: i guess this must have been a stupid question
PostPosted: Fri Sep 17, 2004 9:29 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Not one comment ... I guess my idea sucked !

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 10:17 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"SELECT new ImageIndexAndTitlePropertyImageDTO(id,title,index) ... "


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 10:18 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
baliukas wrote:
"SELECT new ImageIndexAndTitlePropertyImageDTO(id,title,index) ... "


Wait a second , your telling me that works with hibernate 2.16 ?

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 10:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
of course - read the docs


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 10:21 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
It does !!!!!! Hibernate is even better than i thought !!! You guys are the
best !!!!

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: it will not work if the constructor contains Map's though ?
PostPosted: Fri Sep 17, 2004 2:04 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
baliukas wrote:
"SELECT new ImageIndexAndTitlePropertyImageDTO(id,title,index) ... "


Ok been playing arround with this and it doesn't seem to understand
construtor args that are collections.

Doesn't work ( descriptions is a map )
select property.descriptions from Property as property

Works
select elements(property.descriptions ),indices(property.descriptions ) from Property as property

Doesn't work
select new ie.jestate.bo.property.PropertySummaryDTO(property.id, property.descriptions ,property.summaryDescriptions ) from Property as property

Generates this error message

net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after: id [select new ie.jestate.bo.property.PropertySummaryDTO(property.id, property.descriptions ,property.summaryDescriptions ) from ie.jestate.bo.property.Property as property]

Am I missing something or is this normal behaviour, are there any plans
to implement this ?

It strikes me as a neat feature.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is normal, afaik it is not planned to implement this.


Top
 Profile  
 
 Post subject: yep been checking the hibernate 3.0 source
PostPosted: Fri Sep 17, 2004 2:27 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
michael wrote:
This is normal, afaik it is not planned to implement this.


I've been checking the hibernate 3.0 source code and there is no
reference to this.

It is a shame there is no plans to support this as I have tried to
design my application for easy internationalization and as a result
I am storing almost all my descriptions as java.util.Maps.

If I was to send the full object out to the web tier it would be far to
fat and cause scalablity issues.

I guess I'm back to square one on this one.

Thanks for your help anyhows.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 8:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This would be very, very difficult to implement.


Top
 Profile  
 
 Post subject: hmmm
PostPosted: Fri Sep 17, 2004 9:31 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
gavin wrote:
This would be very, very difficult to implement.


Gavin,

Ok I've been thinking about this but it's 3am over here so just in case my
reply comes out as complete nonsense I'm going to read it in the morning
before sending it.

I'm impressed that you think it would be difficult to implement though as
by all accounts you seem to be a top notch coder.

I dont really understand the internals of hibernate all that clearly but I
think I will try to learn a little more about them.

From a performance standpoint I think that this would make things
a lot more performant as you would not need to wrap each
map in a persistant class.

If you think of the possibilities it would be so cool if you could
custom wrap query results so that you never need to pass back
a class which is one variable larger than necessary without
going through the tedium of wrapping it yourself.

Although I'm a big fan of object mapping I've still got the old school
mentality of every byte counts and I need to come up with a plan to
lighten up my session storage requirements.

Thanks for taking the time to look at this.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 9:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Perhaps I misunderstood what you want, it's not clear.

Does the last argument of PropertySummaryDTO() constructor take a collection, or a single summaryDescription?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 9:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. Flattery will get you everywhere - it's such an underrated tool :-)


Top
 Profile  
 
 Post subject: ha ha
PostPosted: Fri Sep 17, 2004 10:05 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
gavin wrote:
P.S. Flattery will get you everywhere - it's such an underrated tool :-)


descriptions and summaryDescriptions are both maps.

I'm gonna wrap them in pojo's though, they will work that way
wont they ?

I do have the utmost respect for your work though, I don't know if
your a unix guy as well but I notice one of your compatriots
( Tridgell ) seems to be fairly busy with samba4 right now, another
great project might I add.

Anyhow I really am gonna have to crash now, have a good weekend
and thanks for taking the time to check this out.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.