-
Notifications
You must be signed in to change notification settings - Fork 95
Class Persistence.createEntityManagerFactory() used in Verticle produced new Vertx Instance #995
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
Comments
I'm working on the documentation of this part, but basically you need to register the already existing Vert.x instance when you create the SessionFactory. I've explained how to do it as an answer to this question. Let me know if that helps. I will add that section to the documentation before the final release |
Thanks! |
The service loader mechanism described in the answer should work with the JPA approach as well. |
Please, it would be better if you could attach the code as preformatted text and not using images. You don't show what the class These are the two approaches:
UPDATED: I don't think the example I wrote initially for case 2 will work. I will test it and update the answer if I can find a better solution
I guess in this case you should go with the first solution. |
Actually, I'm not sure the second approach will work. I will create a test and get back to you |
Sorry,I will no longer use code images. As you told,the second approach didn't work. I used MainVerticle which implements VertxInstace instead of MyProvider.
But,it still create a new Vertx instance When I run following code:
Run result:
Here is my MainClass code:
|
I suppose you could try something like this:
But using the Hibernate configuration instead of the Persistence one looks better IMHO. By the way, you can change the code to something more reactive by using this approach. |
Thanks a lot! On your suggestion,it still create new one.Maybe I should give up using Persistence. But,is there any possibility that Hibernate reactive could support to use Persistence in Verticle in the future?It seems that |
That's weird, are you sure the service is defined correctly in your app? Does
The I think what we already have allows this already. How would you pass an instance of Vert.x in the |
Here is my demo: By the way, first approach using |
I can see that the ServiceLoader is not loading MyProvider. |
Here is run result:
So, MyProvider will be printed to the console when I invoke |
Mmmh... I think you have found a bug |
Oh, I see! In fact, I'd read the source code roughly yesterday, it seems that
In addtion, here is the method
Could
|
You know, I think that was the initial plan. @gavinking? Anyway, I understand now why the service loader is not working. |
@Mr-CodingXu Would you like to send a PR about changing |
Anyway, to register a custom VertxInstance using the java ServiceLoader the correct approach is to use a
and then regsiter it using the file:
I've forked the project you've provided and updated it on my repository: https://github.com/DavideD/hibernate-demo |
Oh, yes! I'll think it over and try to do it in the shortest time. |
Your code refactoring offers me another train of thought for better code, thanks! |
Thanks :-) I'm closing this issue. It seems we figure out what we need to improve. Thanks a lot again! |
I've clened up the demo a bit more: DavideD/hibernate-demo@c7c96aa |
Here is my code:


Console printed the following message:
The text was updated successfully, but these errors were encountered: