Skip to content

HHH-19324 - Switch tests using hbm.xml to use mapping.xml #9956

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 1 commit into from
May 2, 2025
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
@@ -1,12 +1,11 @@
[[collections]]
=== Collections
:majorMinorVersion: 6.2
:root-project-dir: ../../../../../../..
:core-project-dir: {root-project-dir}/hibernate-core
:core-test-base: {core-project-dir}/src/test/java
:example-dir-collection: {core-test-base}/org/hibernate/orm/test/mapping/collections
:docs-base: https://docs.jboss.org/hibernate/orm/{majorMinorVersion}
:javadoc-base: {docs-base}/javadoc
:javadoc-base: {docs-base}/javadocs
:java-javadoc-base: https://docs.oracle.com/en/java/javase/11/docs/api/java.base
:extrasdir: extras/collections

Expand Down Expand Up @@ -285,7 +284,16 @@ is available to have Hibernate interpret a `List` with no `@OrderColumn` and no


An ID_BAG is similar to a BAG, except that it maps a generated, per-row identifier into the collection
table. `@CollectionId` is the annotation to configure this identifier
table. `@CollectionId` is the annotation to configure this identifier.

For details about defining an id-bad identifier, see the Javadocs for:

* link:{javadoc-base}/org/hibernate/annotations/CollectionId.html[@CollectionId]
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJavaClass.html[@CollectionIdJavaClass]
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJavaType.html[@CollectionIdJavaType]
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJdbcType.html[@CollectionIdJdbcType]
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJdbcTypeCode.html[@CollectionIdJdbcTypeCode]
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdType.html[@CollectionIdType]


// todo (6.0) - finish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@DomainModel(
annotatedClasses = { Person.class },
xmlMappings = "org/hibernate/community/dialect/Person.hbm.xml"
)
@DomainModel(annotatedClasses = Person.class)
@RequiresDialect(AltibaseDialect.class)
@SessionFactory
public class AltibaseFunctionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
*/
package org.hibernate.community.dialect;

import java.sql.*;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;

import java.sql.Date;
import java.sql.Blob;
import java.sql.Clob;

