Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d82e66c
Resolve every column of an enum unique-group member
jamesfredley Oct 22, 2026
baae3cd
Create unique-group keys after composite association columns are bound
jamesfredley Oct 28, 2026
23d85bc
Merge 8.0.x and resolve unique-group columns through one path
jamesfredley Oct 29, 2026
2e8c775
docs: include Grails-owned Spring Security in the threat model
jamesfredley Nov 13, 2026
1ac3908
Merge remote-tracking branch 'origin/8.0.x' into docs/threat-model-sp…
jamesfredley Nov 18, 2026
2b6efd8
Merge branch '8.0.x' into fix/enum-unique-group-multicolumn-8.0.x
jamesfredley Nov 18, 2026
dd3b190
Merge remote-tracking branch 'origin/8.0.x' into docs/threat-model-sp…
jamesfredley Nov 18, 2026
262075f
Merge remote-tracking branch 'origin/8.0.x' into fix/enum-unique-grou…
jamesfredley Nov 18, 2026
18331b9
Merge branch '8.0.x' into docs/threat-model-spring-security-8.0.x
jamesfredley Nov 19, 2026
a2707c6
test(hibernate7): cover the joins of nested association blocks in cri…
gustavoharff Dec 3, 2026
ed188b5
docs: upgrade note for the Hibernate 7 list() fetch mode join (#16940)
borinquenkid Dec 3, 2026
b3c7d05
Merge pull request #16720 from apache/fix/enum-unique-group-multicolu…
jdaugherty Dec 3, 2026
a592b38
Merge pull request #16976 from apache/docs/threat-model-spring-securi…
jdaugherty Dec 3, 2026
ac11817
Make the GSP Spring Boot script example run on 8.0.x
codeconsole Dec 4, 2026
9b6c7b8
Run the GSP Spring Boot script example against the branch's snapshot
codeconsole Dec 4, 2026
281bcb6
Merge pull request #17312 from codeconsole/fix/gsp-spring-boot-script…
codeconsole Dec 4, 2026
6e2f47b
Merge branch '8.0.x' into 8.1.x
codeconsole Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/scripts/setSnapshotGrailsVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ echo "Setting new version in GrailsUtilsTests.java: ${NEXT_VERSION}-SNAPSHOT"
sed -i "s/assertEquals(\".*$/assertEquals(\"${NEXT_VERSION}-SNAPSHOT\", GrailsUtil.getGrailsVersion());/" "${GITHUB_WORKSPACE}/grails-core/src/test/groovy/grails/util/GrailsUtilTests.java"
sed -n "/assertEquals(\".*/p" "${GITHUB_WORKSPACE}/grails-core/src/test/groovy/grails/util/GrailsUtilTests.java"
git add "${GITHUB_WORKSPACE}/grails-core/src/test/groovy/grails/util/GrailsUtilTests.java"

GSP_SCRIPT="${GITHUB_WORKSPACE}/grails-test-examples/gsp-spring-boot/script/app.groovy"
echo "Setting new version in the GSP Spring Boot script example: ${NEXT_VERSION}-SNAPSHOT"
sed -i "s/^@Grab('org.apache.grails:grails-gsp-spring-boot:.*')$/@Grab('org.apache.grails:grails-gsp-spring-boot:${NEXT_VERSION}-SNAPSHOT')/" "${GSP_SCRIPT}"
grep -q "^@Grab('org.apache.grails:grails-gsp-spring-boot:${NEXT_VERSION}-SNAPSHOT')$" "${GSP_SCRIPT}"
sed -n "/^@Grab(/p" "${GSP_SCRIPT}"
git add "${GSP_SCRIPT}"
32 changes: 17 additions & 15 deletions THREAT_MODEL.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public ColumnBinder(
columnNameFetcher(metadataBuildingContext, namingStrategy),
new StringColumnConstraintsBinder(),
new NumericColumnConstraintsBinder(dialect),
new CreateKeyForProps(columnNameFetcher(metadataBuildingContext, namingStrategy)),
new CreateKeyForProps(columnNameFetcher(metadataBuildingContext, namingStrategy),
metadataBuildingContext == null ? null : metadataBuildingContext.getMetadataCollector()),
new IndexBinder());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public CompositeUserTypeBinder(
new ColumnBinder(metadataBuildingContext, namingStrategy, jdbcEnvironment.getDialect()),
new CreateKeyForProps(new ColumnNameForPropertyAndPathFetcher(
namingStrategy, new DefaultColumnNameFetcher(namingStrategy), new BackticksRemover(),
metadataBuildingContext)),
metadataBuildingContext), metadataBuildingContext.getMetadataCollector()),
new CompositeUserTypeColumns(namingStrategy, new BackticksRemover(), metadataBuildingContext));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected EnumTypeBinder(
indexBinder,
columnConfigToColumnBinder,
namingStrategy,
new CreateKeyForProps(columnNameForPropertyAndPathFetcher));
new CreateKeyForProps(columnNameForPropertyAndPathFetcher, metadataBuildingContext.getMetadataCollector()));
}

