When you execute SQL in a Java application, you are wondering what to use. I wrote an article for such a person.
In conclusion, 2WaySql (DBFlute, uroboroSQL, Doma, etc.) is personally recommended.
The features of 2WaySql are as follows.
What is good is ...
Be flexible. It is easy to develop because it is made into an external file and SQL can be executed as it is with a SQL client. Also, it's easy to move to languages other than Java, and it's easy to move to other platforms.
If a query (Criteria API, JPQL, SQL, etc.) is written directly in Java, it depends on Java and the migration is low.
Development side It's easy to develop because it's just writing SQL. It is OK even if the developer level is low.
There is no need to remember Criteria API, JPQL, or anything unique to the product.
Excellent in terms of performance. It is easy to tune SQL because it is easy to add hints and change the SQL structure (such as changing the join order).
Performance tuning is difficult when writing in ORM without SQL.
Operability Since it is made into an external file, it is easy to investigate the range of influence and static check (such as prohibiting with clause).
If a query (Criteria API, JPQL, SQL, etc.) is written directly in Java, it will be very difficult to investigate the range of influence because it depends on Java. It's a waste to investigate how many SQLs there are. There may be an opinion that it can be judged on the DB side, but it is difficult to investigate because there are SQL for health check and SQL called from other than the application.
In ORM, if it is not performance or if it is a complicated query, you will end up writing SQL, but I have been writing various queries such as SQL-less, with SQL (external file), with SQL (Java direct writing). It tends to be out of control and difficult to investigate the extent of impact.
Looking at the above, it may seem that I hate ORM, but ... As an "individual" developer, I like to use it! !! ORM is honestly very convenient! !! However, it's too convenient and I can do various things. When there are many developers, it is difficult to control. So, personally, using ORM is a system that issues a lot of simple SQL (such as reference API). I think it should be limited when it is built. Or, by wrapping the ORM appropriately, there are restrictions on the functions that can be used by developers on a system-by-system basis. I think I need to.
Recommended Posts