This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

A way to handle Hibernate's LazyLoading with remotingPage Title Module

I have also come accross a similar problem. My server has to have a very generic interface, since it has many clients (currently a webapp and a rich client), both of which can be extended by thirdparties through plugins. The requirements for these applications (in terms of the data they need) is not known to me, since it will depend on the client/plugin. So for example exposing a getUser() method that returns the User object and all associated related objects may make sense for the rich-client app but not for the webclient.

In the end what I decided to do was to expose a QueryManager service, which allowed the client to specifically get just what information it requires. In essense the QueryManager provides a number methods that take in a query and associated parameters and returns a List of the results. The QueryManager is
a bit smarter than I mention here, for example it can support multiple query
language flavors (currently HQL and SQL), provides names queries for often
used queries etc...

This design also meant I could get rid of all the methods I used to have in
my other service interfaces that were strictly related to data retrieval,
cutting down on the code drastically.

But for this to work you need to design your persistent objects with this in
mind. No lazy loading, for one. You also need to know who is executing the
queries if you have priviliged data and then use hibernate's filters to prevent
un authorised access to data. Since I was already using acegi, this was trivial.

Not using lazy loading may seem like a big compromise, but I have found it is
not since clients always load precisely what they need and nothing more.

Comment

I work on a 3-tiered app with Java clients and a Spring/Hibernate server acessed over RMI, so your approach is of great interest to me. However, I can't figure it out with so few code. Would you mind giving us a more detailed exemple, with a sample domain object and a bit of client code?

I'd be grateful for that. Regards,
Baptiste

Sure, I have run out of time today, but Iíll post something tomorrow.
Federico.

Comment

Ok, here is the code and a little example.
Not precisely a polished document , but it should get readable once you format de code. The JDK 1.5 parts should be easy to extract if you canít use them.
Hope this helps figuring things out, and if it doesnít donít hesitate to ask.

Regards,
Federico.

Comment

Ok, here is the code and a little example.
Not precisely a polished document , but it should get readable once you format de code. The JDK 1.5 parts should be easy to extract if you canít use them.
Hope this helps figuring things out, and if it doesnít donít hesitate to ask.

Regards,
Federico.

Thanks a lot. It's getting clearer but I still have difficulty getting the whole picture. I haven't worked with Java 1.5 and these kinds of aspects before, so this explains that.