protected EnumTypeBinder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public String getColumnNameForPropertyAndPath(

/**
* The names of all the columns of the property: the one name {@link #getColumnNameForPropertyAndPath} resolves
* without a column configuration for a property that has one column, or one name per attribute of the
* embeddable class for a property mapped with a composite user type, which spans one column per attribute and
* has no single column name.
* without a column configuration for an unconfigured property, one name per configured column, or one name
* per attribute of the embeddable class for a property mapped with a composite user type, which spans one
* column per attribute and has no single column name.
*
* @param grailsProp the property
* @param path the path of the property within its entity
Expand All @@ -114,6 +114,12 @@ public List<String> getColumnNamesForPropertyAndPath(HibernatePersistentProperty
if (grailsProp.getCompositeUserType() != null) {
return compositeUserTypeColumns.columnNamesOf(grailsProp, path);
}
List<ColumnConfig> columns = grailsProp.getHibernateMappedForm().getColumns();
if (!columns.isEmpty()) {
return columns.stream()
.map(column -> getColumnNameForPropertyAndPath(grailsProp, path, column))
.toList();
}
return Collections.singletonList(getColumnNameForPropertyAndPath(grailsProp, path, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import org.hibernate.MappingException;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Table;

Expand All @@ -35,17 +36,31 @@ public class CreateKeyForProps {

private final ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher;
private final UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator;
private final InFlightMetadataCollector metadataCollector;

public CreateKeyForProps(ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher) {
this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher;
this.uniqueKeyForColumnsCreator = new UniqueKeyForColumnsCreator();
this(columnNameForPropertyAndPathFetcher, new UniqueKeyForColumnsCreator(), null);
}

public CreateKeyForProps(
ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher,
InFlightMetadataCollector metadataCollector) {
this(columnNameForPropertyAndPathFetcher, new UniqueKeyForColumnsCreator(), metadataCollector);
}

protected CreateKeyForProps(
ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher,
UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator) {
this(columnNameForPropertyAndPathFetcher, uniqueKeyForColumnsCreator, null);
}

protected CreateKeyForProps(
ColumnNameForPropertyAndPathFetcher columnNameForPropertyAndPathFetcher,
UniqueKeyForColumnsCreator uniqueKeyForColumnsCreator,
InFlightMetadataCollector metadataCollector) {
this.columnNameForPropertyAndPathFetcher = columnNameForPropertyAndPathFetcher;
this.uniqueKeyForColumnsCreator = uniqueKeyForColumnsCreator;
this.metadataCollector = metadataCollector;
}

public void createKeyForProps(HibernatePersistentProperty grailsProp, String path, Table table, String columnName) {
Expand All @@ -59,11 +74,8 @@ public void createKeyForProps(HibernatePersistentProperty grailsProp, String pat
PropertyConfig mappedForm = grailsProp.getMappedForm();

if (mappedForm.isUnique() && mappedForm.isUniqueWithinGroup()) {

List<Column> keyList = new ArrayList<>();
keyList.add(new Column(columnName));
addGroupColumns(grailsProp, mappedForm, path, keyList);
uniqueKeyForColumnsCreator.createUniqueKeyForColumns(table, keyList);
createKeyWhenReady(() -> createKeyForGroup(grailsProp, path, table,
List.of(new Column(columnName)), mappedForm));
}
}

Expand All @@ -85,6 +97,20 @@ public void createKeyForColumns(
if (!mappedForm.isUnique() || columns.isEmpty()) {
return;
}
createKeyWhenReady(() -> createKeyForGroup(grailsProp, path, table, columns, mappedForm));
}

private void createKeyWhenReady(Runnable createKey) {
if (metadataCollector == null || metadataCollector.isInSecondPass()) {
createKey.run();
} else {
metadataCollector.addSecondPass(persistentClasses -> createKey.run());
}
}

private void createKeyForGroup(
HibernatePersistentProperty grailsProp, String path, Table table, List<Column> columns,
PropertyConfig mappedForm) {
List<Column> keyList = new ArrayList<>(columns);
if (mappedForm.isUniqueWithinGroup()) {
addGroupColumns(grailsProp, mappedForm, path, keyList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*
* 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 grails.gorm.tests

import grails.gorm.annotation.Entity
import grails.gorm.hibernate.HibernateEntity
import groovy.transform.EqualsAndHashCode
import org.grails.orm.hibernate.CompositeMoney
import org.grails.orm.hibernate.CompositeMoneyType
import org.springframework.dao.DataIntegrityViolationException
import spock.lang.Issue

@Issue('https://github.com/apache/grails-core/issues/16713')
class EnumUniqueGroupAssociationSpec extends HibernateGormDatastoreSpec {

void setupSpec() {
manager.registerDomainClasses(EnumUniqueCompositeParent, EnumUniqueCompositeChild,
StringUniqueCompositeChild, DeclaredFirstUniqueCompositeChild, DeclaredFirstCompositeAmountChild)
}

void "an enum unique group includes every mapped column of a composite parent"() {
given:
def table = datastore.metadata.getEntityBinding(EnumUniqueCompositeChild.name).table

expect:
table.uniqueKeys.values().collect { it.columns*.name.toSet() } ==
[['child_state', 'parent_code', 'parent_revision'] as Set]
table.getForeignKeys().values().any { it.columns*.name.toSet() == ['parent_code', 'parent_revision'] as Set }
}

void "the same enum can be saved for parents differing in either identifier column"() {
when:
[['a', 1], ['a', 2], ['b', 1]].each { code, revision ->
def parent = new EnumUniqueCompositeParent(code: code, revision: revision).save(failOnError: true)
new EnumUniqueCompositeChild(parent: parent, state: EnumUniqueCompositeState.ON).save(failOnError: true)
}
manager.session.flush()
manager.session.clear()

then:
EnumUniqueCompositeChild.count() == 3
EnumUniqueCompositeChild.list()*.parent.collect { [it.code, it.revision] }.toSet() ==
[['a', 1], ['a', 2], ['b', 1]] as Set
}

void "a duplicate enum for the same composite parent violates the unique key"() {
given:
def parent = new EnumUniqueCompositeParent(code: 'duplicate', revision: 1).save(failOnError: true)
new EnumUniqueCompositeChild(parent: parent, state: EnumUniqueCompositeState.ON).save(flush: true, failOnError: true)

when:
new EnumUniqueCompositeChild(parent: parent, state: EnumUniqueCompositeState.ON).save(flush: true, validate: false)

then:
thrown(DataIntegrityViolationException)
}

void "a string unique group includes every configured column of a composite parent"() {
given:
def table = datastore.metadata.getEntityBinding(StringUniqueCompositeChild.name).table

expect:
table.uniqueKeys.values().collect { it.columns*.name.toSet() } ==
[['code', 'parent_code', 'parent_revision'] as Set]
}

void "declared-first enum and string groups include every implicit composite-association column"() {
given:
def table = datastore.metadata.getEntityBinding(DeclaredFirstUniqueCompositeChild.name).table
def foreignKeyColumns = ['enum_unique_composite_parent_code', 'enum_unique_composite_parent_revision'] as Set

expect:
table.uniqueKeys.values().collect { it.columns*.name.toSet() }.toSet() ==
[(['code'] as Set) + foreignKeyColumns, (['kind'] as Set) + foreignKeyColumns] as Set
table.getForeignKeys().values().any { it.columns*.name.toSet() == foreignKeyColumns }
}

void "declared-first enum and string groups accept parents differing in either identifier column"() {
when:
[['a', 1], ['a', 2], ['b', 1]].each { code, revision ->
def parent = new EnumUniqueCompositeParent(code: code, revision: revision).save(failOnError: true)
new DeclaredFirstUniqueCompositeChild(parent: parent, code: 'same', kind: EnumUniqueCompositeState.ON)
.save(failOnError: true)
}
manager.session.flush()
manager.session.clear()

then:
DeclaredFirstUniqueCompositeChild.count() == 3
}

void "a declared-first composite user type group includes every implicit composite-association column"() {
given:
def table = datastore.metadata.getEntityBinding(DeclaredFirstCompositeAmountChild.name).table

expect:
table.uniqueKeys.values().collect { it.columns*.name.toSet() } ==
[['amount_amount', 'amount_currency', 'enum_unique_composite_parent_code',
'enum_unique_composite_parent_revision'] as Set]
}

void "a declared-first composite user type group accepts parents differing in either identifier column"() {
when:
[['a', 1], ['a', 2], ['b', 1]].each { code, revision ->
def parent = new EnumUniqueCompositeParent(code: code, revision: revision).save(failOnError: true)
new DeclaredFirstCompositeAmountChild(parent: parent, amount: new CompositeMoney(amount: 10, currency: 'EUR'))
.save(failOnError: true)
}
manager.session.flush()
manager.session.clear()

then:
DeclaredFirstCompositeAmountChild.count() == 3
}

void "a duplicate declared-first composite value for the same parent violates the unique key"() {
given:
def parent = new EnumUniqueCompositeParent(code: 'duplicate', revision: 1).save(failOnError: true)
new DeclaredFirstCompositeAmountChild(parent: parent, amount: new CompositeMoney(amount: 10, currency: 'EUR'))
.save(flush: true, failOnError: true)

when:
new DeclaredFirstCompositeAmountChild(parent: parent, amount: new CompositeMoney(amount: 10, currency: 'EUR'))
.save(flush: true, validate: false)

then:
thrown(DataIntegrityViolationException)
}

void "a duplicate declared-first #property for the same composite parent violates the unique key"() {
given:
def parent = new EnumUniqueCompositeParent(code: 'duplicate', revision: 1).save(failOnError: true)
new DeclaredFirstUniqueCompositeChild(parent: parent, code: 'same', kind: EnumUniqueCompositeState.ON)
.save(flush: true, failOnError: true)

when:
new DeclaredFirstUniqueCompositeChild(parent: parent, code: code, kind: kind).save(flush: true, validate: false)

then:
thrown(DataIntegrityViolationException)

where:
property | code | kind
'string' | 'same' | EnumUniqueCompositeState.OFF
'enum' | 'other' | EnumUniqueCompositeState.ON
}
}

enum EnumUniqueCompositeState {
ON, OFF
}

@Entity
@EqualsAndHashCode(includes = ['code', 'revision'])
class EnumUniqueCompositeParent implements HibernateEntity<EnumUniqueCompositeParent>, Serializable {
String code
Integer revision

static mapping = {
id composite: ['code', 'revision']
}
}

@Entity
class EnumUniqueCompositeChild implements HibernateEntity<EnumUniqueCompositeChild> {
EnumUniqueCompositeParent parent
EnumUniqueCompositeState state

static mapping = {
state column: 'child_state', unique: 'parent'
parent {
column name: 'parent_code'
column name: 'parent_revision'
}
}
}

@Entity
class StringUniqueCompositeChild implements HibernateEntity<StringUniqueCompositeChild> {
String code
EnumUniqueCompositeParent parent

static mapping = {
code unique: 'parent'
parent {
column name: 'parent_code'
column name: 'parent_revision'
}
}
}

@Entity
class DeclaredFirstUniqueCompositeChild implements HibernateEntity<DeclaredFirstUniqueCompositeChild> {
String code
EnumUniqueCompositeState kind
EnumUniqueCompositeParent parent

static mapping = {
code unique: 'parent'
kind unique: 'parent'
}
}

@Entity
class DeclaredFirstCompositeAmountChild implements HibernateEntity<DeclaredFirstCompositeAmountChild> {
CompositeMoney amount
EnumUniqueCompositeParent parent

static mapping = {
amount type: CompositeMoneyType, unique: 'parent'
}
}
Loading
Loading