Show HN: A new way of ORM in Java
IMHO, ORM solves wrong problem. I don&#x27;t see the mapping itself as a problem - in almost any language there are data structures which can represent data we query from db. The ability to map a table record to an instance of some class looks like a good idea initially. But with time you find yourself in the situation where you need to query only a subset of fields and you end up with several implicit contexts with its own set of accessible fields each.<p>The real problems are:<p>1. Boilerpalte we get in the code which extract query results. This issue is not universal. Psycopg in Python produces a lot less boilerplate than, for instance, JDBC. This problem is a lot more visible in statically typed languages.<p>2. Boilerplate we get creating queries. Conditionally turning part of queries on and off produces a lot of code. This is mostly due to SQL syntax being more friendly to human rather than machine. Infix logical operators in conditions, commas etc., makes it hard to write code which generates SQL.<p>3. SQL is not good at reusing query parts. Views don&#x27;t solve all problems.<p>The first problem is better to solve with code generation at compile time making it possible to perform all kinds of type check etc.
Generating SQL is not that easy without introducing some kind of intermediate language which is more code friendly. I think some kind of templating could solve the problem so that it would look essntialy like SQL but with ability switch part of the query on and off.
The hardest part is reuse which I don&#x27;t know how to address. For instance, adding a join to some ACL table with conditions to exclude entities the client is not authorized to access.