dpHibernate - Hibernate lazy loading with Adobe BlazeDS

One of the biggest problems with working with data in a RIA/Flex application is that it's all or nothing. You either need to get all of the data or write a lot of code to return the data in multiple requests. The problem is that good design means that we want to design our data object to match the data, not the UI. For instance a User might have an array of Orders which each have an array of Items. Seems simple enough, right. The problem is that this is a large complex objects which could require a query that joins multiple tables when returning data to your application. No big deal if you want to display all of the data. But if you are just trying to output the users name and email in a search result screen then this is a huge performance hit.

Luckily there is a solution, It is called lazy loading. JSP developers, which use the java hibernate framework, have been able to use lazy loading for years. But until now this did not work with remote client applications like Flex. For those of you who have tried, I'm sure your familiar with the dreaded LazyLoadingException. Frustrating huh. Lazy loading let's your define a complete object model, such as a User with an array of Orders. But only return the data you are actually using in your presentation layer (Flex). Avoiding that all or nothing data problem that is so common.

I'm happy to announce a new Digital Primates open source project. dpHibernate, add support to BlazeDS for Hibernate lazy loading. You can find both the java and the ActionScript parts of the project here: http://code.google.com/p/dphibernate

If you're not familiar with hibernate, check out http://www.hibernate.org. At a real high level, Hibernate is a java ORM tool, which lets you map java beans to a relation database. Hibernate does all of the sql work for you.

So how do dpHibernate work? dpHibernate is actually a combination of two code bases. First, there is a custom java adapter for the BlazeDS server. This HibernateAdapter understands the hibernate proxy objects and knows how to convert them into a special dpHibernate proxy which the AMF serializer will ignore and not try to initialize. This is how the proxy objects are able to go back to the client without getting the LazyLoadingException.

The second part of dpHibernate is an ActionScript library which gives your application the code it needs to understand these dpHibernate proxy objects. This AS library has the code to manage your ActionScript beans and knows how to call back to the server to load a proxy once that object has been touched, usually with a binding expression.

In case your wondering, how does dpHibernate differ from the hibernate support in LiveCycle Data Services ES? For one dpHibernate doesn't require LCDS it works with the open source BlazeDS server. The other big difference is that hibernate support in LCDS requires you to duplicate the lazy associations in the services-config.xml and you need to use an Assembler class to get the hibernate objects. dpHibernate let's you call any java method and return any hibernate object.

So check it out, if you can use it I'd love to hear about it. If it doesn't work for you I want to know about that too. And as with all open source projects this one can use as many eyes as possible on it too. If you find any hibernate configurations that don't work let me know. Or better yet, send me a test case with the right hibernate mapping files to recreate the issue.

Thanks, ---mike nimer mikenimer at yahoo.com

Comments
Steve Brownlee's Gravatar I can't wait to try this. I already know the project in which I'd like to use it.
# Posted By Steve Brownlee | 5/21/08 6:27 PM
Rodrigo P. Fraga's Gravatar Spring Integration?

And is coupled to hibernate, or
I can to use with a JPA implementation?

Thanks!

\o
# Posted By Rodrigo P. Fraga | 5/30/08 9:01 AM
Mike Nimer's Gravatar Yes spring is supported and as for JPA. Right now it's rightly coupled to hibernate class names. However It shouldn't be that hard to do the same thing for jpa in the serializer in the future
# Posted By Mike Nimer | 6/1/08 1:13 AM
Rodrigo P. Fraga's Gravatar Hi!,

I tried to use the dpHibernate, but I didn't have sucess!

My architecture is based in Spring+JPA+Hibernate Entity Manager.

The problem is that, when a lazy object is loaded, it only show the attributes of dpHibernate, such proxy, destination...

The real data, don't load! I think that is the mapping with annotations, because, I use only JPA, I use hibernate as a JPA vendor,
my entities, it don't couple with a framework[Hibernate], only with an API [JPA]

So, do you have any idea?

