SelectSelectStep<Record> select() to return the SelectSelectStep without declaring the fields (it's useless declaring fields, please read the following)
<T> List<T> list(Select<?> select)
<T> T uniqueResult
list and uniqueResult take in input the select statement generated with jOOQ and build the SQLQuery code using 1 and 2.
with the tables discovery, I take the first table and use it for the root entity. And then I use them to generate select statement with this form: select {tableAlias1.*}, {tableAlias2.*} from
with the join conditions, i am able to found (using the Hibernate Session "Metadata" API) the Entity relations between tables
Session session = ...;
HibernateDSLContext hdsl = HibernateDSLContext.using(session);
Select<?> select = hdsl.select().from(...).join(...).on(...);
List<Entity> hdsl.list(select);
For the point 1 and 2 at first i used GSP (General SQL Parser)
at the end i tried to use VisitListener of jOOQ (in the next post i will write some "issues" that i encountered and my "workaround").
I want to know what do you think about this HibernateDSLContext for a better integration with Hibernate.
The project is just in development and the code is not already available on github. I would to improve it (maybe better integration with DSLContext and SQLQuery), for now it's just a prototype.
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Lukas,
thank you, if it's really work (i have to write more tests on it and test with different version of Hibernate) I think that could be really interesting for jOOQ because it's truth that you always say that jOOQ don't replace JPA\Hibernate framework but can complement it, but it's also true that you can't use together but you have to use separetely because there isn't any kind of integration with those framework, and if you only use the fetchInto feature of jOOQ to fill the Entities, you don't work with the proxy so the entire ORM framework is useless from the point of view of lazy associations and stuff like this
Regarding the Vlad observation, this project can be useful if you have an architecture completely based on Hibernate framework when the DAO Layer is coupled with Hibernate Entity (that is our case) and you want to take control of the DAO Layer replacing the Criteria API with query written in jOOQ.
For us it could be really simple replace Criteria API because we can use a SQL wrapper to get the SQL Query, use the tool SQL 2 jOOQ to generate code base for jOOQ query, modify it and replace Criteria API with a call to the HibernateDSLContext (maybe here could be also interest to write an article if the prototype evolve in a good way :) )
You said that you prefer separate reading using jOOQ and writing using Hibernate\JPA, but what if you have a business method that read some data before write or update something based on what is read? If you can work with the entities also for the reading part (written in jOOQ), you can reuse the same objects to write or update those data. So in this scenario it can be really useful thinks in terms of Entities.
It's also true that for other kind of reading, for example in the case of a complex report\view of data, thinks in terms of Entities is not so good instead is a really pain in the xxx, and in that case is obviously better using select with projections and specific bean to represent the data maybe 1-1 with the select fields.
So i don't prefer entity graph instead of business-case projections, it's only that the best choise depends on what are you doing and for sure you can\have to use both approaches depending on the case.
Finally i think that this project has a lot of application field.
I can also think to develop a JPADslContext that is limited only to fetch the entity without any associations (unfortunately there isn't an API for that like in Hibernate).
I will publish soon the project (actually called jooq4hibernate) in a public BitBucket repository and i'll share the link with you.
I will also post my doubts and problems encountered using VisitListener of jOOQ (when the code will be available is better).
Lucas you can eventually tell me how to handle certain things that actually i handle using reflection in the VisitListener (to extract some data, i had to study little pieces of jOOQ code to access it, also because the poor documentation of VisitListener).
Stay tuned!
Antonio
Hi Lukas,
thank you, if it's really work (i have to write more tests on it and test with different version of Hibernate) I think that could be really interesting for jOOQ because it's truth that you always say that jOOQ don't replace JPA\Hibernate framework but can complement it, but it's also true that you can't use together but you have to use separetely because there isn't any kind of integration with those framework, and if you only use the fetchInto feature of jOOQ to fill the Entities, you don't work with the proxy so the entire ORM framework is useless from the point of view of lazy associations and stuff like this
Regarding the Vlad observation, this project can be useful if you have an architecture completely based on Hibernate framework when the DAO Layer is coupled with Hibernate Entity (that is our case) and you want to take control of the DAO Layer replacing the Criteria API with query written in jOOQ.
For us it could be really simple replace Criteria API because we can use a SQL wrapper to get the SQL Query, use the tool SQL 2 jOOQ to generate code base for jOOQ query, modify it and replace Criteria API with a call to the HibernateDSLContext (maybe here could be also interest to write an article if the prototype evolve in a good way :) )
You said that you prefer separate reading using jOOQ and writing using Hibernate\JPA, but what if you have a business method that read some data before write or update something based on what is read? If you can work with the entities also for the reading part (written in jOOQ), you can reuse the same objects to write or update those data. So in this scenario it can be really useful thinks in terms of Entities.
It's also true that for other kind of reading, for example in the case of a complex report\view of data, thinks in terms of Entities is not so good instead is a really pain in the xxx, and in that case is obviously better using select with projections and specific bean to represent the data maybe 1-1 with the select fields.
So i don't prefer entity graph instead of business-case projections, it's only that the best choise depends on what are you doing and for sure you can\have to use both approaches depending on the case.
Finally i think that this project has a lot of application field.
I can also think to develop a JPADslContext that is limited only to fetch the entity without any associations (unfortunately there isn't an API for that like in Hibernate).
I will publish soon the project (actually called jooq4hibernate) in a public BitBucket repository and i'll share the link with you.
I will also post my doubts and problems encountered using VisitListener of jOOQ (when the code will be available is better).
Lucas you can eventually tell me how to handle certain things that actually i handle using reflection in the VisitListener (to extract some data, i had to study little pieces of jOOQ code to access it, also because the poor documentation of VisitListener).
Obiouvsly the project is not intended to replace the Criteria API\JPQL, but for some scenario\functionality i think that for sure with this library (in theory) you could think about use Criteria API or JOOQ with the HibernateDSLContext, because basically both can work in terms of JPA Entity.
Yes, with SQL you don't query the object graph, infact one of the purpose of the library is try to find (if exists) the relationship between join conditions and Entity Objects, in order to specify automatically the "addJoin" for the hibernate SQLQuery API. The effect of doing this is obtain the root entity with the entity object associated eagerly fetched.
Totally agree.
Not equivalent for sure, but the purpose of this "jooq4hibernate" is trying to write a little layer that enable you to write select that returns Entity with Associations attached. So as i said, in some scenario maybe you can think about use Criteria API or HibernateDSLContext.
Maybe, i didn't study those yet, but you should write by hands the association logic. Instead the purpose of this library is to find "automagically" those associations from join conditions :P
@Lukas: Is there a way from the maven plugin jooq-codegen-maven to manipulate the prefix of the table? Because actually I have same classname with different packages for JPA Entity and Jooq table and I want to avoid it with a prefix.
Hi Antonio,We're on the same line of thought, about SQL vs. ORM. I had no doubts about it, but I had to make a clear statement for future readers :-) (e.g. https://groups.google.com/forum/#!topic/jooq-user/dVw0unCHJGo)
Thanks for sharing the link to your jooq4hibernate prototype. I'll be looking into it sometime these days.
Regarding your question:2015-04-20 13:07 GMT+02:00 <antoni...@fhoster.com>:@Lukas: Is there a way from the maven plugin jooq-codegen-maven to manipulate the prefix of the table? Because actually I have same classname with different packages for JPA Entity and Jooq table and I want to avoid it with a prefix.If by "prefix" you mean a prefix for the class names only, then yes. This is called the generator strategies:
I'll get back to you with more feedback once I've seen jooq4hibernate.
I'll get back to you with more feedback once I've seen jooq4hibernate.Thank you very much.I just find out that in the project QueryDSL, there is a little documentation that describe the same approach.QueryDSL for sure have JPA native support using JPQL and metamodel based on entity (infact in our architecture I discuss with my collegues to use this instead of jOOQ, to rewrite some statements written with Criteria) but it also have SQL support.
Here http://www.querydsl.com/static/querydsl/2.1.0/reference/html/ch02s02.html is described how to use SQL metadata to handle query with Hibernate Native Query (in the chapter 2.2.14).