-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DAOs should be proxyable #4854
Comments
Thank you very much for your suggestion. Indeed, we're aware of this limitation caused by some Also: I'm curious about the |
OK, I suspect you really want to inject the DAO, rather than do what you did in your example. The most sensible approach here would be to generate interfaces for each DAO. Does that match your expectations? |
Speaking from the CDI perspective, when you inject a bean, most of the time you don't get an instance of the bean class itself but an instance of a client proxy. When the bean class is a real class and not just an interface, the client proxy has a class generated by byte code manipulation. The proxy class extends the real bean class. Methods of the proxy class take care of any interceptors and decorators, then select the correct target instance of the real bean class and delegate method invocations to that target instance. If the target bean class has any final methods, the proxy class cannot be generated, since it needs to override any non-private method. So the plan of #4696 to remove Most likely, this issue is not specific to CDI. Other solutions working with client proxies may run into the same problem. I think Spring has a similar approach of generating target proxies via CGLIB. Regarding In a classical layered architecture, you would have a However, in simple cases, you'll find that all The last two paragraphs would apply to any hand-written classes. Now for the In other words, what I did in my example is the necessary prerequisite (but not sufficient, see below) to inject the DAO with CDI. For CDI, it would be really convenient, if the code generator could be configured to generate classes like @ApplicationScoped
@Transactional
public class CountryDao extends DaoImpl<Country> {
@Inject @SomeQualifier
private Configuration config;
// methods
} where the In fact, my producer example was wrong. I've checked the CDI spec:
So the transactional interceptor binding has no effect on the producer method, and that means that a DAO interface |
Thank you very much for your additional info. jOOQ's DAOs are among the "hottest" topics. The concrete implementation has often been criticised, people have been confused about how to use them "correctly", and they have not been designed to be used with Spring's Perhaps. On the other hand, the exact semantics of each annotation is something that people will always want to fine-tune. For instance, your suggested I keep wondering if we shouldn't simply deprecate DAOs as they are today, and move forward with the improvements of the code generator, such that users can generate their own, very specific DAO style (they can already do this today, but we don't encourage extending the code generator, yet). In the end, we wouldn't need to discuss In any case, thanks again for your suggestion. We'll think about this. I cannot promise any quick win, as I doubt there is one. But I am sure that there is a thorough, strategic solution that jOOQ can offer for Spring and/or CDI. |
For the record, here's the discussion I've started on the user group regarding future strategic code generation improvements: |
I have given this some additional thought. While I believe that a more fundamental problem is present here, in the context of which I will thus implement #4696 as "removing all usages of |
Generated DAOs don't integrate very well with CDI in a Java EE context due to a lot of final methods in
DAOImpl
. Classes with final methods are unproxyable and cannot be used as normal scoped CDI beans.This prevents use cases like
The text was updated successfully, but these errors were encountered: