12 Jan 2011 3:12 PM #1
Data persistence: Hibernate vs JDBC queries vs MyBatis
I'm newbie with GWT/GXT and I'm looking for best persistence way for my future apps. I was considering many variants of doing that so I decided to draw a graph (see attachment).
So my conclusions are:
1) Hibernate is the best persistence framework but it hates cooperation with GWT and a specially with GXT
2) JDBC it was just a joke
3) MyBatis is really great tool for gaining data from db, but writing mappers is the worst thing ever, but its fast, efficient and has great possibilities not seen in Hibernate.
4) Dozzer is server and user resourcess killer. You must write a lot of boiler plate code and it just copy data (sometimes a lot). Don't use it at any cost!!! Imagine server that runs 100 sessions and each bean request must use Dozzer.
5) DTO - similar situation. It's boilerplate, and it's just transforming one data type into other. There is no serious data processing. Use server resourcess wisely.
6) Gilead is copying hibernate beans states. It could be dangerous (just heard from few comments), hard to configure and integrate with other IoC frameworks (Guice in my case).
7) Best practise for me and maybe for you: find the shortest path on the graph from DB to the BaseModel bean on the client side.
8) MyBatis allows to map query results to the BaseModel beans (tested) so they don't need to be transformed many times and you don't have to care about it at all. The only thing is writing proper mappings.
This is my personal opinion and remember that I'm newbie. Please explain me if I'm wrong and give cons arguments. Maybe you know another ORM or similar to MyBatis framework that could give me as short path.
22 Jan 2011 5:30 PM #2
+1 for 4, 5, 6. I have worked in projects where everything was DTOed and it was madness. In general, I try to reuse entity beans vertically across application layers and use DTOs only where necessary (e.g. data projections).
I don't do much ExtGWT development, however, I do a lot of ExtJS and plain GWT. In both cases use Hibernate + Spring on the backend with Spring MVC as a RESTful web service gateway. This way, services are completely independent from any client toolkit. The downside is that you lose the convenience of the GWT RPC mechanism.
22 Jan 2011 8:51 PM #3
The new GWT 2.1 feature of RequestFactory can do away with the need to create BaseModelData and subclasses as DTOs. Instead, you maintain an interface representing each server entity you want access to on the client. This must still be maintained - if it automatically gave access to any get/set available on the server, building anything resembling a secure webapp would be next to impossible. So one must use the interface as a way to describe which properties may be loaded for use on the client.
AutoBeans (available in 2.1.1) can also provide similar functionality with a little less magic already done for you - you must implement your own mechanism to serialize data and request services. RF is implemented using AutoBeans.
Neither of these work with GXT 2.2 and prior - we should be seeing a 2.3 release coming soon with some wrappers over these beans to make them accessible from the existing Bindings and Store code, and 3.0 (coming this spring) should allow full integration to these.
FWIW, I am working up a GWT/GAE/Guice app to see how much trouble it really is to keep your persistence classes ignorant of the other layers in the app via RF. So far, the only detail is that each persistable instance must have an id and a version, and as of GWT2.1.1, id must be a String or a Long and the version must be an Integer - hopefully these restrictions will be looser soon. (note that the entity itself need not have the id and version, but that the server must be able to discover a unique and consistent id, and a version number which increases when changes occur). I hang out in ##gwt and #extgwt of irc.freenode.net if you have any questions about my approach.
27 Jan 2011 1:47 PM #4
I'm using EJB 3.x with JPA 2.0 (eclipselink).
I made DTOs but I'm waiting for the next version of GXT for removing them.
11 Feb 2011 7:19 PM #5
Thanks you for the post.
By chalu in forum Community DiscussionReplies: 1Last Post: 13 Feb 2010, 11:37 AM
By Dr.T in forum Ext 1.x: Help & DiscussionReplies: 4Last Post: 15 Jul 2009, 2:25 AM
By brookd in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 28 Apr 2008, 1:54 PM
By deitch in forum Ext 1.x: User Extensions and PluginsReplies: 9Last Post: 13 Dec 2007, 12:16 PM
By figaro in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 5 Oct 2007, 3:59 PM