Skip to content
Merged
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 @@ -2743,9 +2743,11 @@ else if ( source instanceof JaxbHbmIdBagCollectionType idBag ) {
// the target will cause CollectionBinder to classify it as ID_BAG.
// Setting BAG explicitly would bypass the CollectionId annotation check.
transferCollectionId( idBag, target );
target.setOrderBy( idBag.getOrderBy() );
}
else if ( source instanceof JaxbHbmBagCollectionType ) {
else if ( source instanceof JaxbHbmBagCollectionType bag ) {
target.setClassification( LimitedCollectionClassification.BAG );
target.setOrderBy( bag.getOrderBy() );
}
else if ( source instanceof JaxbHbmListType listType ) {
transferListIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,27 @@ public void testSiblingEntitiesWithSameColumnNameDifferentColumnMetadata(Service
} );
}

@Test
@JiraKey( "HHH-20762" )
public void testIdBagOrderByTransformation(ServiceRegistryScope scope) {
transformAndVerify( "xml/jaxb/mapping/idbag-order-by/hbm.xml", scope, transformed -> {
assertThat( transformed.getEntities() ).hasSize( 2 );

final JaxbEntityImpl ownerEntity = transformed.getEntities().stream()
.filter( e -> "IdBagOwner".equals( e.getClazz() ) )
.findFirst()
.orElseThrow();

assertThat( ownerEntity.getAttributes().getManyToManyAttributes() ).hasSize( 1 );

final JaxbManyToManyImpl items = ownerEntity.getAttributes().getManyToManyAttributes().get( 0 );
assertThat( items.getName() ).isEqualTo( "items" );
assertThat( items.getOrderBy() )
.as( "idbag order-by should be transferred to the many-to-many" )
.isEqualTo( "itemName asc" );
} );
}

@Test
@JiraKey( "HHH-20697" )
public void testNonAggregatedCompositeIdColumnsNotUnique(ServiceRegistryScope scope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.boot.jaxb.mapping.idbagorderby;

public class IdBagItem {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.boot.jaxb.mapping.idbagorderby;

import java.util.ArrayList;
import java.util.List;

public class IdBagOwner {
private String name;
private List<IdBagItem> items = new ArrayList<>();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<IdBagItem> getItems() {
return items;
}

public void setItems(List<IdBagItem> items) {
this.items = items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ SPDX-License-Identifier: Apache-2.0
~ Copyright Red Hat Inc. and Hibernate Authors
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.orm.test.boot.jaxb.mapping.idbagorderby">

<class name="IdBagOwner" table="idbag_owner">
<id name="name"/>

<idbag name="items" order-by="itemName asc" table="owner_items">
<collection-id type="long" column="bag_id">
<generator class="increment"/>
</collection-id>
<key column="ownerName"/>
<many-to-many column="itemName" class="IdBagItem"/>
</idbag>
</class>

<class name="IdBagItem" table="idbag_item">
<id name="name"/>
</class>

</hibernate-mapping>