I am writing a GWT application using Hibernate on the server side. Now I am completely confused about the correct way to transfer my objects to the client side of the GWT application in the least amount of code. I use Gilead to avoid having to double the number of classes in my domain model [1].
Firstly, my question is how should I open sessions and transactions. I originally did this on every call to the RPC server:
// begin rpc call
getCurrentSession
beginTransaction
// ...do stuff
commit
// session is automatically closed
// end rpc call
Since this opens and closes a session for each RPC call, does it also create a new connection to the database server each time?
In any case, as soon as I start using lazily loaded collections, I get the following exception using this pattern:
org.hibernate.HibernateException: collection is not associated with any session
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:449)`
, , Gilead , .
, , , , :
openSession
// begin rpc call
beginTransaction
// ...do stuff
commit
// end rpc call
// next rpc call
beginTransaction
// ...etc
, , , Session. -, createQuery(). ExecuteUpdate(), , , , . , , session.flush(), session.clear() .., "ClassCastException: null" Gilead Beanlib.
, - :
clients get an object from the server
client modifies object
client sends object back
server calls session.saveOrUpdate()
, , " ".
? ? , , , , , , .
[1] http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html