We are developing a Swing-based application launched via WebStart and we would like to use Hibernate on the client side. I know this sort of architecture has been discussed here before, but I have somewhat different needs than those before me. We are going to use VJDBC (
http://vjdbc.sourceforge.net/) on the client side to connect to our database (the JDBC driver basically acts as a proxy to a servlet which actually runs the queries for those not familiar). The client Hibernate session will be read-only. Any changes to entities must happen on the server! We are communicating with our server via Spring remoting (not that it really matters, but thought I'd throw it in). Anyway, we're currently looking at two different scenarios:
1. Create one session with a long-running transaction so that all relationship traversals work without having to monkey with creating new sessions all over the place. Since we're read-only, this shouldn't be a big deal.
2. Scrap using Hibernate on the client altogether and just return our entities pre-loaded with whatever they'll need on the client side from our remote services.
I would like to hear what the experts think about this. If I choose option 1, I think I'll have to do some real coding to get Hibernate to work like we want (i.e. to support a pseudo transaction which doesn't really keep track of changes and allow the first-level cache to be garbage collected to avoid memory leaks). Option 2 means we have to do a lot of pre-fetching and write a lot of versions of query methods (or come up with a fetch graph API), but it is simple; if we got a LazyInitializationException, we'd know exactly how to fix it (make sure that relationship is fetched before returning). Am I missing something? Which way would you do it if you were in my situation? Any advice would be greatly appreciated!
Thanks,
James
Hibernate version: 3.2.2.ga [/list]