The name "O/R Mapper" sounds like a special move for elementary school students. Recently, I had the opportunity to come into contact with various O/R mappers in my work, so I summarized what I researched.
O/R mapping is the conversion of data formats between objects and relational databases (RDBs) in object-oriented programming languages. What is IT Glossary -O/R Mapper
Simply put, it bridges RDB with programming languages such as Java.
Those who want to know more Object-relational mapping (https://qiita.com/yk-nakamura/items/acd071f16cda844579b9) Role and Benefits of O/R Mapping
Each has its advantages and disadvantages, so which O/R mapper is better depends on the project. Please read this first rather than researching various things. Points for selecting Java OR mapper
In summary, it looks like this. JDBC wrapper type, easy to understand for beginners. It tends to be redundant. SQL mapper type ↑ Query builder type ↓ O / R mapper type learning cost is required. The degree of freedom is high, but the difficulty of operation is also extremely high. Below is a list of typical O/R mappers.
Spring JDBC### A JDBC wrapper that can be used within the Spring Framework. ⭕️ Developers do not have to be aware of Connection and Prepared Statement. ⭕️ All you have to do is describe where to refill from the ResultSet. ⭕️ Can be used in other environments such as Java EE environment. ⭕️ Easy for beginners to understand the connection between programming languages and RDBs. ❌ Since the SQL part is solidly written in the class file, it cannot be reused when acquiring similar data. Somewhat redundant. Poor maintainability. ❌ Since it is written solidly in the Java class file, errors such as grammar are not detected during coding. Therefore, it is often noticed only after it is executed.
iciql### One of the JDBC libraries. ⭕️ Provided as a single jar file ⭕️ Can be used without a configuration file (no need to set in xml) ⭕️ JDBC description can be simplified. ❌ Is there a problem with the automatically generated SQL date-related processing? [Java] Easy DB access with iciql [OR mapper] Try to introduce ICIQL About O/R mapper iciql
DbOom### One of the JDBC libraries. ⭕️ Provided as a single jar file ⭕️ JDBC description can be simplified. ❌ There are few Japanese documents DbOom (Official) Copy and paste of the following site Comparison of Java DB access libraries
Jodd seems to be easy to use because it can be cut out for each function. The SQL to be executed can be acquired in the parameter embedded state, which is advantageous for debugging. There is insert () that can save Model as it is. There is also an auxiliary script for update. It may be nice to have a function such as a session. Transactions are generally supported. Camel <-> snake With conversion function. There seems to be a cache. You have to stack up the initial settings yourself, but it feels like you have all the necessary tools. It's good not to do anything extra, but it may be troublesome. Jodd's JTX seems to be cut out and used when using other libraries.
Apache Commons DbUtils### One of the JDBC libraries. The amount of description in the library itself is small, and the purpose is to run it at high speed. ⭕️ Provided as a single jar file ⭕️ JDBC description can be simplified. ❌ There are not many advanced functions. Apache Commons DbUtils (Official)
MyBatis### SQL mapper type. Write SQL in an XML file. ⭕️ Since the official document supports super-other languages, it is kind to Japanese people who are allergic to offshore development and English. (English, Japanese, Chinese, Spanish ...) ⭕️ High degree of freedom in SQL ❌ XML rules are troublesome. You need to understand how to handle the description of inequality signs and conditional branches.
DOMA### SQL mapper type. An O/R mapper perfect for personal projects and systems without complex processing. It is used when there are many processes that can be CRUDed by one entity. ⭕️ 2WaySQL。
2WaySQL is simply SQL that can be executed by pasting the SQL as it is, or by changing the parameters in the application.
Source [For super beginners] Mirage SQL super introduction ⭕️ Automatically prepares DML for one entity in the DB. ❌ In the case of SQL that requires table join, it is necessary to create a custom query. ❌ It is not possible to use two SQLs in one class file. Only the first SQL is executed.
jOOQ### Query builder type. ⭕️ SQL is automatically generated, so you don't have to worry about typos. ❌ Is there a limit to expressing complex SQL?
JPA### O/R mapper type. JPA is just a "specification", so you need to implement it with eclipseLink or Hibernate instead of using it alone. JPA can do advanced things, so the learning cost is an order of magnitude. Shouldn't it be introduced easily? After all this site is the strongest. .. .. Points for selecting Java OR mapper (repost)
① DB can be newly registered (2) There are few requirements for complicated SQL such as set operations and subqueries in the FROM clause. ③ There is at least one person in the project who has read through "Perfect Java EE". If there is an item that does not apply to even one item, it may be better to use another OR mapper.
⭕️ There is vendor support. It has become a standard technology. ❌ JPA specifications are over 600 pages in English and the learning cost is high! Muri! Yomi Takunai!
eclipseLink### O/R mapper type. Used to implement JPA. SQL is automatically generated by the processing inside the framework. I want to do the same with Hibernate, but there are some subtle differences in the generated SQL.
Hibernate### O/R mapper type. Used to implement JPA. SQL is automatically generated by the processing inside the framework. It's the same as eclipseLink, but there are some subtle differences in the generated SQL.
List of open source Java O/R mapping software (January 2014 version)
I thought I'd write it myself, but this article was still very easy to understand. Please try this already. I've written so far, but you only have to look at this article from the beginning ... Slide 62 and later are already the answer (ry) Points for selecting Java OR mapper
Please do not hesitate to point out any mistakes. Also, if you have any supplements, I would appreciate it if you could comment.
No, please supplement it. If you are familiar with this matter, please tell yourself. Deadly O/R Mapper! !! !!
Points for selecting Java OR mapper (repost) Object-relational mapping (https://qiita.com/yk-nakamura/items/acd071f16cda844579b9) DOMA DOMA bind variable comment mybatis DBFlute About Outside SQL (Outside Sql) jOOQ Comparison of Java DB Access Library Differences between JPA, Hibernate, EclipseLink-Codeflow JPA Basics 1 (with description about eclipseLink) [For super beginners] Mirage SQL super introduction (repost) Must-see for young Java engineers. 23 Framework Tools You Should Know IT Glossary -What is O/R Mapper (repost) [Java] Easy DB access with iciql [OR mapper] Try to introduce ICIQL DbOom (Official) Apache Commons DbUtils (Official)
Recommended Posts