regards.
# Posted By Rodrigo P. Fraga | 6/1/08 11:33 PM
Mike Nimer's Gravatar Sorry I didn't see this right away, for a faster response can you post any follow ups in the dpHibernate discussion group.

It sounds like you aren't using the HibernateRemoteObject tag in your flex code. So we aren't able to wrap the results and do the right thing to load the proxy when you access a property in flex.

Any chance you post or email me a sample applicationt that I can use to walk through it with the debugger.

thanks,
---mike
# Posted By Mike Nimer | 6/10/08 12:45 PM
Den's Gravatar Mike,

did you check graniteds?

Den
# Posted By Den | 6/11/08 11:21 AM
Mike Nimer's Gravatar Yes I did, the difference is that this is a new adapter that works inside of official Adobe servers (BlazeDS and LCDS). Grantie also has hibernate lazy loading support too, but it is a whole new server. Plus I don't like the way it requires you to write your own externalizable methods. The idea with dpHibernate is to make it as seemless as possible to plug in.
# Posted By Mike Nimer | 6/14/08 1:58 PM
Bath pillows's Gravatar I tried to use it, but it has a lot of bugs.
# Posted By Bath pillows | 6/22/08 9:23 AM
Tadeu Rodrigo's Gravatar dpHibernate it´s really great!! I´ve just follow the setup/configuration
and everthing works fine. I´m using them with many tables
and relationships (one-to-many, many-to-one, many-to-many) working with lazy.
Besides, I had a problem with lazy at hibernate. I changed at hibernate configuration
files (cfg.xml) the propertie fetch="join" that solve the problem. But, there´s only one
error:
java.lang.NoSuchMethodError: org.hibernate.Query.setResultTransformer(Lorg/hibernate/transform/ResultTransformer;)Lorg/hibernate/Query;

at net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.getPkIds(HibernateSerializer.java:426)
at net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.getCollectionProxies(HibernateSerializer.java:365)
....

Any idea to solve this problem? The application works fine, but I want to solve this ;-)

[]´s
# Posted By Tadeu Rodrigo | 10/8/08 12:48 PM
Tadeu Rodrigo's Gravatar dpHibernate it´s really great!! I´ve just follow the setup/configuration
and everthing works fine. I´m using them with many tables
and relationships (one-to-many, many-to-one, many-to-many) working with lazy.
Besides, I had a problem with lazy at hibernate. I changed at hibernate configuration
files (cfg.xml) the propertie fetch="join" that solve the problem. But, there´s only one
error:
java.lang.NoSuchMethodError: org.hibernate.Query.setResultTransformer(Lorg/hibernate/transform/ResultTransformer;)Lorg/hibernate/Query;

at net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.getPkIds(HibernateSerializer.java:426)
at net.digitalprimates.persistence.translators.hibernate.HibernateSerializer.getCollectionProxies(HibernateSerializer.java:365)
....

Any idea to solve this problem? The application works fine, but I want to solve this ;-)

[]´s
# Posted By Tadeu Rodrigo | 10/8/08 2:02 PM
luos's Gravatar good
# Posted By luos | 11/11/08 1:52 AM
mb's Gravatar I think you are right
# Posted By mb | 11/11/08 1:53 AM
wow gold's Gravatar very god......
# Posted By wow gold | 5/18/09 10:00 PM
wholesale jewelry's Gravatar agree with you
# Posted By wholesale jewelry | 5/20/09 7:18 AM
handmade jewelry's Gravatar good website
# Posted By handmade jewelry | 5/20/09 7:19 AM
discount jewelry's Gravatar thanks for sharing
# Posted By discount jewelry | 5/20/09 7:19 AM
Angel's Gravatar Great..........

Thanks
# Posted By Angel | 5/24/09 10:52 AM
cheap wow gold's Gravatar http://www.igvir.com
http://www.igvir.com/wowus.php" target="_blank">http://www.igvir.com/wowus.php
http://www.igvir.com/woweu.php" target="_blank">http://www.igvir.com/woweu.php
# Posted By cheap wow gold | 5/29/09 12:41 PM
ed hardy's Gravatar good day
# Posted By ed hardy | 5/30/09 11:24 AM
haley's Gravatar Luckily there is a solution, It is called lazy loading. JSP developers, which use the java hibernate framework, have been able to use lazy loading for years. But until now this did not work with remote client applications like Flex. For those of you who have tried, I'm sure your familiar with the dreaded LazyLoadingException. Frustrating huh. Lazy loading let's your define a complete object model, such as a User with an array of Orders. But only return the data you are actually using in your presentation layer (Flex). Avoiding that all or nothing data problem that is so common.
<a href=http://www.batterieslaptop.net/fujitsu-fpcbp115-la...;|<a href=http://www.batterieslaptop.net/ibm-02k7052-laptop-...;

<a href=http://www.batterieslaptop.net/dell-3120341-laptop...;|<a href=http://www.batterieslaptop.net/fujitsu-fpcbp64-lap...;|<a href=http://www.batterieslaptop.net/dell-3120504-laptop...;
# Posted By haley | 6/2/09 7:19 AM
Sword of the New World Vis's Gravatar I really like your post, thanks for sharing.
# Posted By Sword of the New World Vis | 6/3/09 2:20 AM
4story Luna's Gravatar I agree with some of your views.
# Posted By 4story Luna | 6/3/09 2:21 AM
???'s Gravatar A slim, wide-eyed [url=http://www.mygamegold.net]mygamegold[/url]woman almost human in [url=http://www.virbanks.net/]virbanks[/url]features eyed the pair. Her nose [url=http://www.agamegold.org/]agamegold[/url]was sharp, but very elegant. She had a [url=http://www.tbcgold.net/]tbcgold[/url]pale, beautiful face the color[url=http://www.trade4game.org/]trade4game[/url] of ivory, and for [url=http://www.veryge.net/]veryge[/url]hair
# Posted By ??? | 6/3/09 6:31 AM
Atlantica online Gold's Gravatar I like it.
# Posted By Atlantica online Gold | 6/4/09 10:44 PM
last chaos gold's Gravatar it is a good game gold
# Posted By last chaos gold | 6/4/09 10:44 PM
2moons dil's Gravatar Do you know 2moons dil?
# Posted By 2moons dil | 6/4/09 10:45 PM
cheap aion kina's Gravatar Do you know the <a href="http://sellaoin.com/">aion kina</a>, in the game you need the <a href="http://sellaoin.com/">aion online kina</a>. It can help you increase your level. My friends always asked me how to <a href="http://sellaoin.com/">buy aion kina</a>, and I do not know he spend how much money to buy the <a href="http://sellaoin.com/">aion gold</a>, when I see him in order to play the game and search which the place can buy the
<a href="http://sellaoin.com/">cheap aion kina</a>. I am happy with him.
aion kina, aion online kina, aion gold, buy aion kina, cheap aion kina
# Posted By cheap aion kina | 6/4/09 10:59 PM
Rom Gold's Gravatar good site
# Posted By Rom Gold | 6/5/09 12:07 AM
rohan money's Gravatar good idea
# Posted By rohan money | 6/5/09 12:08 AM
rohan crone's Gravatar thanks for sharing
# Posted By rohan crone | 6/5/09 12:09 AM
buy habbo gold's Gravatar good
# Posted By buy habbo gold | 6/5/09 2:54 AM
World of Warcraft Gold's Gravatar The website sells the kinds of game gold, you can buy in here, and you can find the gold is very cheap.
# Posted By World of Warcraft Gold | 6/5/09 5:51 AM
World of Kung fu Gold's Gravatar If you have any good advice, please post it on our website, and our after service is also good.
# Posted By World of Kung fu Gold | 6/5/09 5:52 AM
requiem money's Gravatar Welcome to view our website and if you order form with us, we will give you a good price.
# Posted By requiem money | 6/5/09 5:53 AM
???'s Gravatar A slim, wide-eyed [url=http://www.mygamegold.net]mygamegold[/url]woman almost human in [url=http://www.virbanks.net/]virbanks[/url]features eyed the pair. Her nose [url=http://www.agamegold.org/]agamegold[/url]was sharp, but very elegant. She had a [url=http://www.tbcgold.net/]tbcgold[/url]pale, beautiful face the color[url=http://www.trade4game.org/]trade4game[/url] of ivory, and for
# Posted By ??? | 6/5/09 10:31 AM
# Posted By xunda | 6/5/09 2:46 PM
# Posted By igvir | 6/8/09 4:26 AM
wholesale jewelry's Gravatar thanks for sharing.
# Posted By wholesale jewelry | 6/8/09 6:07 AM
wow gold's Gravatar wow gold say waht do you know
<a href="http://www.game4power.com/">Wow Gold</A>,
<a href="http://www.game4power.com/"><strong>... wow gold </strong> </A>,
<a href="http://www.game4power.com/buy-gold/">; wow gold cheap </a>.
# Posted By wow gold | 6/9/09 4:28 AM
cheap wow goldow gold's Gravatar cheap wow gold here,
<a href="http://www.wowgoldone.com/">;cheap" target="_blank">http://www.wowgoldone.com/">;cheap wow gold </a>,
<a href="http://www.game4power.com/">Buy Gold Wow </A>.
<a href="http://www.wowgoldone.com/">; cheapest wow gold </a>,
# Posted By cheap wow goldow gold | 6/9/09 4:31 AM
world of warcraft gold's Gravatar a man must do what he can do about buy wow gold
<a href="http://www.itemchannel.com/">; world of warcraft gold</a>,
<a href="http://www.itemchannel.com/">; wow gold </a>
<a href="http://www.itemchannel.com/?op=powerleveling"...; wow gold powerleveling </a>.
# Posted By world of warcraft gold | 6/9/09 4:33 AM
wow gold's Gravatar When the wolf [url=http://www.game4power.com/" target="_blank">http://www.game4power.com/]wow gold [/url] finally found the hole [url=http://www.game4power.com]Buy Wow Gold[/url] in the chimney he [url=http://www.wowgoldone.com/]Cheap WoW Gold[/url] crawled down and KERSPLASH right into that kettle of water [url=http://www.wowgoldone.com/]cheapest wow gold[/url] and that was the end of his troubles with the big bad wolf.

