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
valves supplier's Gravatar Thanks for your post, I know it, thanks.
# Posted By valves supplier | 10/20/09 3:11 AM
fittings's Gravatar One of the biggest problems with working with data in a RIA/Flex application is that it's all or nothing, I also have this question, thanks!
# Posted By fittings | 10/20/09 3:13 AM
ugg boots sale,ugg boot sale's Gravatar ?A sound mind in a sound body.
# Posted By ugg boots sale,ugg boot sale | 10/20/09 5:53 AM
ugg boots sale,ugg boot sale's Gravatar ?A sound mind in a sound body.
# Posted By ugg boots sale,ugg boot sale | 10/20/09 5:54 AM
ugg boots sale's Gravatar it is very good!!
# Posted By ugg boots sale | 10/20/09 5:55 AM
world of warcraft eu's Gravatar Thank you!
# Posted By world of warcraft eu | 10/21/09 3:16 AM
world of warcraft eu's Gravatar Good information!
# Posted By world of warcraft eu | 10/21/09 3:17 AM
metin2's Gravatar you are right ,i think so
# Posted By metin2 | 10/21/09 3:52 AM
hj's Gravatar you are right
# Posted By hj | 10/21/09 3:55 AM
ball valves's Gravatar very well,thanks
# Posted By ball valves | 10/22/09 11:43 PM
fittings's Gravatar your write is very good,thanks for post.
# Posted By fittings | 10/22/09 11:44 PM
???'s Gravatar good
# Posted By ??? | 10/23/09 1:22 AM
ugg boots's Gravatar 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]
# Posted By ugg boots | 10/24/09 1:52 AM
cheap links of london's Gravatar It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
# Posted By cheap links of london | 10/26/09 3:37 AM
lycan's Gravatar As a member of a guild the results of your Guild Fights will have effects on both every guild member and the guild <a href="http://www.metin2.mobi"; title="metin2 yang">metin2 yang</a>itself. You must<a href="http://www.metin2king.com"; title="metin2 yang">metin2 yang</a> fight to gain <a href="http://www.metin2pro.com"; title="metin2 yang">metin2 yang</a>possession of one of the rare strongholds. As your guild?s might rises, you will get the chance to use <a href="http://www.metin2king.com"; title="metin2 yang">metin 2 yang</a>Non-Player-Characters in your stronghold and train them <a href="http://www.metin2fox.com"; title="metin2 yang">metin 2 yang</a>to be more effective.
# Posted By lycan | 10/26/09 6:29 AM
lycan's Gravatar As a member of a guild the results of your Guild Fights will have effects on both every guild member and the guild <a href="http://www.metin2.mobi"; title="metin2 yang">metin2 yang</a>itself. You must<a href="http://www.metin2king.com"; title="metin2 yang">metin2 yang</a> fight to gain <a href="http://www.metin2pro.com"; title="metin2 yang">metin2 yang</a>possession of one of the rare strongholds. As your guild?s might rises, you will get the chance to use <a href="http://www.metin2king.com"; title="metin2 yang">metin 2 yang</a>Non-Player-Characters in your stronghold and train them <a href="http://www.metin2fox.com"; title="metin2 yang">metin 2 yang</a>to be more effective.
# Posted By lycan | 10/26/09 6:32 AM
metin2 yang's Gravatar 100%safe metin2 yang!
metin2 powerleveling!
cheap metin2 yang!
# Posted By metin2 yang | 10/26/09 6:38 AM
ugg boots's Gravatar Nice post. I will go to this blog everyday.
I want to tell everybody that i ordered ugg boots in a store:http://www.landugg.com. I like them as i like this blog.All of my friends like the boots in landugg.com.
<a href=http://www.landugg.com>Cheap" target="_blank">http://www.landugg.com>Cheap UGG boots</a> from UGGs online store, you can get all kinds of UGGs boots such as <a href=http://www.ugg-store.net>Classic Cardy</a>. Moreover, if you are not quite clear on <a href=http://www.homeugg.com>UGG Colors</a>, you'll find the UGG Colors Guide in our store! It's free-shipping and non-tax now!Can you missing it?
# Posted By ugg boots | 10/26/09 12:13 PM
ugg boots's Gravatar <a href=http://www.landugg.com>Cheap UGG boots</a> from UGGs online store, you can get all kinds of UGGs boots such as <a href=http://www.ugg-store.net>Classic Cardy</a>. Moreover, if you are not quite clear on <a href=http://www.homeugg.com>UGG Colors</a>, you'll find the UGG Colors Guide in our store! It's free-shipping and non-tax now!Can you missing it?
# Posted By ugg boots | 10/26/09 12:15 PM
Uggs Boots On Sale's Gravatar <a href="http://www.selluggsboots.com";><strong>Uggs Boots on sale</strong></a>!Shop <a href="http://www.selluggsboots.com";><strong>Cheap" target="_blank">http://www.selluggsboots.com";><strong&g... uggs boots</strong></a> on Selluggsboots.Inc,100% authentic <a href="http://www.selluggsboots.com"; target="_parent"><strong>uggs</strong></a>,<a href="http://www.selluggsboots.com/classic-tall-ugg-boot...; target="_parent"><strong>classic tall ugg boots on sale </strong></a>,free shipping and super delivery,Enjoying shopping now!
# Posted By Uggs Boots On Sale | 10/27/09 6:40 AM
EAFSETERT's Gravatar <p>This article is very good!!<a href="http://www.mytobling.com/ugg-bailey-button-

