Hi Pedro,
Thanks for your clarifications
> Do you understand my point of view?
Yes I do. Even if I don't entirely agree with you :-)
> Good JPA 2.0 things (in my opinion):
> * Java standard.
Yes. Unfortunately, though, a very invasive one
> * You can declare database mertadata by annotations.
Partially, yes. For rather simple relational schemata, this works. For
true SQL (incuding compound primary keys, check constraints, triggers,
auto-generated values from stored procedures, sophisticated indexes,
IOT, partitioning, custom storage clauses, etc.) it doesn't work. But
in many cases, this can be ignored, I agree.
> * Admits a metamodel based in classes.
Yes. But then, again, you're not doing SQL. We could start a religious
discussion here ;-) ... which we won't
> * Typesafe queries with a criteria API.
Type-safety is nice. It works well for checking syntax correctness
(DSL) and field/column type checking to some extent
As far as I understand, though, JPA also pretends to offer type-safety
on a record-level, which highly limits SQL features and scope. True
record-level type-safety cannot be simulated in Java, short of formal
support for tuple and record types. However, I was thrilled to see
Brian Goetz's recent mentioning of such ideas on the lambda-dev
mailing list, using a hash operator #:
http://mail.openjdk.java.net/pipermail/lambda-dev/2012-May/004979.html
The ideas include
#(a, b) // Tuple
#(a: 3, b: 4) // Record
If this is supported by the Java language, then true type-safety can
finally be implemented in SQL abstraction APIs like JPA or jOOQ. Scala
already simulates tuples, which leads to some increased typesafety.
> Bad JPA 2.0 things (in my opinion):
> * Adds an abstraction level on top of SQL: no control over
> generated SQL, cache mechanism (entity manager), etc.
Indeed. It doesn't run SQL, it runs JPQL, yet another QL highly
inferior to SQL, just like OQL, JPOQL, HQL, and many others.
> * The criteria API is horrendous, very far of SQL syntax.
I couldn't agree more on this one ;-) It's even quite far from the
JPQL syntax, which it really generates.
> I would like, ideally:
> * Java standard.
> * You can declare database mertadata by annotations.
> LOGICALLY, I'M RESPONSIBLE OF MANTAIN SYNCHRONIZED MY
> DATABASE AND MY ANNOTATIONS.
> * Admits a metamodel based in classes.
> * Typesafe queries with a fluent SQL-like syntax: JOOQ
> * Direct emission of SQL sentences (no cache, no sw layer).
I see. In the short run, if you really want to use jOOQ right now,
you'll probably have to resort to some tricks involving the Hibernate
code generator. For instance, you could:
- Define your annotated entities
- Generate an HSQLDB or H2 database from those entities
- Use jOOQ to generate jOOQ artefacts from that temporary database
In the long run, here's my point of view:
jOOQ is now quite mature and getting more and more popular. One of my
long-term goals is indeed to closely interact with JPA, as I do
believe that Java standards are a good thing, too, at least to some
extent. Already today, you can fetch data into your custom
JPA-annotated beans. Your suggestions go in a similar direction.
Also, source code generation from an "offline" database schema
definition (XML, CSV, annotated Java classes) is a good idea, as it
leads to better development processes.
While I do not agree that those "offline" database schema definitions
should be the primary schema definition as you will lose a lot of
features and scope from what a database really offers, I can see that
for some users, this is still an acceptable approach.
Besides, supporting your idea will help make jOOQ more suitable for
those that want to couple jOOQ and Hibernate/JPA.
From many recent feature requests, I start to realise that I will have
to completely re-engineer jooq-meta and jooq-codegen, allowing for
providing "plugins" as a schema source. Users (such as you) could
contribute new schema sources and code-generation targets. Those
"plugins", however, will not be part of the official jOOQ
distribution:
1) because there might be too many
2) because they're hard to integration-test
3) because I probably often won't agree with them :-)
4) because jooq-codegen / jooq-meta are nice additions to the jOOQ
core. I would really prefer to spend less time on code generation :-)
There are a lot of SQL features on the roadmap that I would prefer to
implement.
Yet, "plugins" allow for much more flexibility when using jOOQ.
I hope you understand that these things will not be implemented before
jOOQ 3.0 (hopefully in late 2012), though. I will track these ideas as
#1464:
https://sourceforge.net/apps/trac/jooq/ticket/1464
Any contributions are very welcome, too.
Cheers
Lukas
2012/6/1 Pedro Pastor <
pedropasto...@gmail.com>: