-
Notifications
You must be signed in to change notification settings - Fork 3k
Hibernate ORM extension config overhaul #1121
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
Changes from all commits
a25e884
683b308
63393ef
4cd8f58
5de9447
e6ddab9
087b62e
ca17c6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,23 +106,77 @@ This is useful to have a data set ready for your tests or demos. | |
|
||
There are optional properties useful to refine your `EntityManagerFactory` or guide guesses of {project-name}. | ||
|
||
`quarkus.hibernate.dialect`:: (e.g. `org.hibernate.dialect.PostgreSQL95Dialect`). | ||
==== Dialect | ||
|
||
`quarkus.hibernate-orm.dialect`:: (e.g. `org.hibernate.dialect.PostgreSQL95Dialect`). | ||
Class name of the Hibernate ORM dialect. | ||
|
||
`quarkus.hibernate.schema-generation.database.action`:: | ||
`quarkus.hibernate-orm.dialect.storage-engine`:: (e.g. `MyISAM` or `InnoDB`). | ||
The storage engine to use when the dialect supports multiple storage engines. | ||
|
||
==== Miscellaneous | ||
|
||
`quarkus.hibernate-orm.sql-load-script`:: | ||
(defaults to `/import.sql`) Name of the file containing the SQL statements to execute when Hibernate ORM starts. | ||
By default, simply add `import.sql` in the root of your resources directory and it will be picked up without having to set this property. | ||
|
||
`quarkus.hibernate-orm.batch-fetch-size`:: (defaults to `-1` i.e. batch fetching is disabled). | ||
The size of the batches used when loading entities and collections. | ||
|
||
==== Query | ||
|
||
`quarkus.hibernate-orm.query.query-plan-cache-max-size`:: | ||
The maximum size of the query plan cache. | ||
|
||
`quarkus.hibernate-orm.query.default-null-ordering`:: (defaults to `none`). | ||
Default precedence of null values in `ORDER BY` clauses. | ||
Options are `none`, `first`, `last`. | ||
|
||
==== Database | ||
|
||
`quarkus.hibernate-orm.database.generation`:: | ||
(e.g. `drop-and-create` which is awesome in development mode). Select whether the database schema is generated or not. | ||
Options are `none`, `create`, `drop-and-create`, `drop` | ||
|
||
`quarkus.hibernate.show-sql`:: (defaults to `false`). | ||
`quarkus.hibernate-orm.database.generation.halt-on-error`:: (defaults to `false`) | ||
Whether we should stop on the first error when applying the schema. | ||
|
||
`quarkus.hibernate-orm.database.default-catalog`:: | ||
The default catalog to use for the database objects. | ||
|
||
`quarkus.hibernate-orm.database.default-schema`:: | ||
The default schema to use for the database objects. | ||
|
||
`quarkus.hibernate-orm.database.charset`:: | ||
The charset of the database. | ||
|
||
==== JDBC | ||
|
||
`quarkus.hibernate-orm.jdbc.timezone`:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have more than one timezone setting? Does it matter that it is used via JDBC? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at the moment. I must admit I wondered if we should just have I just thought being cautious wouldn't hurt here as what it does is pretty clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep the jdbc prefix as it clarifies the scope. Not sure if it shouldn't just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well. It may clarify the scope for people who understand what that scope means. If you think it's important that users understand that it's I personally don't know enough about its function to judge, so it's a honest question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the timezone used by the JDBC driver, which might be different of the timezone of the JVM. So it's important to know it's the one from the JDBC driver. |
||
The time zone pushed to the JDBC driver. | ||
|
||
`quarkus.hibernate-orm.jdbc.statement-fetch-size`:: | ||
How many rows are fetched at a time by the JDBC driver. | ||
|
||
`quarkus.hibernate-orm.jdbc.statement-batch-size`:: | ||
The number of updates (inserts, updates and deletes) that are sent by the JDBC driver at one time for execution. | ||
|
||
==== Logging | ||
|
||
`quarkus.hibernate-orm.log.sql`:: (defaults to `false`). | ||
Show SQL logs and format them nicely. | ||
|
||
`quarkus.hibernate.sql-load-script-source`:: | ||
(defaults to `/import.sql`) Name of the file containing the SQL statements to execute when Hibernate ORM starts. | ||
By default, simply add `import.sql` in the root of your resources directory and it will be picked up without having to set this property. | ||
`quarkus.hibernate-orm.log.jdbc-warnings`:: (defaults to `false`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect more kinds of warnings? If not how about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are really specific to JDBC and the capability of the driver to get them. So having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it really is important to single out jdbc warnings from non-jdbc warnings? Again, I've no clue, so it's a honest user question. I sort of assumed that hibernate had warnings, and that jdbc warnings would be a category within them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are different. Essentially this allows the Database to issue warnings which we relay to the application log.. sometimes that's very useful as the DB can give you some very good clues, but if you're not opting in specifically, the fact that we do this is really weird. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you collect jdbc/db warnings and log them in the ORM logger somewhere. From a clueless user perspective, it sounds like something I would force to true (and set log level to debug) and let users decide if they want to see them by bumping up those log's category. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently, this things is there because you could have weird issues depending on your driver/database and you need some knob to be able to disable it/enable it if needed. Ideally, it's something that should be managed automatically but that's not the case right now. Apparently, it was judged sufficiently important by the Hibernate ORM team to get to the Hibernate ORM - Quarkus config document so let's not have this discussion again. |
||
Whether JDBC warnings should be collected and logged. | ||
|
||
==== Statistics | ||
|
||
`quarkus.hibernate-orm.statistics`:: (defaults to `false`) | ||
Whether statistics collection is enabled. | ||
|
||
[NOTE] | ||
-- | ||
Do not mix `persistence.xml` and `quarkus.hibernate.*` properties in `{config-file}`. | ||
Do not mix `persistence.xml` and `quarkus.hibernate-orm.*` properties in `{config-file}`. | ||
{project-name} will raise an exception. | ||
Make up your mind on which approach you want to use. | ||
-- | ||
|
@@ -149,7 +203,7 @@ This is useful for: | |
|
||
[NOTE] | ||
-- | ||
If you have a `persistence.xml`, then you cannot use the `quarkus.hibernate.*` properties | ||
If you have a `persistence.xml`, then you cannot use the `quarkus.hibernate-orm.*` properties | ||
and only persistence units defined in `persistence.xml` will be taken into account. | ||
-- | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
package io.quarkus.hibernate.orm; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
/** | ||
* @author Emmanuel Bernard [email protected] | ||
*/ | ||
@ConfigRoot | ||
public class HibernateOrmConfig { | ||
/** | ||
* The hibernate ORM dialect class name | ||
*/ | ||
// TODO should it be dialects | ||
//TODO should it be shortcuts like "postgresql" "h2" etc | ||
@ConfigItem | ||
public Optional<String> dialect; | ||
|
||
/** | ||
* The storage engine used by the dialect if it supports several storage engines. | ||
* <p> | ||
* This is the case of MariaDB. | ||
*/ | ||
@ConfigItem(name = "dialect.storage-engine") | ||
public Optional<String> dialectStorageEngine; | ||
|
||
/** | ||
* To populate the database tables with data before the application loads, | ||
* specify the location of a load script. | ||
* The location specified in this property is relative to the root of the persistence unit. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> sqlLoadScript; | ||
|
||
/** | ||
* The size of a batch when using batch loading to load entities and collections. | ||
* <p> | ||
* -1 means batch loading is disabled. | ||
*/ | ||
@ConfigItem(defaultValue = "-1") | ||
public int batchFetchSize; | ||
|
||
/** | ||
* Query related configuration. | ||
*/ | ||
@ConfigItem | ||
public HibernateOrmConfigQuery query; | ||
|
||
/** | ||
* Database related configuration. | ||
*/ | ||
@ConfigItem | ||
public HibernateOrmConfigDatabase database; | ||
|
||
/** | ||
* JDBC related configuration. | ||
*/ | ||
@ConfigItem | ||
public HibernateOrmConfigJdbc jdbc; | ||
|
||
/** | ||
* Logging configuration. | ||
*/ | ||
@ConfigItem | ||
public HibernateOrmConfigLog log; | ||
|
||
/** | ||
* Statistics configuration. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean statistics; | ||
|
||
public boolean isAnyPropertySet() { | ||
return dialect.isPresent() || | ||
dialectStorageEngine.isPresent() || | ||
sqlLoadScript.isPresent() || | ||
batchFetchSize > 0 || | ||
statistics || | ||
query.isAnyPropertySet() || | ||
database.isAnyPropertySet() || | ||
jdbc.isAnyPropertySet() || | ||
log.isAnyPropertySet(); | ||
} | ||
|
||
@ConfigGroup | ||
public static class HibernateOrmConfigQuery { | ||
|
||
/** | ||
* The max size of the query plan cache. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> queryPlanCacheMaxSize; | ||
|
||
/** | ||
* The default ordering of nulls specific in the ORDER BY clause. | ||
* <p> | ||
* Valid values are: none, first, last. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> defaultNullOrdering; | ||
|
||
public boolean isAnyPropertySet() { | ||
return queryPlanCacheMaxSize.isPresent() || defaultNullOrdering.isPresent(); | ||
} | ||
} | ||
|
||
@ConfigGroup | ||
public static class HibernateOrmConfigDatabase { | ||
|
||
/** | ||
* Control how schema generation is happening in Hibernate ORM. | ||
* <p> | ||
* Same as JPA's javax.persistence.schema-generation.database.action. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> generation; | ||
|
||
/** | ||
* Whether we should stop schema application at the first error or continue. | ||
*/ | ||
@ConfigItem(name = "generation.halt-on-error", defaultValue = "false") | ||
public boolean generationHaltOnError; | ||
|
||
/** | ||
* The default database catalog. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> defaultCatalog; | ||
|
||
/** | ||
* The default database schema. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> defaultSchema; | ||
|
||
/** | ||
* The charset of the database. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> charset; | ||
|
||
public boolean isAnyPropertySet() { | ||
return generation.isPresent() || defaultCatalog.isPresent() || defaultSchema.isPresent() || generationHaltOnError | ||
|| charset.isPresent(); | ||
} | ||
} | ||
|
||
@ConfigGroup | ||
public static class HibernateOrmConfigJdbc { | ||
|
||
/** | ||
* The timezone pushed to the JDBC driver. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> timezone; | ||
|
||
/** | ||
* How many rows are fetched at a time by the JDBC driver. | ||
*/ | ||
@ConfigItem | ||
public Optional<Integer> statementFetchSize; | ||
|
||
/** | ||
* The number of updates (inserts, updates and deletes) that are sent to the database at one time for execution. | ||
*/ | ||
@ConfigItem | ||
public Optional<Integer> statementBatchSize; | ||
|
||
public boolean isAnyPropertySet() { | ||
return timezone.isPresent() || statementFetchSize.isPresent() || statementBatchSize.isPresent(); | ||
} | ||
} | ||
|
||
@ConfigGroup | ||
public static class HibernateOrmConfigLog { | ||
|
||
/** | ||
* Whether we log all the SQL queries executed. | ||
* <p> | ||
* Setting it to true is obviously not recommended in production. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean sql; | ||
|
||
/** | ||
* Whether JDBC warnings should be collected and logged. | ||
* <p> | ||
* Default value depends on the dialect. | ||
*/ | ||
@ConfigItem | ||
public Optional<Boolean> jdbcWarnings; | ||
|
||
public boolean isAnyPropertySet() { | ||
return sql || jdbcWarnings.isPresent(); | ||
} | ||
} | ||
} |
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.
Would
quarkus.hibernate-orm.schema
andquarkus.hibernate-orm.catalog
make sense for the defaults to use?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.
+1 yeah that sounds quite better actually
Uh oh!
There was an error while loading. Please reload this page.
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 don't think it's a good idea. Especially for schema as we have
schema.generation
. And they are different things.Having the
default
prefix helps to understand what it does IMHO.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.
well it's not like one can switch schema at runtime.. so what is the "default" for?
AFAIK the only case is one can override the schema for a specific entity; I did that a couple of times but TBH I don't remember if that was a hack..
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.
schema.default-schema
looks like something went wrong, though, which is why I brought this up.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.
Well, unfortunately, the same name is used for the database schema and the notion of schema in a database.
I renamed
.schema.
to.database.
to make things hopefully clearer and a few other adjustments to get something hopefully better.