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
Support multiple Hibernate ORM persistence units via Quarkus configuration #11322
Conversation
8143d0b
to
0dc2c5a
Compare
4d251f4
to
974f27f
Compare
@machi1990 I had to tweak the config a bit due to a SmallRye Config issue and I end up having another issue with the documentation:
Could you have a look? |
I added a commit that somehow makes it work (removing the |
Okay, I'll check it out later today. Thanks for the update. |
Yeap. This was the issue as the anchor used for the dialect config section and the contained An easy fix will be to make the config section anchor unique enough by using the title for example. A more appropriate fix will be to construct the anchor separate from the configuration name e.g simply traversing the object and hyphenating the field name will be enough. |
It has a special meaning and I don't want it to conflict with the user defined ones.
No code changes, just moving methods around.
In passing, we now make JTA the only case handled. I will throw a proper error in a follow-up commit when not enabled.
I decided to support multiple PUs there. We will see how it goes in Panache.
Sanne confirmed that not having JTA around is not a valid configuration. We used to have some partial support for it but it was buggy at best. The support was removed in a previous commit, this commit only adds a proper exception for it.
We don't have a prefix in the other extensions so let's try to be consistent and see how it goes.
In passing, reorganize the dialect configuration to work around an issue with SmallRye Config.
e729b01
to
e79df93
Compare
@gsmet I checked in ORM and can confirm that |
OK, I will change the logic once this PR is in, then! |
Isn't this kinda legacy? Does anyone really need to generate MyISAM schemas these days? IMO this is pretty much deprecated functionality. |
Ironically this configuration flag was only added recently, "bolted on" as
environment variable since dialects in 5 don't support configuration.
There's still people preferring MyISAM, and there's other pluggable engines
as well.
…On Thu, 20 Aug 2020, 17:50 Gavin King, ***@***.***> wrote:
@gsmet <https://github.com/gsmet> I checked in ORM and can confirm that
hibernate.dialect.storage_engine is only applied to MySQL (and MariaDB as
a consequence)
Isn't this kinda legacy? Does anyone really need to generate MyISAM
schemas these days?
IMO this is pretty much deprecated functionality.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11322 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAKMTMHJJSP5OX5E4XW4QTSBVH4JANCNFSM4P23WQ7A>
.
|
@@ -666,6 +697,14 @@ private static void producePersistenceUnitDescriptorFromConfig( | |||
// we found one | |||
ParsedPersistenceXmlDescriptor descriptor = new ParsedPersistenceXmlDescriptor(null); //todo URL | |||
descriptor.setName(persistenceUnitName); | |||
|
|||
descriptor.setExcludeUnlistedClasses(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, did you figure that this was necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary as you forced it in LightPersistence...
but... I'm not sure we will keep it that way so wanted to be extra sure it wouldn't break if we change it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks I was just puzzled.
@@ -126,7 +126,7 @@ | |||
|
|||
public static final String HIBERNATE_ORM_CONFIG_PREFIX = "quarkus.hibernate-orm."; | |||
public static final String NO_SQL_LOAD_SCRIPT_FILE = "no-file"; | |||
public static final String DEFAULT_PERSISTENCE_UNIT_NAME = "default"; | |||
public static final String DEFAULT_PERSISTENCE_UNIT_NAME = "<default>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "has special meaning", is it not possible for a user to speficy this name explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to avoid a conflict between the default one and a potential named PU called "default". Thus why I added the special characters. Also, it's consistent with the Agroal extension.
quarkus.hibernate-orm.persistence-units."users".dialect=org.hibernate.dialect.H2Dialect | ||
quarkus.hibernate-orm.persistence-units."users".log.sql=true | ||
quarkus.hibernate-orm.persistence-units."users".database.generation=drop-and-create | ||
quarkus.hibernate-orm.persistence-units."users".datasource=users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment somewhere to remind why this is an invalid configuration? I guess because it's missing the package names filter packages
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
return jtaEnabled.get(); | ||
public EntityManagerFactory getEntityManagerFactory(String unitName) { | ||
LazyPersistenceUnit lazyPersistenceUnit = null; | ||
if (unitName == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this condition check useful? I was assuming that unitName
would be always defined, at most <default>
.
If I'm wrong, we might want to improve the following (nested) if
so that the default can still be used/injected even when there's more than one PU defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's always set except when you're explicitly calling null. This was the case somewhere in the code base so I decided to make it null safe just to be on the safe side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it feels a bit smelly but we can clean it up later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it safe not smelly. I'm not sure I understand your problem.
Everything is working fine with the default injection, we have tests for that. The null test is there just if someone calls it programmatically. When dealing with injection, you pass the default unit name (which is not null).
For me passing null is not really valid, I only support it because someone used it (and I changed that call to not use it) and I thought maybe someone else could have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll approve as my minor comments and questions are certainly not blocking, but please have a look at them.
/cc @Sanne @machi1990 @michael-schnell
This is the preliminary infrastructure work for the support of multiple persistence units. I would like to merge this PR early (well, as soon as we agree the code is correct) and then do additional follow-ups for tweaking how we do the entity <-> persistence unit mapping and if we allow an entity to belong to several persistence units.
Fixes #2835