Skip to content

HHH-19299 - <element-collection/> with LIST classification interpreted as BAG #10107

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ public static void applyPluralAttributeStructure(
private static FetchMode interpretFetchMode(JaxbPluralFetchModeImpl fetchMode) {
return switch ( fetchMode ) {
case JOIN -> FetchMode.JOIN;
case SELECT -> FetchMode.SELECT;
case SUBSELECT -> FetchMode.SELECT;
case SELECT, SUBSELECT -> FetchMode.SELECT;
};
}

Expand All @@ -211,15 +210,16 @@ private static void applyOrderColumn(
MutableMemberDetails memberDetails,
XmlDocumentContext xmlDocumentContext) {
final JaxbOrderColumnImpl jaxbOrderColumn = jaxbPluralAttribute.getOrderColumn();
if ( jaxbOrderColumn == null ) {
return;
}

final OrderColumnJpaAnnotation orderColumnAnn = (OrderColumnJpaAnnotation) memberDetails.applyAnnotationUsage(
JpaAnnotations.ORDER_COLUMN,
xmlDocumentContext.getModelBuildingContext()
);
if ( jaxbOrderColumn != null
|| jaxbPluralAttribute.getClassification() == LimitedCollectionClassification.LIST ) {
final OrderColumnJpaAnnotation orderColumnAnn = (OrderColumnJpaAnnotation) memberDetails.applyAnnotationUsage(
JpaAnnotations.ORDER_COLUMN,
xmlDocumentContext.getModelBuildingContext()
);

orderColumnAnn.apply( jaxbOrderColumn, xmlDocumentContext );
if ( jaxbOrderColumn != null ) {
orderColumnAnn.apply( jaxbOrderColumn, xmlDocumentContext );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.List;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.PersistentClass;
Expand All @@ -29,6 +30,8 @@ void testXml(DomainModelScope domainModelScope) {
final PersistentClass rootBinding = domainModelScope.getDomainModel().getEntityBinding( Root.class.getName() );
validateTags( rootBinding.getProperty( "tags" ) );
validateCategories( rootBinding.getProperty( "categories" ) );
validateAdmins( rootBinding.getProperty( "admins" ) );
validateAdmins2( rootBinding.getProperty( "admins2" ) );
}

private void validateTags(Property tags) {
Expand Down Expand Up @@ -58,9 +61,6 @@ private void validateCategories(Property categories) {
else if ( "owner".equals( subProperty.getName() ) ) {
validateCategoryOwner( subProperty );
}
else if ( "admins".equals( subProperty.getName() ) ) {
validateAdmins( subProperty );
}
else {
fail( "Unexpected Category property :" + subProperty.getName() );
}
Expand All @@ -80,16 +80,41 @@ private void validateCategoryOwner(Property owenerProperty) {

}

private void validateAdmins(Property adminsProperty) {
assertThat( adminsProperty.getColumns() ).hasSize( 1 );
assertThat( adminsProperty.getColumns().get( 0 ).getName() ).isEqualTo( "root_fk" );
private void validateAdmins(Property property) {
// mapped as many-to-many
assertThat( property.getColumns() ).isEmpty();

final List listValue = (List) adminsProperty.getValue();
final List listValue = (List) property.getValue();
assertThat( listValue.getCollectionTable().getName() ).isEqualTo( "root_admins" );

final KeyValue foreignKey = listValue.getKey();
assertThat( foreignKey.getColumns() ).hasSize( 1 );
assertThat( foreignKey.getColumns().get( 0 ).getName() ).isEqualTo( "root_fk" );

final BasicValue indexValue = (BasicValue) listValue.getIndex();
assertThat( indexValue.getColumns() ).hasSize( 1 );

final ManyToOne element = (ManyToOne) listValue.getElement();
assertThat( element.getReferencedEntityName() ).isEqualTo( User.class.getName() );
}

private void validateAdmins2(Property property) {
// mapped as one-to-many
assertThat( property.getColumns() ).isEmpty();

final List listValue = (List) property.getValue();
assertThat( listValue.getColumns() ).isEmpty();
assertThat( listValue.getCollectionTable().getName() ).isEqualTo( "root_admins2" );

// key
final KeyValue foreignKey = listValue.getKey();
assertThat( foreignKey.getColumns() ).hasSize( 1 );
assertThat( foreignKey.getColumns().get( 0 ).getName() ).isEqualTo( "root_fk" );

final BasicValue indexValue = (BasicValue) listValue.getIndex();
assertThat( indexValue.getColumns() ).hasSize( 1 );

final ManyToOne element = (ManyToOne) listValue.getElement();
assertThat( element.getReferencedEntityName() ).isEqualTo( User.class.getName() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
</one-to-many>

<many-to-many name="admins" classification="LIST" target-entity="User">
<order-column/>
<join-table name="root_admins">
<join-column name="root_fk"/>
<inverse-join-column name="user_fk"/>
</join-table>
</many-to-many>

<element-collection name="tags" classification="LIST" target-class="java.lang.String">
<order-column/>
<column name="txt"/>
<collection-table>
<join-column name="root_fk"/>
Expand Down
Loading