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

瀏覽次數:142 次
跳到第一則未讀訊息

Rebornspirit

未讀,
2007年2月8日 上午9:31:212007/2/8
收件者: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

未讀,
2007年2月8日 晚上7:59:182007/2/8
收件者: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

回覆所有人
回覆作者
轉寄
0 則新訊息