Hibernate + GWT: OpenSessionInViewFilter or DTO (view model objects)

142 views
Skip to first unread message

Rebornspirit

unread,
Feb 8, 2007, 9:31:21 AM2/8/07
to Google Web Toolkit
I would like to hear some advice on best practices.

Which one would you recommend:
- Hibernate integration with a OpenSessionInViewFilter?
- Or a GWT remote service which actually creates DTO's - meaning model
objects for a certain widget - out of multiple Hibernate instrumented
domain objects?

I prefer the second one because:
- there is a cleaner separation between the different layers
- no hibernate dependency on the view layer, which makes it easier to
switch to jdbc or something else. Because with option one you gotta
deal with the LazyInitException
- less traffic, you only send to the client exactly what he needs, in
the correct format
- ...

I would like to hear your thoughts...

Rob Jellinghaus

unread,
Feb 8, 2007, 7:59:18 PM2/8/07
to Google Web Toolkit
A plain OpenSessionInViewFilter won't work because GWT RPC will try to
serialize every lazy collection in your persistent object graph.

There are a couple of solutions. You could have a separate DTO
hierarchy. Or, you could have code that just creates copies of your
domain objects themselves, terminating lazy collections with nulls
instead -- basically an "object marshaling layer" that makes a
subsetted copy of your object graph. (This is good if you have no
control over your serialization layer; we're doing this with Axis 1.4
in another project now.)

Or, you can hook into GWT's RPC. See this thread -- http://
groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/
thread/669e3d31b60bb1be -- for an example of that.

Cheers!
Rob

Reply all
Reply to author
Forward
0 new messages