A memo about the types of Java O/R mappers and how to select them

What is O/R Mapper?

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

Classification of O/R 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.

Features of each O/R mapper

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.

More maniac (older)

List of open source Java O/R mapping software (January 2014 version)

How to select O/R mapper

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

A memo about the types of Java O/R mappers and how to select them
[Java] Types of comments and how to write them
How to convert A to a and a to A using AND and OR in Java
A story about misunderstanding how to use java scanner (memo)
Basics of Java development ~ How to write programs (variables and types) ~
[chown] How to change the owner of a file or directory
How to check for the contents of a java fixed-length string
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
How to get the absolute path of a directory running in Java
[Java improvement case] How to reach the limit of self-study and beyond
[Java] Memo on how to write the source
[Java] How to get the authority of the folder
Basics of Java development ~ How to write a program (flow and conditional branching) ~
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
[Java] How to get the URL of the transition source
How to write Scala from the perspective of Java
[Java] How to get the maximum value of HashMap
I summarized the types and basics of Java exceptions
[Technical memo] About the advantages and disadvantages of Ruby
[ruby] How to assign a value to a hash by referring to the value and key of another hash
Let's sort out the differences between Java substring and C # Substring, and how to port them.
How to display the select field of time_select every 30 minutes
A quick explanation of the five types of static in Java
I tried to summarize the basics of kotlin and java
Difference between Java and JavaScript (how to find the average)
How to create a form to select a date from the calendar
Command to check the number and status of Java threads
[Ruby] How to retrieve the contents of a double hash
How to develop and register a Sota app in Java
How to derive the last day of the month in Java
How to check the extension and size of uploaded files
[jsoup] How to get the full amount of a document
[Java] I thought about the merits and uses of "interface"
Considering the adoption of Java language in the Reiwa era ~ How to choose a safe SDK
How to write comments in the schema definition file in GraphQL Java and reflect them in GraphQL and GraphQL Playground
A memo of the program that allows you to realize that the probability of dice rolling is about 1/6
[Java] Various summaries attached to the heads of classes and members
How to create a jar file or war file using the jar command
[Rails] How to get the URL of the transition source and redirect
About fastqc of Biocontainers and Java
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
How to make a Java container
About TestSize advocated by Google and how to realize TestSize by Java and Maven
[Java] How to create a folder
[Java] How to search for a value in an array (or list) with the contains method
[jOOQ] How to CASE WHEN in the WHERE / AND / OR clause
A story about hitting the League Of Legends API with JAVA
From fledgling Java (3 years) to Node.js (4 years). And the impression of returning to Java
I tried to summarize the methods of Java String and StringBuilder
About Java primitive types and reference types
[Java] How to convert from String to Path type and get the path
How to make a Java array
How to deal with the type that I thought about writing a Java program for 2 years
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
How to operate IGV using socket communication, and the story of making a Ruby Gem using that method
A memo that was soberly addicted to the request of multipart / form-data
A memo when you want to clear the time part of the calendar
How to test a private method in Java and partially mock that method