For a new project using Spring with JDBCTemplates, iBatis / myBatis or Hibernate?

Hi, we are starting a project in which we must decide whether to use Spring JDBCTemplates, iBatis / myBatis or Hibernate for our persistence level. I am more or less familiar with the concepts of both of them, but I wonder what people currently tend to use.

My requirements:

  • keep everything as simple as possible
  • easy to learn and use
  • high performance
  • optimal developer productivity
  • should use Spring 3

As already noted, we would like to keep everything as simple as possible. My preferences tend to be towards iBatis / myBatis, because it looks easier to use, and we don't need a real OR Mapper. But I really look forward to learning from the guys who use this framework.

+6
source share
5 answers

I advise you to take a look at minuteproject reverse engineering solution for spring / hibernate / ibatis as well as JPA (2), as it meets your development requirements. There is one thing that it does not generate (yet) jdbctemplate.

Before choosing a technology, I will look at all of your points that fit the minuteproject method.

  • keeping everything as simple as possible : let minuteproject generate the code for you to save in iBatis (sqlMaps), in Hibernate (hbm files), in JPA (orm file or annotated objects), But all the additional frame integration: spring configuration, comprehensive stack DAO (not limited to basic CRUD operations). It can correspond to 20 to 40% of your application artifacts and time.
  • easy to learn and use : your model will become your technology textbook! Find out what was created. You can, of course, expand it to your specific needs.
  • high performance : in the minuteproject track for spring / hibernate or spring / JPA: minuteproject provides ehcache configuration generation integrated with the orm product. It provides and maintains a dao level with a custom query that you only need to specify.
  • optimal developer productivity . It helps you focus on your real business, and not on all the tedious tasks of orm / dao. It aligns the technology learning curve.
  • should be used with spring 3 : spring artifacts compatible with 2.5+

But the best that can judge is you, so try it on your model. To get a brief overview of the start / bin / start-console. (Cmd / sh) feature, point to your database and select the generation track. This usually takes a few minutes if your database (mysql, db2, oracle, hsqldb has a default value such as a hibernatedialect preset). For more advanced use, use the configuration (this is for all db).

Regarding which technology to use, I personally have production experience with all of them, but I would think that the bidirectional aspect of the orm framework, such as sleep mode, is a strong point over unidirectional sqlmap. It saves configuration and graphical navigation is intuitive.

Good: escaping a special character such as' is included in the orm framework. And this is the problem that you usually encounter when doing native sql in sqlmap, such lastname = 'o'hara' insert ...

I would go for Hibernate (among your chosen option), but go to JPA2 (if you turned it on). If you want real additional performance to integrate querydsl for the compiled criteria API.

+5
source

I worked with Ibatis and Hibernate. Ibatis is simple and simple. Hibernation can become difficult if you are not careful, but it is a lot for you. spring-jdbc is better than the original JDBC.

Hibernate's greatest advantage is the ability to map different databases. You can even disable schema prefixes. You have options such as using the in-memory database for testing, or if the developers have local databases other than the target product (for example, if you target Oracle and the licenses target the problem) or the ability to target multiple databases . Sleep id generator easily with hibernate. With Hibernate, native SQL is an option, but with Ibatis there is no choice.

It is also not possible to save Ibatis DRY display files. If you have multiple requests with different offers, you will get cut-n-paste. With Hibernate, there is almost no such duplication.

Both Ibatis and Hibernate, by the way, have a declarative caching mechanism. Of course, sleep mode is much more involved.

spring-jdbc shares all the flaws I listed for Ibatis. Also, I don't think it has a caching mechanism. its main advantage is that JDBC objects are not so well hidden, so you can directly access them more easily if you need it.

Spring integrates with all three alternatives; spring support is no different.

One more thing: Hibernate works great with artificial keys. He can manage composite business keys, but he works a lot more. Ibatis and spring -jdbc are not complex enough to solve this problem.

If your developers are cautious and thorough, and if you can simplify your approach (for example, using a session per request, not saving any objects from one session to another and using artificial keys), then go to Hibernate. If you decide that you don’t need the database abstraction that Hibernate provides, or if you don’t trust your developers with sharp tools, go with Ibatis. Keep spring-jdbc as a recession to make specific requests that need to be configured with jdbc using bare metal.

By the way, Grails and GORM make Hibernate much easier to experiment because there is much less time to install, Grails launches you using a database in memory, and you can do without writing map files.

+3
source

Hibernate offers you a nice and easy way to map your own SQL queries in addition to ORM, while iBatis offers only SQL matching. Thus, with Hibernate you have more options and, if necessary, you can use ORM or your own SQL. For this reason, I prefer Hibernate.

Hibernate definitelly integrates well with Spring. iBatis probably also does, but I have never used such integration.

These are my two cents. If someone has a different opinion, send another answer.

+2
source

For these two purposes: - keep everything as simple as possible - easy to learn and use

Both MyBatis and JdbcTemplate will work fine. Both of them simply provide a high-level API for accessing your database with SQL.

You save the code using MyBatis because it will be able to perform most of the mappings (from result sets to objects), and you will save objects if you use maps (dynamic interfaces that map methods to sql statements).

On the other hand, you are likely to get better performance with JdbcTemplate, because manually coded mappings are faster than introspection.

Regarding "optimal developer productivity." Hibernate is more productive than MyBatis / JdbcTemplate, but it requires more skills and experience, otherwise your performance may become very low.

All of them are really well integrated with Spring 3.

+1
source

Since there is no presentation layer, and it looks like most business rules will be outside the save layer, my suggestion would be Spring JDBCTemplate. Although I used ibatis before my experience with Hibernate and Spring far exceeded my experience with ibatis, I therefore offer the following reasons for my suggestion.

Hibernate - Since hibernation is an excellent basis for saving , it takes someone with experience to get the most out of hibernation. . Some developers see hibernate as a black box, and they carelessly treat their HQL and cause serious performance problems. Since you are looking to easily raise and understand the level of perseverance - I would not have avoided this. But , if you do not use sleep mode, you free up the simple caching system that sleep mode provides out of the box. The lack of a caching system in your drawings stinks, so I would think about integrating it into any other solution where performance is important.

Spring - Spring JDBCTemplates should be fairly lightweight for most people. This is not a new technology or infrastructure, but Spring's goal is to simply simplify use. Since one of your requirements is Spring3, would I suggest that most of you are already familiar with the idea of ​​injecting dependencies, string maps, and DTOs? Regardless of the solution you choose, I would also use Spring's transactional testing tools . Finally, debugging performance issues with JDBCTemplates is much simpler than in sleep mode.

Ibatis - Since my experience with iBatis is not enough, I would only suggest it on JDBCTemplates if your team had a positive experience with this tool. This is a slightly less popular solution for the other two, but it looks like a good medium-sized platform.

0
source

Source: https://habr.com/ru/post/892244/


All Articles