开发者

GWT + Hibernate : is it a sane idea to construct DetachedCriteria in the client (Javascript) side?

开发者 https://www.devze.com 2023-03-17 20:08 出处:网络
One requirement in our project is criteria builder in which Hibernate criteria is a perfect fit to back the feature.

One requirement in our project is criteria builder in which Hibernate criteria is a perfect fit to back the feature.

Rather than creating indirection, I prefer the client to directly construct DetachedCriteria object and have it sent to the server side to be executed.

Considering t开发者_JS百科hat our project is using GWT, which means that the DetachedCriteria will be constructed in the Javascript realm, is this a sane idea, or doable at all?


No, it's not a sane idea :-)

The GWT code should handle presentation logic. The way data is displayed in the presentation layer doesn't necessarily match the way this data is stored in database, and the presentation layer shouldn't even know Hibernate is used in the data access layer. Building a Criteria object is the role of the data access layer.

I would just use some kind of DTO containing the search criteria, pass this DTO to my service layer, which would give it to the data access layer (with potential additional search criterias depending on the context), which would build a Hibernate Criteria object.

Think about it: imagine the request needs to be done in HQL or SQL in the future because of limitations of the Criteria API. Would it sound normal to have to completely change the presentation and service layers?

0

精彩评论

暂无评论...
验证码 换一张
取 消