[url=http://www.game4power.com/" target="_blank">http://www.game4power.com/]game4power[/url],[url=http://www.game4power.com/" target="_blank">http://www.game4power.com/buy-gold/" target="_blank">http://www.game4power.com/" target="_blank">http://www.game4power.com/buy-gold/]buy cheap wow gold [/url]
# Posted By wow gold | 6/9/09 4:39 AM
Replica Rolex's Gravatar <a href="http://www.rolexreplicas2u.com"><strong...;Replica Rolex</strong></a>.
<a href="http://www.rolexreplicas2u.com"><strong...; Rolex watches</strong></a>.
<a href="http://www.rolexreplicas2u.com"><strong...;swiss" target="_blank">http://www.rolexreplicas2u.com"><strong... replica</strong></a>.
# Posted By Replica Rolex | 6/10/09 7:17 AM
Rolex watches's Gravatar I was just now googling around about this when I came upon your post. I’m simply visiting to say that I really liked seeing this post, it is really well written. Are you considering blogging more on this? It looks like there is more depth here for later posts.
# Posted By Rolex watches | 6/10/09 7:23 AM
Darkfall Gold's Gravatar good
# Posted By Darkfall Gold | 6/10/09 10:57 PM
???'s Gravatar A slim, wide-eyed [url=http://www.mygamegold.net]mygamegold[/url]woman almost human in [url=http://www.virbanks.net/]virbanks[/url]features eyed the pair. Her nose [url=http://www.agamegold.org/]agamegold[/url]was sharp, but very elegant. She had a [url=http://www.tbcgold.net/]tbcgold[/url]pale, beautiful face the color[url=http://www.trade4game.org/]trade4game[/url] of ivory, and for [url=http://www.veryge.net/]veryge[/url]hair
# Posted By ??? | 6/11/09 6:35 AM
cheap jewelry's Gravatar good website
# Posted By cheap jewelry | 6/12/09 6:49 AM
discount fashion jewelry's Gravatar we engaged in discount jewelry,cheap jewelry,handmade jewelry,discount fashion jewelry,china jewelry,wholesale discount jewelry,discount china jewelry,discount handmade jewelry,handcarfted jewelry,discount costume jewelry,discount pearl jewelry,discount gemstone jewelry,discount turquoise jewelry,discount coral jewelry,discount shell jewelry,discount crystal jewelry,discount jewellery,cheap jewellery,handmade jewellery,discount fashion jewellery,china jewellery and so on.
# Posted By discount fashion jewelry | 6/12/09 6:50 AM
???'s Gravatar A slim, wide-eyed [url=http://www.mygamegold.net]mygamegold[/url]woman almost human in [url=http://www.virbanks.net/]virbanks[/url]features eyed the pair. Her nose [url=http://www.agamegold.org/]agamegold[/url]was sharp, but very elegant. She had a [url=http://www.tbcgold.net/]tbcgold[/url]pale, beautiful face the color[url=http://www.trade4game.org/]trade4game[/url] of ivory, and for [url=http://www.veryge.net/]veryge[/url]hair she wore a wondrous mane of downy feathers.
# Posted By ??? | 6/16/09 1:19 PM
cheap Lord Of The Rings Gold's Gravatar Do you know this game ?
# Posted By cheap Lord Of The Rings Gold | 6/17/09 10:08 PM
9 Dragons gold's Gravatar you can also borrow 9 Dragons gold from other players
# Posted By 9 Dragons gold | 6/17/09 10:28 PM
buy AO credits's Gravatar But you can buy AO credits
# Posted By buy AO credits | 6/17/09 10:29 PM
2moons gold's Gravatar My brother often goes to buy 2moons gold and play it.
# Posted By 2moons gold | 6/17/09 10:30 PM
rappelz rupees's Gravatar good site
# Posted By rappelz rupees | 6/17/09 10:30 PM
mabinogi gold's Gravatar i think it is good
# Posted By mabinogi gold | 6/17/09 10:38 PM
LOTRO Gold's Gravatar i liek it
# Posted By LOTRO Gold | 6/17/09 10:39 PM
lastchaos money's Gravatar I really like your post, thanks.
# Posted By lastchaos money | 6/18/09 12:16 AM
rs gold's Gravatar But I could not like spending my own <a href="http://www.gamekoo.com/product/RuneScape_II_gold.h... gold</a>.
# Posted By rs gold | 6/18/09 5:51 AM
buy runescape's Gravatar You also cost buy runescape</a> to help your character to reach level high.
# Posted By buy runescape | 6/18/09 5:52 AM
Tibia Gold's Gravatar Tibia Gold and the game I have played for about 3 years now and I have always found it fun to play.
# Posted By Tibia Gold | 6/18/09 5:55 AM
???'s Gravatar A slim, wide-eyed [url=http://www.mygamegold.net]mygamegold[/url]woman almost human in [url=http://www.virbanks.net/]virbanks[/url]features eyed the pair. Her nose [url=http://www.agamegold.org/]agamegold[/url]was sharp, but very elegant. She had a [url=http://www.tbcgold.net/]tbcgold[/url]pale, beautiful face the color[url=http://www.trade4game.org/]trade4game[/url] of ivory, and for [url=http://www.veryge.net/]veryge[/url]hair she wore a wondrous mane of downy feathers.
# Posted By ??? | 6/18/09 10:21 AM
best-tutor's Gravatar best-tutor.com

http://www.best-tutor.com

good site
# Posted By best-tutor | 6/20/09 8:57 AM
Rolex's Gravatar Best Quality Guarantee, Cheap Price,<A href="http://www.newstylerolex.com/"; title="Cheap Brand Name Watches">Rolex</A>-
<A href="http://www.newstylerolex.com/";>Rolex Replica</A>-
<A href="http://www.newstylerolex.com/";>Replica" target="_blank">http://www.newstylerolex.com/";>Replica Rolex</A>-
<A href="http://www.newstylerolex.com/"; title="Cheap Brand Name Watches">Replica Watches</A>-
<A href="http://www.thecompany-web.com/">????</A... time!
# Posted By Rolex | 6/21/09 1:45 AM
louis vuitton's Gravatar there is a custom java adapter for the BlazeDS server. This HibernateAdapter understands the hibernate proxy objects and knows how to convert them into a special dpHibernate proxy which the AMF serializer will ignore and not try to initialize.
http://www.replicaslouisvuitton.com/replica-louis-...
# Posted By louis vuitton | 6/24/09 12:52 AM
daily news's Gravatar Yes I did, the difference is that this is a new adapter that works

inside of official Adobe servers..
# Posted By daily news | 6/24/09 1:03 AM
daily news's Gravatar Doesn't seem to be much of a point is it? Isn't the entire point

behind that.
http://alextomi.blogspot.com/

http://marketnew.blogspot.com/
# Posted By daily news | 6/24/09 1:05 AM
E-pal online dating Web site's Gravatar http://www.mail-sonata.com/
http://www.thewoodtrader.com/
http://www.h-delivery.net/
http://www.deai-dating.net/


E-pal online dating Web site
E-pal online dating Web site
E-pal online dating Web site
E-pal online dating Web site
E-pal online dating Web site
# Posted By E-pal online dating Web site | 6/24/09 4:08 AM
buy wow gold's Gravatar They had joined[url=http://www.game4power.com/]game4power[/url] the humans, elves, dwarves, and [url=http://www.game4power.com/]Buy Wow Gold[/url]dragons to decimate the demonic warriors and ghoulish beasts and push the[url=http://www.aocsale.com]aoc gold[/url] remnants back into [url=http://www.game4power.com/buy-gold/" target="_blank">http://www.game4power.com/buy-gold/]wow gold cheap[/url]the hellish beyond. Thousands [url=http://www.vipwarhammergold.com]warhammer gold
# Posted By buy wow gold | 6/27/09 7:56 AM
cheapv's Gravatar cheap wholesale from china the best choose is www.cheapv.com cheapest price and all free shipping discount paypal ,asa cell
as cellphone mp4 mp3 mp5 player iphone touch iphone nano all wholesale there direct from factory ,you can have a look .
http:www.cheapv.com
# Posted By cheapv | 6/29/09 6:10 AM
Terrible online dating Web site's Gravatar http://www.scitexdv.com/

Terrible online dating Web site
# Posted By Terrible online dating Web site | 6/29/09 10:43 PM
cheap wow gold's Gravatar http://www.wowgolds.org have 3 years sales experience in world of warcraft. We are committed to provide users with fast, safe and cheap wow gold,wow accounts and powerleveling services!"
# Posted By cheap wow gold | 7/2/09 4:41 AM
runescape accounts for sale's Gravatar http://www.accountmmo.com is the best way to buy runescape accounts or sell runescape accounts. There are also hundreds wow accounts for sale. Update wow accounts everyday.100% safe guaranteed for buy wow account or sell wow accounts.
# Posted By runescape accounts for sale | 7/2/09 4:41 AM
wow account's Gravatar http://www.accountmmo.com supply cheap wow account,sell wow account,WoW account,buy WoW account,more World of Warcraft account on our website!
# Posted By wow account | 7/2/09 4:42 AM
[Home]