boots-c-93.html">vUggs on sale</a></p>
# Posted By EAFSETERT | 10/28/09 12:30 AM
replica watches's Gravatar worn by <a href=http://www.overwatches.com/cartier-watches.html>... cartier watches</a> people who are <a href=http://www.wholewatches.com/omega-watches.html>... omega watches</a> considered to be rich. Rolex watches are the status symbol as much as what Rolls Royce car is. Basically a replica Rolex is an identical copy of the real <a href=http://www.overwatches.com/omega-watches.html>r... omega watches</a>, which looks the same on the surface. Generally speaking, it is quite difficult to tell the difference between an original and a fake Rolex.
# Posted By replica watches | 10/28/09 2:03 AM
rolex watches's Gravatar A good blog.The tragic consequences have been suffered by generations… We must break this obscene cycle,” the minister added.
# Posted By rolex watches | 10/28/09 11:55 PM
world of warcraf power leveling's Gravatar Thanks for your information, i have read it, very good?
# Posted By world of warcraf power leveling | 10/29/09 4:14 AM
???????'s Gravatar thanks so much 4 a nice topic

well done
# Posted By ??????? | 10/29/09 9:59 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.
# Posted By rolex watches | 10/30/09 7:58 AM
??SEO's Gravatar google seo serves
# Posted By ??SEO | 11/1/09 10:21 PM
powerleveling's Gravatar it's very nice!
# Posted By powerleveling | 11/2/09 4:16 AM
powerleveling's Gravatar it's very nice!
# Posted By powerleveling | 11/2/09 4:18 AM
acer aspire's Gravatar acer aspire
# Posted By acer aspire | 11/4/09 6:06 AM
valves manufacturer's Gravatar I agree with you do a wrok with data is very bad thing, your head will explode.
# Posted By valves manufacturer | 11/8/09 11:59 PM
justsoso's Gravatar <p>Whatever your fashion calling is or isn't, nothing says dedication like <a href="www.nfldream.net">NFL football jerseys</a>.<br>
<a href="www.purpleuggsonline.net">Ugg boots</a> are fast becoming one of the fashion trends of the decade<br>
get yourself a brand new pair of <a href="www.knittedugg.com">cheap Uggs</a>.</p>
# Posted By justsoso | 11/10/09 9:34 AM
aion kinah's Gravatar If you like using aion kinah to play the game.
# Posted By aion kinah | 11/18/09 11:19 PM
Atlantica online Gold's Gravatar <a href="http://www.u4game.com/Atlantica-87.html">A... online Gold</a> and the swordsman in the game. Is it solo able in the <a href="http://www.u4game.com/Atlantica-87.html">A... Gold</a>? It is not too bad, you should survive pretty well with <a href="http://www.u4game.com/Atlantica-87.html">b... Atlantica online Gold</a> if you equipment is up to date. Someone would like me who just reached IVI90 be able to survive more than one hit because <a
# Posted By Atlantica online Gold | 11/19/09 4:22 AM
valves manufacturer's Gravatar very good.thanks .
# Posted By valves manufacturer | 11/19/09 10:24 PM
air max shoes's Gravatar Any idea to solve this problem? The application works fine, but I want to solve this ;-)
# Posted By air max shoes | 11/23/09 7:13 AM
buy wholesale's Gravatar Banggood is your dream come true for all your wholesale products shopping needs. Our inexpensive selection of quality wholesale merchandise is out of this world. We sell everything you can imagine from to cell phone and hiphone supplies. If you are buying bulk merchandise for an apparel shop, then our amazing line of Computer,Video Games, Wedding Apparel, Jewelry and Watch and Brand Cell Phones are perfect for you. We also carry incredible wholesale supplies that would be great at a home improvement or China Wholesale.
# Posted By buy wholesale | 12/3/09 4:45 AM
banggood's Gravatar good! Support you!
# Posted By banggood | 12/3/09 4:48 AM
poll's Gravatar Did you ever play <a href="http://sllinden.org/">eve isk</a> in the past time? You should pay much attention to<a href="http://sealol.org/">fiesta Gold</a> if you do not play ever. <a href="http://silkroadol.org/">flyff penya</a> is so important to protect yourself. Believe that you could do <a href="http://mysilkroad.org/">habbo credits</a> much better.
# Posted By poll | 12/10/09 12:27 AM
china wholesale's Gravatar En...Very good!
# Posted By china wholesale | 12/11/09 12:38 AM
buy wholesale's Gravatar oh year...You write very well!
# Posted By buy wholesale | 12/11/09 12:42 AM
wastewater treatment's Gravatar 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.
# Posted By wastewater treatment | 12/22/09 12:30 AM
coagulant's Gravatar A bad beginning makes a bad ending.
# Posted By coagulant | 12/22/09 12:32 AM
wholesale's Gravatar <a href="http://www.***.com">.</a>
# Posted By wholesale | 12/24/09 4:56 AM
wholesale's Gravatar merry christmas
# Posted By wholesale | 12/24/09 4:58 AM
wholesale's Gravatar very good
# Posted By wholesale | 12/24/09 5:13 AM
cheap zeny's Gravatar <a href="http://www.cheers4game.com/product/Ragnarok_Online... zeny</a> is important in this game. If you do not want to be bullied by the high level of players, you should ear more <a href="http://www.cheers4game.com/product/Ragnarok_Online... zeny</a> which can you get a high level in short time. But it is difficulty for a new player to do this. Yet you are lucky because we sell the <a href="http://www.cheers4game.com/product/Ragnarok_Online... zeny</a>. You can buy <a href="http://www.cheers4game.com/product/Ragnarok_Online... zeny</a> from us. I believe that you can play happier with enough <a href="http://www.cheers4game.com/product/Ragnarok_Online... online zeny</a>.
# Posted By cheap zeny | 12/25/09 9:54 PM
# Posted By along\ | 1/8/10 5:39 AM
lili's Gravatar Once the pride,[url=http://www.metin2.mobi]metin2 yang[/url]we embrace the lofty ideal,[url=http://www.metin2store.com]metin2 yang[/url]
in a strange city,[url=http://www.metin2pro.com]metin2 yang[/url]looking for the true dream inside.[url=http://www.metin2king.com]metin2 yang[/url]
Once again,[url=http://www.metin2fox.com]metin2 yang[/url]the pure thought[url=http://www.wow-gold-tip.com]aion kinah[/url]
# Posted By lili | 1/11/10 7:57 AM
lili's Gravatar I imagine I 18 years oldI imagine I 18 years old
# Posted By lili | 1/11/10 7:58 AM
hardysale's Gravatar Legend has it that "ugg" is short for "ugly" - so, "ugg boots" apparently meant "ugly boots." For decades, "ugg" was generic term used for sheepskin boots made in Australia.The word was so commonplace that it was found in Australian dictionaries, and ugg boots were also known as "ug" or "ugh" boots. But in the United States, when people refer to "UGG boots," they're usually talking about the boots made by Deckers Outdoor Corporation, the parent company of "UGG Australia."So if you're traveling the world and talking about footwear, it's good to know that when the term "ugg boot" is used, it could be referring to an Australian-made sheepskin boot, or a popular brand name boot. site:hardysale.com
We sell authentic UGG Boots in our website for many year.We offer the best service and favourable price.People all aound the world buy our products do not pay for the shipping,we charge it!site:hardysale.com
Our UGG Boots have the advantages below:
* 100% authentic sheepskin for unrivalled comfort
* genuine twin-face sheepskin for refreshing comfort
* have a molded EVA light and flexible outsole designed for amazing comfort with every step.
*You can wear them up or style them folded down
Welcome to buy UGG Boots in our website,we offer the UGG Australia boots are all
with top quality!site:hardysale.com
# Posted By hardysale | 1/27/10 10:13 AM
shoedhardy's Gravatar what's the main point of the boots?the answer is to keep your feet warm.If you by one pair of boots put them on,especially in winter,you'll feel very tenderness and comfortable.they can make your feet warm.and youll find its really fashionable.you can tie-in each kind of clothes with them and still looks beautifull.site:shoedhardy.com
# Posted By shoedhardy | 1/27/10 10:13 AM
metin2 yang's Gravatar lili lili
# Posted By metin2 yang | 1/29/10 1:42 AM
metin2 yang's Gravatar lili
# Posted By metin2 yang | 1/29/10 1:44 AM
ugg boots's Gravatar In <a href="http://www.heyugg.com/ugg-bailey-button-boots-c-1.... boots</strong></a> you will not only get the highest quality products, but highly competitive prices and excellent customer service. If you can not find what you are looking for, or have any questions about our products, please visit our or contact us for more information. Children and <a href="http://www.heyugg.com/ugg-erin-baby-bootie-c-18.ht... boots</strong></a> are also available. As well as <a href="http://www.heyugg.com/ugg-coquette-slippers-c-16.h... slippers</strong></a> and Moccassins. In line with our footwear products, we also provide high-quality cashmere shawl, it is incredibly warm sheepskin jacket. Do not forget to visit our special programs page and to seize their a bargain of <a href="http://www.heyugg.com/ugg-erin-baby-bootie-c-18.ht... boots</strong></a>!
# Posted By ugg boots | 2/7/10 5:30 AM
golf shop's Gravatar this is good blog. thanks! share for us!
# Posted By golf shop | 3/9/10 5:25 AM
<A href="http://www.toppowerlevel.net"'s Gravatar Cooking
Another good skill to pick up. Some of the better meats give bonuses like +12 to spirit for 20 minutes. Stuff like that helps in the long run.
# Posted By <A href="http://www.toppowerlevel.net" | 3/31/10 11:43 PM
<A href='s Gravatar Cooking
Another good skill to pick up. Some of the better meats give bonuses like +12 to spirit for 20 minutes. Stuff like that helps in the long run.
# Posted By <A href= | 3/31/10 11:46 PM
wow power leveling's Gravatar Cooking
Another good skill to pick up. Some of the better meats give bonuses like +12 to spirit for 20 minutes. Stuff like that helps in the long run.
# Posted By wow power leveling | 3/31/10 11:48 PM
classic glasses's Gravatar Good Article!Thanks your sharing!Welcome to best glasses company! If you are looking for a pair of quality
# Posted By classic glasses | 4/2/10 12:55 AM
Made in China's Gravatar Made in China
# Posted By Made in China | 5/13/10 4:22 AM
replica watches's Gravatar once it leaves the field, but you may need to reset your watch <a href=http://www.watchesfan.com/>replica watches</a> you pay a little time to do a little research , you can <a href=http://www.corwatches.com/>replica watches</a> just a beautiful sporty watch, but also an extremely <a href=http://www.pocwatches.com/>replica watches</a> Replica has a great quantity of supply in compare to <a href=http://www.sanwatches.com/>replica watches</a> exceptional looksThe Colored Dial.JJ.05.15
# Posted By replica watches | 5/15/10 4:14 AM