|
| Index | Recent Threads | Unanswered Threads | List Polls | Public Albums | Who's Online | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 9 |
|
| Author |
|
|
Newbie Joined: May 14, 2003 Post Count: 20 Status: Offline |
Have you looked at Torque as an option? It is simple and easy to use, and takes all the hassel out of moving from one database (e.g. Oracle) to another (e.g. mysql) Generator : --------------- -It creates the database. [ant] -It creates all the tables. [ant] -It will populate the tables with initial values. [ant] -stores the schema in an xml format for database portability. [you-edit] Runtime: ----------- -can use various jdbc connection pools and/or jndi datasources. -generates an encapsulated java object persistence layer that is very easy to use. Admittedly, I have no Hibernate experience, but I do know that Torque seems to solve most the problems you are talking of. ============================================= Here is a simple example (schema, followed by simple code use) : <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_1.dtd"> <database name="metric" defaultIdMethod="idbroker"> <table name="task"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER"/> <column name="name" required="true" type="VARCHAR" size="255"/> <column name="description" required="false" type="LONGVARCHAR"/> <column name="category_id" required="true" type="INTEGER"/> <column name="date_created" required="true" type="TIMESTAMP"/> <foreign-key foreignTable="category"> <reference local="category_id" foreign="id"/> </foreign-key> </table> <table name="category"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER"/> <column name="name" required="true" type="VARCHAR" size="255"/> <column name="description" required="false" type="LONGVARCHAR"/> <unique> <unique-column name="name"/> </unique> <foreign-key foreignTable="task"> <reference local="id" foreign="category_id"/> </foreign-key> </table> </database> import gnu.metric.torque.Category; import gnu.metric.torque.CategoryPeer; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import org.apache.torque.util.Criteria; public class CategoryAction extends DispatchAction { private static final Criteria criteria = new Criteria(); public ActionForward display( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List categories = CategoryPeer.doSelect(criteria); request.setAttribute("categories", categories); return mapping.findForward("category"); } public ActionForward add( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Category category = new Category(); category.setName(request.getParameter("name")); category.setDescription(request.getParameter("description")); category.save(); return display(mapping, form, request, response); } public ActionForward delete( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("id"); Criteria criteria = new Criteria(); criteria.add(CategoryPeer.ID, id); CategoryPeer.doDelete(criteria); return display(mapping, form, request, response); } } |
||
|
|
Newbie Joined: May 14, 2003 Post Count: 20 Status: Offline |
here is an article that sums up the differences better than I could http://www.mail-archive.com/torque-user@db.apache.org/msg00792.html |
||
|
|
mvnForum Developer Vietnam Joined: Oct 16, 2002 Post Count: 2956 Status: Offline |
From your link I found this: I've used both and they are both good for different things. It's easier to get up and running with Torque, because it's simpler and doesn't try to do as much. On the other hand, with more complex projects, Hibernate may be better. I think Hibernate is more mature and feature-rich than Forque ![]() ---------------------------------------- Minh Nguyen mvnForum Developer Want a free, open source Java Jsp/Servlet forum, get mvnForum at http://www.mvnForum.com http://www.DienDanLinux.org |
||
|
|
mvnForum Developer Joined: Feb 27, 2003 Post Count: 185 Status: Offline |
Hibernate is probably the most popular ORM today. I have used it on few project and I also have analyzed few Torque projects but I am pretty sure that Hibernate would be much better solution for mvnForum than Torque. Since Hibernate persists POJOs (no need for extending/implementing Hibernate classes/interfaces) it would be much easer to isolate Hibernate code in DAO classes. On the other hand Torque needs few different classes (4 as I can remember) per table and they are Torque specific. |
||
|
|
Newbie Joined: May 14, 2003 Post Count: 20 Status: Offline |
I think I will check Hibernate out then. When just inserting new data (with Torque) it just uses the Bean Object that represents the table. In this case you just need to use one object. For the example of a "category table" : <code> Category category = new Category(); category.setName(request.getParameter("name")); category.setDescription(request.getParameter("description")); category.save(); </code> And if you want to do a select, delete, or update you use the Peer class and the Bean. And if you want a where clause you have to use the Criteria object. Three objects needed for a delete with a where clause. <code> Criteria criteria = new Criteria(); criteria.add(CategoryPeer.ID, id); CategoryPeer.doDelete(criteria); </code> |
||
|
|
Newbie Joined: Dec 6, 2003 Post Count: 20 Status: Offline |
Hibernate is probably the most popular ORM today. I have used it on few project and I also have analyzed few Torque projects but I am pretty sure that Hibernate would be much better solution for mvnForum than Torque. Since Hibernate persists POJOs (no need for extending/implementing Hibernate classes/interfaces) it would be much easer to isolate Hibernate code in DAO classes. On the other hand Torque needs few different classes (4 as I can remember) per table and they are Torque specific. yes , torque will generate 4 clazz, (base and peer..) and i think the seriousest problem is torque lacks document support ,if you are in trouble,its hard to find help.For this reason,i gave up using torque. |
||
|
|
Newbie Joined: May 14, 2003 Post Count: 20 Status: Offline |
I found the documentation to be quite good. The only problem I had was setting up a Datasource in tomcat, and I ended up looking at the Tomcat documentation to get that running. Besides that all the documentation I needed Torque provided. Although they may have updated it since you last looked at it. |
||
|
|
Member ![]() Joined: Jul 2, 2003 Post Count: 74 Status: Offline |
Hmm nice to hear all these pros and cons.. :) ---------------------------------------- http://code.google.com/p/myalumni/ MyAlumni - is a Java/Jsp open source project that help keep alive the line of communications between alumni/alumnus of any school that are all over the world. Manage profiles, hide emails, hide address, PM etc... |
||
|
|
mvnForum Developer Joined: Feb 27, 2003 Post Count: 185 Status: Offline |
Hmm nice to hear all these pros and cons.. :) Here is one comparison of ORM tools which compares probably all known ORM tools ORM tools Comparison |
||
|
|
|
|
|
Current timezone is GMT Jan 7, 2009 6:06:42 PM |


