Repository navigation
Hibernate 7: keep the key of a unidirectional hasMany updatable unless it shares a join table #16686
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
Merged
Merged
Hibernate 7: keep the key of a unidirectional hasMany updatable unless it shares a join table #16686
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
173e8a3
fix(hibernate7): keep the key of a unidirectional hasMany updatable u…
borinquenkid f2ea509
Merge remote-tracking branch 'origin/8.0.x' into fix/h7-multiple-hasm…
borinquenkid 7138500
fix(hibernate7): count only collection-bound siblings when deciding w…
borinquenkid 074284c
Merge remote-tracking branch 'origin/8.0.x' into fix/h7-multiple-hasm…
borinquenkid 383c139
Hibernate 7: one scanner for the query package, and keep a spaced sql…
borinquenkid 7c04569
Hibernate 7: read an HQL query once
borinquenkid ddbb8d0
Hibernate 7: an enum for the HQL keywords the reader looks for
borinquenkid e79032a
Hibernate 7: brackets group an expression unless they open an identif…
borinquenkid 8b7515a
Hibernate 7: round-trip the shared join table through GORM, and docum…
borinquenkid e3c7fc7
Hibernate 7: read native SQL in the syntax of the database, resolved …
borinquenkid da0ef2b
Hibernate 7: read native SQL as each database lexes it, and HQL as Hi…
borinquenkid 30586fc
Merge branch 'fix/h7-multiple-hasmany-8.0.x' into feat/sql-text-8.0.x
borinquenkid 4aeaf4b
Merge branch 'fix/h7-multiple-hasmany-8.0.x' into feat/sql-text-8.0.x
borinquenkid a369f6b
Merge remote-tracking branch 'origin/8.0.x' into fix/h7-multiple-hasm…
borinquenkid c4e82e2
Hibernate 7: the count over a SQL projection no longer depends on how…
borinquenkid e394df9
Hibernate 7: a string in single quotes in a group by clause is a lite…
borinquenkid 6333d95
Hibernate 7: pin that a literal in the group by clause reaches the SQL
borinquenkid d6b6da6
Merge branch '8.0.x' into fix/h7-multiple-hasmany-8.0.x
borinquenkid a928abb
Merge branch 'fix/h7-multiple-hasmany-8.0.x' into feat/sql-text-8.0.x
borinquenkid d3d2279
Merge pull request #16735 from apache/feat/sql-text-8.0.x
borinquenkid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...s-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/dialect/DialectKeyed.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.grails.orm.hibernate.dialect; | ||
|
|
||
| import org.hibernate.dialect.Dialect; | ||
|
|
||
| /** | ||
| * An enum whose constants each stand for the databases of some Hibernate dialects, so that one of them is chosen | ||
| * for the dialect a session factory connects with. A constant lists the dialect classes it is for; the one listing | ||
| * {@link Dialect} itself is the default, chosen for a dialect no other constant lists; a constant listing none is | ||
| * never chosen for a dialect. The constants are tried in their declared order, so a constant for a dialect | ||
| * subclass is declared before the constant for its superclass. | ||
| * | ||
| * @param <T> the enum | ||
| * @since 8.0.1 | ||
| */ | ||
| public interface DialectKeyed<T extends Enum<T> & DialectKeyed<T>> { | ||
|
|
||
| /** The dialect classes the constant is for: the database of any of their instances. */ | ||
| Class<? extends Dialect>[] dialectClasses(); | ||
|
|
||
| /** | ||
| * Returns the constant of the enum for the dialect: the first whose dialect classes the dialect is an instance | ||
| * of, or else the first listing {@link Dialect} itself. | ||
| * | ||
| * @throws IllegalArgumentException if no constant is for the dialect and none is the default | ||
| */ | ||
| static <T extends Enum<T> & DialectKeyed<T>> T forDialect(Class<T> type, Dialect dialect) { | ||
| T fallback = null; | ||
| for (T candidate : type.getEnumConstants()) { | ||
| for (Class<? extends Dialect> dialectClass : candidate.dialectClasses()) { | ||
| if (dialectClass == Dialect.class) { | ||
| if (fallback == null) { | ||
| fallback = candidate; | ||
| } | ||
| } else if (dialectClass.isInstance(dialect)) { | ||
| return candidate; | ||
| } | ||
| } | ||
| } | ||
| if (fallback == null) { | ||
| throw new IllegalArgumentException(type.getName() + " has no constant for " + dialect.getClass().getName()); | ||
| } | ||
| return fallback; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/HqlKeyword.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.grails.orm.hibernate.query; | ||
|
|
||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| /** | ||
| * The HQL keywords the reader of a query looks for, and which of them start a clause: a token after the root | ||
| * entity that starts a clause is the clause, not an alias of the entity. | ||
| * | ||
| * @since 8.0.1 | ||
| */ | ||
| enum HqlKeyword { | ||
|
|
||
| SELECT("select", false), | ||
| FROM("from", false), | ||
| DISTINCT("distinct", false), | ||
| ALL("all", false), | ||
| AS("as", false), | ||
| NEW("new", false), | ||
| WHERE("where", true), | ||
| JOIN("join", true), | ||
| LEFT("left", true), | ||
| RIGHT("right", true), | ||
| INNER("inner", true), | ||
| OUTER("outer", true), | ||
| GROUP("group", true), | ||
| ORDER("order", true), | ||
| HAVING("having", true); | ||
|
|
||
| private static final Map<String, HqlKeyword> BY_TEXT = Stream.of(values()) | ||
| .collect(Collectors.toUnmodifiableMap(HqlKeyword::text, Function.identity())); | ||
|
|
||
| private final String text; | ||
| private final boolean startsClause; | ||
|
|
||
| HqlKeyword(String text, boolean startsClause) { | ||
| this.text = text; | ||
| this.startsClause = startsClause; | ||
| } | ||
|
|
||
| /** The keyword in lower case, as the reader matches it against a lowercased query. */ | ||
| String text() { | ||
| return text; | ||
| } | ||
|
|
||
| /** Whether a token, in any case, is a keyword that starts a clause. */ | ||
| static boolean startsClause(String token) { | ||
| HqlKeyword keyword = BY_TEXT.get(token.toLowerCase(Locale.ROOT)); | ||
| return keyword != null && keyword.startsClause; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
This changes user-visible persistence. An owner with two unidirectional hasMany associations now writes the join table when each association has its own table, and still does not when they share one. That distinction is not in
grails-docor the GORM upgrade notes.Please add a short public note: separate join tables are written; a shared join table is still the 10811 case and is not fixed by this change alone. A bugfix that changes which rows get written is a user-facing change and needs that coverage.
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.
Added in 8b7515a: section 26.11 of the Grails 8 upgrade notes says an owner with several unidirectional hasMany associations writes each join table of its own, as under Hibernate 5, and that two associations on one shared join table are read but not written, which is issue 10811 and not fixed by this change; the one-to-many chapter of the GORM for Hibernate 7 guide carries the same paragraph.