@Entity
public class Person {
@Id
@GeneratedValue
@SequenceGenerator(sequenceName = "PERSON_SEQ")
private int id;
private String name;
private Date birthDate;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Describe an identifier column for a bag.
* Describe the identifier for an id-bag.
*
* @see CollectionIdJavaClass
* @see CollectionIdJavaType
* @see CollectionIdJdbcType
* @see CollectionIdJdbcTypeCode
* @see CollectionIdMutability
* @see CollectionIdType
*
* @author Emmanuel Bernard
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.annotations;

import org.hibernate.Incubating;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Specifies the Java class to use for the {@linkplain CollectionId id} of an id-bag mapping.
* An alternative to {@linkplain CollectionIdJavaType}. E.g.
*
* <pre>
* &#64;Bag
* &#64;CollectionId(generator="increment")
* &#64;CollectionIdJavaClass(Integer.class)
* Collection&lt;Person&gt; authors;
* </pre>
*
* @since 7.1
*
* @author Steve Ebersole
*/
@Incubating
@Target({METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
public @interface CollectionIdJavaClass {
/**
* The Java class to use as the collection-id.
*/
Class<?> idType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/**
* Form of {@link JavaType} for describing the id of an id-bag mapping.
*
* @see CollectionIdJavaClass
*
* @since 6.0
*/
@Inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.hibernate.boot.jaxb.mapping.spi;

import jakarta.persistence.DiscriminatorType;

import java.util.List;

/**
Expand All @@ -29,6 +31,8 @@ public interface JaxbAnyMapping extends JaxbPersistentAttribute {
*/
interface Key {
List<JaxbColumnImpl> getColumns();
String getType();
String getJavaClass();
}

/**
Expand All @@ -42,6 +46,11 @@ interface Discriminator {
*/
JaxbColumnImpl getColumn();

/**
* The type of discriminator
*/
DiscriminatorType getType();

/**
* Mapping of discriminator-values to the corresponding entity names
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
* @author Steve Ebersole
*/
public interface JaxbBasicMapping {
/**
* The attribute's name
*/
String getName();
void setName(String name);

JaxbUserTypeImpl getType();

void setType(JaxbUserTypeImpl value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
*/
package org.hibernate.boot.jaxb.mapping.spi;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* @author Steve Ebersole
*/
public interface JaxbEmbeddable extends JaxbManagedType {
@Nullable
String getName();
void setName(@Nullable String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,21 @@ private void prepareCollectionId(MemberDetails attribute) {
implicitJavaTypeAccess = typeConfiguration -> null;

explicitJavaTypeAccess = typeConfiguration -> {
final CollectionIdJavaType javaTypeAnn =
attribute.locateAnnotationUsage( CollectionIdJavaType.class, getSourceModelContext() );
final CollectionIdJavaClass javaClassAnn = attribute.locateAnnotationUsage(
CollectionIdJavaClass.class,
getSourceModelContext()
);
if ( javaClassAnn != null ) {
return (BasicJavaType<?>) buildingContext
.getBootstrapContext()
.getTypeConfiguration()
.getJavaTypeRegistry()
.getDescriptor( javaClassAnn.idType() );
}
final CollectionIdJavaType javaTypeAnn = attribute.locateAnnotationUsage(
CollectionIdJavaType.class,
getSourceModelContext()
);
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaType<?>> javaTypeClass = javaTypeAnn.value();
if ( javaTypeClass != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,7 @@
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
import org.hibernate.annotations.Bag;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheLayout;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Check;
import org.hibernate.annotations.Checks;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionIdJavaType;
import org.hibernate.annotations.CollectionIdJdbcType;
import org.hibernate.annotations.CollectionIdJdbcTypeCode;
import org.hibernate.annotations.CollectionType;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.CompositeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchProfileOverride;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterJoinTable;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.HQLSelect;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.LazyGroup;
import org.hibernate.annotations.ListIndexBase;
import org.hibernate.annotations.ListIndexJavaType;
import org.hibernate.annotations.ListIndexJdbcType;
import org.hibernate.annotations.ListIndexJdbcTypeCode;
import org.hibernate.annotations.ManyToAny;
import org.hibernate.annotations.MapKeyJavaType;
import org.hibernate.annotations.MapKeyJdbcType;
import org.hibernate.annotations.MapKeyJdbcTypeCode;
import org.hibernate.annotations.MapKeyMutability;
import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.QueryCacheLayout;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLJoinTableRestriction;
import org.hibernate.annotations.SQLOrder;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.SQLSelect;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.SoftDelete;
import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.SqlFragmentAlias;
import org.hibernate.annotations.Synchronize;
import org.hibernate.annotations.*;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation;
Expand Down Expand Up @@ -1004,6 +954,7 @@ private static CollectionClassification determineCollectionClassification(
}

if ( property.hasDirectAnnotationUsage( CollectionId.class )
|| property.hasDirectAnnotationUsage( CollectionIdJavaClass.class )
|| property.hasDirectAnnotationUsage( CollectionIdJdbcType.class )
|| property.hasDirectAnnotationUsage( CollectionIdJdbcTypeCode.class )
|| property.hasDirectAnnotationUsage( CollectionIdJavaType.class ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ public Column[] getOverriddenColumn(String propertyName) {

private String extractUserPropertyName(String redundantString, String propertyName) {
String className = component.getOwner().getClassName();
boolean specialCase = propertyName.startsWith(className)
&& propertyName.length() > className.length() + 2 + redundantString.length() // .id.
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() )
.equals(redundantString);
if (specialCase) {
//remove id we might be in a @IdClass case
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
if ( className != null && propertyName.startsWith( className ) ) {
boolean specialCase = propertyName.length() > className.length() + 2 + redundantString.length()
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() ).equals( redundantString );
if ( specialCase ) {
//remove id we might be in a @IdClass case
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.annotations.internal.GenericGeneratorAnnotation;
import org.hibernate.boot.models.spi.GenericGeneratorRegistration;
import org.hibernate.boot.models.spi.GlobalRegistrations;
import org.hibernate.boot.models.spi.SequenceGeneratorRegistration;
Expand Down Expand Up @@ -351,6 +352,21 @@ protected void handleNamedAutoGenerator() {
}

private boolean handleAsLocalAutoGenerator() {
if ( "increment".equals( generatedValue.generator() ) ) {
final GenericGeneratorAnnotation incrementGenerator = new GenericGeneratorAnnotation( buildingContext.getBootstrapContext().getModelsContext() );
incrementGenerator.name( "increment" );
incrementGenerator.strategy( "increment" );

GeneratorAnnotationHelper.handleGenericGenerator(
generatedValue.generator(),
incrementGenerator,
entityMapping,
idValue,
buildingContext
);
return true;
}

final String generator = generatedValue.generator();
assert !generator.isEmpty();

Expand Down
Loading
Loading