Skip to content

Commit a657c4c

Browse files
committed
HHH-19324 - Switch tests using hbm.xml to use mapping.xml
HHH-19310 - Simplified declaration of type for basic mappings in XML HHH-19422 - Introduce @CollectionIdJavaClass
1 parent aca7e9e commit a657c4c

File tree

251 files changed

+4020
-7184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+4020
-7184
lines changed

documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[[collections]]
22
=== Collections
3-
:majorMinorVersion: 6.2
43
:root-project-dir: ../../../../../../..
54
:core-project-dir: {root-project-dir}/hibernate-core
65
:core-test-base: {core-project-dir}/src/test/java
76
:example-dir-collection: {core-test-base}/org/hibernate/orm/test/mapping/collections
87
:docs-base: https://docs.jboss.org/hibernate/orm/{majorMinorVersion}
9-
:javadoc-base: {docs-base}/javadoc
8+
:javadoc-base: {docs-base}/javadocs
109
:java-javadoc-base: https://docs.oracle.com/en/java/javase/11/docs/api/java.base
1110
:extrasdir: extras/collections
1211

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

286285

287286
An ID_BAG is similar to a BAG, except that it maps a generated, per-row identifier into the collection
288-
table. `@CollectionId` is the annotation to configure this identifier
287+
table. `@CollectionId` is the annotation to configure this identifier.
288+
289+
For details about defining an id-bad identifier, see the Javadocs for:
290+
291+
* link:{javadoc-base}/org/hibernate/annotations/CollectionId.html[@CollectionId]
292+
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJavaClass.html[@CollectionIdJavaClass]
293+
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJavaType.html[@CollectionIdJavaType]
294+
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJdbcType.html[@CollectionIdJdbcType]
295+
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdJdbcTypeCode.html[@CollectionIdJdbcTypeCode]
296+
* link:{javadoc-base}/org/hibernate/annotations/CollectionIdType.html[@CollectionIdType]
289297

290298

291299
// todo (6.0) - finish

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/AltibaseFunctionsTest.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import static org.hamcrest.MatcherAssert.assertThat;
2424
import static org.junit.jupiter.api.Assertions.assertNotNull;
2525

