When to use Hibernate/JPA/Toplink?

后端 未结 6 434
情深已故
情深已故 2021-02-01 10:41

Right now I\'m making an extremely simple website- about 5 pages. Question is if it\'s overkill and worth the time to integrate some sort of database mapping solution or if it w

6条回答
  •  青春惊慌失措
    2021-02-01 11:24

    My rule of thumb is if it's read-only, I'm willing to do it in JDBC, although I prefer to use an empty Hibernate project with SQLQuery to take advantage of Hibernate's type mapping. Once I have to do writes, I go with Hibernate because it's so much easier to set a few attributes and then call save than to set each column individually. And when you have to start optimizing to avoid updates on unchanged objects, you're way better off with an OR/M and its dirty checking. Dealing with foreign key relationships is another sign that you need to map it once and then use the getters. The same logic would apply to Toplink, although unless they've added something like HQL in the 3 years since I used it, Hibernate would be much better for this kind of transition from pure SQL. Keep in mind that you don't have to map every object/table, just the ones where there's a clear advantage. In my experience, most projects that don't use an existing OR/M end up building a new one, which is a bad idea.

提交回复
热议问题