26-
@DomainModel(
27-
annotatedClasses = { Person.class },
28-
xmlMappings = "org/hibernate/community/dialect/Person.hbm.xml"
29-
)
26+
@DomainModel(annotatedClasses = Person.class)
3027
@RequiresDialect(AltibaseDialect.class)
3128
@SessionFactory
3229
public class AltibaseFunctionsTest {

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/Person.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.sql.*;
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.SequenceGenerator;
811

12+
import java.sql.Date;
13+
import java.sql.Blob;
14+
import java.sql.Clob;
15+
16+
@Entity
917
public class Person {
18+
@Id
19+
@GeneratedValue
20+
@SequenceGenerator(sequenceName = "PERSON_SEQ")
1021
private int id;
1122
private String name;
1223
private Date birthDate;

hibernate-community-dialects/src/test/resources/org/hibernate/community/dialect/Person.hbm.xml

-25
This file was deleted.

hibernate-core/src/main/java/org/hibernate/annotations/CollectionId.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1717

1818
/**
19-
* Describe an identifier column for a bag.
19+
* Describe the identifier for an id-bag.
20+
*
21+
* @see CollectionIdJavaClass
22+
* @see CollectionIdJavaType
23+
* @see CollectionIdJdbcType
24+
* @see CollectionIdJdbcTypeCode
25+
* @see CollectionIdMutability
26+
* @see CollectionIdType
2027
*
2128
* @author Emmanuel Bernard
2229
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.annotations;
6+
7+
import org.hibernate.Incubating;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
13+
import static java.lang.annotation.ElementType.FIELD;
14+
import static java.lang.annotation.ElementType.METHOD;
15+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
16+
17+
/**
18+
* Specifies the Java class to use for the {@linkplain CollectionId id} of an id-bag mapping.
19+
* An alternative to {@linkplain CollectionIdJavaType}. E.g.
20+
*
21+
* <pre>
22+
* &#64;Bag
23+
* &#64;CollectionId(generator="increment")
24+
* &#64;CollectionIdJavaClass(Integer.class)
25+
* Collection&lt;Person&gt; authors;
26+
* </pre>
27+
*
28+
* @since 7.1
29+
*
30+
* @author Steve Ebersole
31+
*/
32+
@Incubating
33+
@Target({METHOD, FIELD, ANNOTATION_TYPE})
34+
@Retention(RUNTIME)
35+
public @interface CollectionIdJavaClass {
36+
/**
37+
* The Java class to use as the collection-id.
38+
*/
39+
Class<?> idType();
40+
}

hibernate-core/src/main/java/org/hibernate/annotations/CollectionIdJavaType.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
/**
1919
* Form of {@link JavaType} for describing the id of an id-bag mapping.
2020
*
21+
* @see CollectionIdJavaClass
22+
*
2123
* @since 6.0
2224
*/
2325
@Inherited

hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbAnyMapping.java

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.hibernate.boot.jaxb.mapping.spi;
66

7+
import jakarta.persistence.DiscriminatorType;
8+
79
import java.util.List;
810

911
/**
@@ -29,6 +31,8 @@ public interface JaxbAnyMapping extends JaxbPersistentAttribute {
2931
*/
3032
interface Key {
3133
List<JaxbColumnImpl> getColumns();
34+
String getType();
35+
String getJavaClass();
3236
}
3337

3438
/**
@@ -42,6 +46,11 @@ interface Discriminator {
4246
*/
4347
JaxbColumnImpl getColumn();
4448

49+
/**
50+
* The type of discriminator
51+
*/
52+
DiscriminatorType getType();
53+
4554
/**
4655
* Mapping of discriminator-values to the corresponding entity names
4756
*/

hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBasicMapping.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
* @author Steve Ebersole
1212
*/
1313
public interface JaxbBasicMapping {
14+
/**
15+
* The attribute's name
16+
*/
17+
String getName();
18+
void setName(String name);
19+
1420
JaxbUserTypeImpl getType();
1521

1622
void setType(JaxbUserTypeImpl value);

hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddable.java

+5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
*/
55
package org.hibernate.boot.jaxb.mapping.spi;
66

7+
import org.checkerframework.checker.nullness.qual.Nullable;
8+
79
/**
810
* @author Steve Ebersole
911
*/
1012
public interface JaxbEmbeddable extends JaxbManagedType {
13+
@Nullable
14+
String getName();
15+
void setName(@Nullable String name);
1116
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,21 @@ private void prepareCollectionId(MemberDetails attribute) {
397397
implicitJavaTypeAccess = typeConfiguration -> null;
398398

399399
explicitJavaTypeAccess = typeConfiguration -> {
400-
final CollectionIdJavaType javaTypeAnn =
401-
attribute.locateAnnotationUsage( CollectionIdJavaType.class, getSourceModelContext() );
400+
final CollectionIdJavaClass javaClassAnn = attribute.locateAnnotationUsage(
401+
CollectionIdJavaClass.class,
402+
getSourceModelContext()
403+
);
404+
if ( javaClassAnn != null ) {
405+
return (BasicJavaType<?>) buildingContext
406+
.getBootstrapContext()
407+
.getTypeConfiguration()
408+
.getJavaTypeRegistry()
409+
.getDescriptor( javaClassAnn.idType() );
410+
}
411+
final CollectionIdJavaType javaTypeAnn = attribute.locateAnnotationUsage(
412+
CollectionIdJavaType.class,
413+
getSourceModelContext()
414+
);
402415
if ( javaTypeAnn != null ) {
403416
final Class<? extends BasicJavaType<?>> javaTypeClass = javaTypeAnn.value();
404417
if ( javaTypeClass != null ) {

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

+2-51
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,7 @@
1717
import org.hibernate.AssertionFailure;
1818
import org.hibernate.FetchMode;
1919
import org.hibernate.MappingException;
20-
import org.hibernate.annotations.Bag;
21-
import org.hibernate.annotations.Cache;
22-
import org.hibernate.annotations.CacheLayout;
23-
import org.hibernate.annotations.Cascade;
24-
import org.hibernate.annotations.Check;
25-
import org.hibernate.annotations.Checks;
26-
import org.hibernate.annotations.CollectionId;
27-
import org.hibernate.annotations.CollectionIdJavaType;
28-
import org.hibernate.annotations.CollectionIdJdbcType;
29-
import org.hibernate.annotations.CollectionIdJdbcTypeCode;
30-
import org.hibernate.annotations.CollectionType;
31-
import org.hibernate.annotations.Columns;
32-
import org.hibernate.annotations.CompositeType;
33-
import org.hibernate.annotations.Fetch;
34-
import org.hibernate.annotations.FetchProfileOverride;
35-
import org.hibernate.annotations.Filter;
36-
import org.hibernate.annotations.FilterJoinTable;
37-
import org.hibernate.annotations.Formula;
38-
import org.hibernate.annotations.HQLSelect;
39-
import org.hibernate.annotations.Immutable;
40-
import org.hibernate.annotations.LazyGroup;
41-
import org.hibernate.annotations.ListIndexBase;
42-
import org.hibernate.annotations.ListIndexJavaType;
43-
import org.hibernate.annotations.ListIndexJdbcType;
44-
import org.hibernate.annotations.ListIndexJdbcTypeCode;
45-
import org.hibernate.annotations.ManyToAny;
46-
import org.hibernate.annotations.MapKeyJavaType;
47-
import org.hibernate.annotations.MapKeyJdbcType;
48-
import org.hibernate.annotations.MapKeyJdbcTypeCode;
49-
import org.hibernate.annotations.MapKeyMutability;
50-
import org.hibernate.annotations.MapKeyType;
51-
import org.hibernate.annotations.NotFound;
52-
import org.hibernate.annotations.NotFoundAction;
53-
import org.hibernate.annotations.OnDelete;
54-
import org.hibernate.annotations.OnDeleteAction;
55-
import org.hibernate.annotations.OptimisticLock;
56-
import org.hibernate.annotations.Parameter;
57-
import org.hibernate.annotations.QueryCacheLayout;
58-
import org.hibernate.annotations.SQLDelete;
59-
import org.hibernate.annotations.SQLDeleteAll;
60-
import org.hibernate.annotations.SQLInsert;
61-
import org.hibernate.annotations.SQLJoinTableRestriction;
62-
import org.hibernate.annotations.SQLOrder;
63-
import org.hibernate.annotations.SQLRestriction;
64-
import org.hibernate.annotations.SQLSelect;
65-
import org.hibernate.annotations.SQLUpdate;
66-
import org.hibernate.annotations.SoftDelete;
67-
import org.hibernate.annotations.SortComparator;
68-
import org.hibernate.annotations.SortNatural;
69-
import org.hibernate.annotations.SqlFragmentAlias;
70-
import org.hibernate.annotations.Synchronize;
20+
import org.hibernate.annotations.*;
7121
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
7222
import org.hibernate.boot.models.JpaAnnotations;
7323
import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation;
@@ -1004,6 +954,7 @@ private static CollectionClassification determineCollectionClassification(
1004954
}
1005955

1006956
if ( property.hasDirectAnnotationUsage( CollectionId.class )
957+
|| property.hasDirectAnnotationUsage( CollectionIdJavaClass.class )
1007958
|| property.hasDirectAnnotationUsage( CollectionIdJdbcType.class )
1008959
|| property.hasDirectAnnotationUsage( CollectionIdJdbcTypeCode.class )
1009960
|| property.hasDirectAnnotationUsage( CollectionIdJavaType.class ) ) {

hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ public Column[] getOverriddenColumn(String propertyName) {
341341

342342
private String extractUserPropertyName(String redundantString, String propertyName) {
343343
String className = component.getOwner().getClassName();
344-
boolean specialCase = propertyName.startsWith(className)
345-
&& propertyName.length() > className.length() + 2 + redundantString.length() // .id.
346-
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() )
347-
.equals(redundantString);
348-
if (specialCase) {
349-
//remove id we might be in a @IdClass case
350-
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
344+
if ( className != null && propertyName.startsWith( className ) ) {
345+
boolean specialCase = propertyName.length() > className.length() + 2 + redundantString.length()
346+
&& propertyName.substring( className.length() + 1, className.length() + 1 + redundantString.length() ).equals( redundantString );
347+
if ( specialCase ) {
348+
//remove id we might be in a @IdClass case
349+
return className + propertyName.substring( className.length() + 1 + redundantString.length() );
350+
}
351351
}
352352
return null;
353353
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdGeneratorResolverSecondPass.java

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
1313
import org.hibernate.boot.models.HibernateAnnotations;
1414
import org.hibernate.boot.models.JpaAnnotations;
15+
import org.hibernate.boot.models.annotations.internal.GenericGeneratorAnnotation;
1516
import org.hibernate.boot.models.spi.GenericGeneratorRegistration;
1617
import org.hibernate.boot.models.spi.GlobalRegistrations;
1718
import org.hibernate.boot.models.spi.SequenceGeneratorRegistration;
@@ -351,6 +352,21 @@ protected void handleNamedAutoGenerator() {
351352
}
352353

353354
private boolean handleAsLocalAutoGenerator() {
355+
if ( "increment".equals( generatedValue.generator() ) ) {
356+
final GenericGeneratorAnnotation incrementGenerator = new GenericGeneratorAnnotation( buildingContext.getBootstrapContext().getModelsContext() );
357+
incrementGenerator.name( "increment" );
358+
incrementGenerator.strategy( "increment" );
359+
360+
GeneratorAnnotationHelper.handleGenericGenerator(
361+
generatedValue.generator(),
362+
incrementGenerator,
363+
entityMapping,
364+
idValue,
365+
buildingContext
366+
);
367+
return true;
368+
}
369+
354370
final String generator = generatedValue.generator();
355371
assert !generator.isEmpty();
356372

0 commit comments

Comments
 (0)