Skip to content

Commit e7c8179

Browse files
committed
HHH-19317 - Mark org.hibernate.boot.models as incubating
1 parent 04b2dd1 commit e7c8179

File tree

4 files changed

+71
-132
lines changed

4 files changed

+71
-132
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public Builder(EffectiveMappingDefaults parentDefaults) {
170170
this.autoImportEnabled = parentDefaults.isDefaultAutoImport();
171171

172172
this.implicitCascadeTypes = parentDefaults.getDefaultCascadeTypes();
173+
this.implicitPropertyAccessType = parentDefaults.getDefaultPropertyAccessType();
173174
this.implicitPropertyAccessorName = parentDefaults.getDefaultAccessStrategyName();
174175
this.entitiesImplicitlyLazy = parentDefaults.isDefaultEntityLaziness();
175176
this.pluralAttributesImplicitlyLazy = parentDefaults.isDefaultCollectionLaziness();

hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.boot.models.annotations.internal.CollectionTableJpaAnnotation;
1212
import org.hibernate.boot.models.annotations.internal.ElementCollectionJpaAnnotation;
1313
import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation;
14+
import org.hibernate.boot.models.xml.internal.SimpleTypeInterpretation;
1415
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
1516
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
1617
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
@@ -53,7 +54,7 @@ public static MutableMemberDetails processElementCollectionAttribute(
5354
elementCollectionUsage.fetch( jaxbElementCollection.getFetch() );
5455
}
5556

56-
applyTarget( jaxbElementCollection, xmlDocumentContext, memberDetails );
57+
applyElementCollectionElementType( jaxbElementCollection, elementCollectionUsage, memberDetails, xmlDocumentContext );
5758

5859
// NOTE: it is important that this happens before the `CommonPluralAttributeProcessing#applyPluralAttributeStructure`
5960
// call below
@@ -91,6 +92,22 @@ public static MutableMemberDetails processElementCollectionAttribute(
9192
return memberDetails;
9293
}
9394

95+
private static void applyElementCollectionElementType(
96+
JaxbElementCollectionImpl jaxbElementCollection,
97+
ElementCollectionJpaAnnotation elementCollectionUsage,
98+
MutableMemberDetails memberDetails,
99+
XmlDocumentContext xmlDocumentContext) {
100+
if ( StringHelper.isNotEmpty( jaxbElementCollection.getTargetClass() ) ) {
101+
final SimpleTypeInterpretation simpleTypeInterpretation = SimpleTypeInterpretation.interpret( jaxbElementCollection.getTargetClass() );
102+
if ( simpleTypeInterpretation != null ) {
103+
elementCollectionUsage.targetClass( simpleTypeInterpretation.getJavaType() );
104+
return;
105+
}
106+
}
107+
108+
applyTarget( jaxbElementCollection, xmlDocumentContext, memberDetails );
109+
}
110+
94111
private static void applyTarget(
95112
JaxbElementCollectionImpl jaxbElementCollection,
96113
XmlDocumentContext xmlDocumentContext,

hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/DynamicModelTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ void testSemiSimpleDynamicModel(ServiceRegistryScope registryScope) {
9999
final FieldDetails labels = classDetails.findFieldByName( "labels" );
100100
assertThat( labels.getType().determineRawClass().getClassName() ).isEqualTo( Set.class.getName() );
101101
final ElementCollection elementCollection = labels.getDirectAnnotationUsage( ElementCollection.class );
102-
assertThat( elementCollection.targetClass() ).isEqualTo( void.class );
103-
final Target targetUsage = labels.getDirectAnnotationUsage( Target.class );
104-
assertThat( targetUsage.value() ).isEqualTo( "string" );
102+
assertThat( elementCollection.targetClass() ).isEqualTo( String.class );
105103

106104
final CollectionClassification collectionClassification = labels.getDirectAnnotationUsage( CollectionClassification.class );
107105
assertThat( collectionClassification.value() ).isEqualTo( LimitedCollectionClassification.SET );

hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/xml/XmlAccessTest.java

Lines changed: 51 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
*/
55
package org.hibernate.orm.test.bootstrap.binding.annotations.access.xml;
66

7-
import java.io.IOException;
8-
import java.io.InputStream;
9-
import java.util.ArrayList;
10-
import java.util.Collections;
11-
import java.util.List;
12-
13-
import org.hibernate.cfg.Configuration;
147
import org.hibernate.engine.spi.SessionFactoryImplementor;
158
import org.hibernate.metamodel.mapping.AttributeMapping;
169
import org.hibernate.metamodel.mapping.AttributeMappingsList;
@@ -19,7 +12,10 @@
1912
import org.hibernate.property.access.spi.GetterFieldImpl;
2013
import org.hibernate.property.access.spi.GetterMethodImpl;
2114

22-
import org.hibernate.testing.util.ServiceRegistryUtil;
15+
import org.hibernate.testing.orm.junit.DomainModel;
16+
import org.hibernate.testing.orm.junit.ServiceRegistry;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
2319
import org.junit.jupiter.api.Test;
2420

2521
import jakarta.persistence.AccessType;
@@ -31,155 +27,82 @@
3127
*
3228
* @author Hardy Ferentschik
3329
*/
30+
@SuppressWarnings("JUnitMalformedDeclaration")
3431
public class XmlAccessTest {
3532

3633
@Test
37-
public void testAccessOnBasicXmlElement() {
38-
Class<?> classUnderTest = Tourist.class;
39-
List<Class<?>> classes = new ArrayList<>();
40-
classes.add( classUnderTest );
41-
List<String> configFiles = Collections.emptyList();
42-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
43-
34+
@ServiceRegistry
35+
@DomainModel(annotatedClasses = Tourist.class)
36+
@SessionFactory
37+
void testBaseline(SessionFactoryScope factoryScope) {
4438
// without any xml configuration we have field access
45-
assertAccessType( factory, classUnderTest, AccessType.FIELD );
46-
factory.close();
47-
// now with an additional xml configuration file changing the default access type for Tourist using basic
48-
configFiles = new ArrayList<>();
49-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist.xml" );
50-
factory = buildSessionFactory( classes, configFiles );
51-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
52-
factory.close();
39+
assertAccessType( factoryScope.getSessionFactory(), Tourist.class, AccessType.FIELD );
5340
}
5441

5542
@Test
56-
public void testAccessOnPersistenceUnitDefaultsXmlElement() {
57-
Class<?> classUnderTest = Tourist.class;
58-
List<Class<?>> classes = new ArrayList<>();
59-
classes.add( classUnderTest );
60-
List<String> configFiles = Collections.emptyList();
61-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
62-
63-
// without any xml configuration we have field access
64-
assertAccessType( factory, classUnderTest, AccessType.FIELD );
65-
factory.close();
66-
// now with an additional xml configuration file changing the default access type for Tourist using persitence unit defaults
67-
configFiles = new ArrayList<>();
68-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist2.xml" );
69-
factory = buildSessionFactory( classes, configFiles );
70-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
71-
factory.close();
43+
@ServiceRegistry
44+
@DomainModel(annotatedClasses = Tourist.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist.xml")
45+
@SessionFactory
46+
public void testAccessOnBasicXmlElement(SessionFactoryScope factoryScope) {
47+
assertAccessType( factoryScope.getSessionFactory(), Tourist.class, AccessType.PROPERTY );
7248
}
7349

7450
@Test
75-
public void testAccessOnEntityMappingsXmlElement() {
76-
Class<?> classUnderTest = Tourist.class;
77-
List<Class<?>> classes = new ArrayList<>();
78-
classes.add( classUnderTest );
79-
List<String> configFiles = Collections.emptyList();
80-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
81-
82-
// without any xml configuration we have field access
83-
assertAccessType( factory, classUnderTest, AccessType.FIELD );
84-
factory.close();
85-
// now with an additional xml configuration file changing the default access type for Tourist using default in entity-mappings
86-
configFiles = new ArrayList<>();
87-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist3.xml" );
88-
factory = buildSessionFactory( classes, configFiles );
89-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
90-
factory.close();
51+
@ServiceRegistry
52+
@DomainModel(annotatedClasses = Tourist.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist2.xml")
53+
@SessionFactory
54+
public void testAccessOnPersistenceUnitDefaultsXmlElement(SessionFactoryScope factoryScope) {
55+
assertAccessType( factoryScope.getSessionFactory(), Tourist.class, AccessType.PROPERTY );
9156
}
9257

9358
@Test
94-
public void testAccessOnEntityXmlElement() {
95-
Class<?> classUnderTest = Tourist.class;
96-
List<Class<?>> classes = new ArrayList<>();
97-
classes.add( classUnderTest );
98-
List<String> configFiles = Collections.emptyList();
99-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
100-
101-
// without any xml configuration we have field access
102-
assertAccessType( factory, classUnderTest, AccessType.FIELD );
103-
factory.close();
104-
// now with an additional xml configuration file changing the default access type for Tourist using entity level config
105-
configFiles = new ArrayList<>();
106-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist4.xml" );
107-
factory = buildSessionFactory( classes, configFiles );
108-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
109-
factory.close();
59+
@ServiceRegistry
60+
@DomainModel(annotatedClasses = Tourist.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist3.xml")
61+
@SessionFactory
62+
public void testAccessOnEntityMappingsXmlElement(SessionFactoryScope factoryScope) {
63+
assertAccessType( factoryScope.getSessionFactory(), Tourist.class, AccessType.PROPERTY );
11064
}
11165

11266
@Test
113-
public void testAccessOnMappedSuperClassXmlElement() {
114-
Class<?> classUnderTest = Waiter.class;
115-
List<Class<?>> classes = new ArrayList<>();
116-
classes.add( classUnderTest );
117-
classes.add( Crew.class );
118-
List<String> configFiles = new ArrayList<>();
119-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Crew.xml" );
120-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
121-
assertAccessType( factory, classUnderTest, AccessType.FIELD );
122-
factory.close();
67+
@ServiceRegistry
68+
@DomainModel(annotatedClasses = Tourist.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Tourist4.xml")
69+
@SessionFactory
70+
public void testAccessOnEntityXmlElement(SessionFactoryScope factoryScope) {
71+
assertAccessType( factoryScope.getSessionFactory(), Tourist.class, AccessType.PROPERTY );
12372
}
12473

12574
@Test
126-
public void testAccessOnAssociationXmlElement() {
127-
Class<?> classUnderTest = RentalCar.class;
128-
List<Class<?>> classes = new ArrayList<>();
129-
classes.add( classUnderTest );
130-
classes.add( Driver.class );
131-
List<String> configFiles = new ArrayList<>();
132-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/RentalCar.xml" );
133-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
134-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
135-
factory.close();
75+
@ServiceRegistry
76+
@DomainModel(annotatedClasses = Waiter.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Crew.xml")
77+
@SessionFactory
78+
public void testAccessOnMappedSuperClassXmlElement(SessionFactoryScope factoryScope) {
79+
assertAccessType( factoryScope.getSessionFactory(), Waiter.class, AccessType.FIELD );
13680
}
13781

13882
@Test
139-
public void testAccessOnEmbeddedXmlElement() {
140-
Class<?> classUnderTest = Cook.class;
141-
List<Class<?>> classes = new ArrayList<>();
142-
classes.add( classUnderTest );
143-
classes.add( Knive.class );
144-
List<String> configFiles = new ArrayList<>();
145-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Cook.xml" );
146-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
147-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
148-
factory.close();
83+
@ServiceRegistry
84+
@DomainModel(annotatedClasses = {RentalCar.class, Driver.class}, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/RentalCar.xml")
85+
@SessionFactory
86+
public void testAccessOnAssociationXmlElement(SessionFactoryScope factoryScope) {
87+
assertAccessType( factoryScope.getSessionFactory(), RentalCar.class, AccessType.PROPERTY );
14988
}
15089

15190
@Test
152-
public void testAccessOnElementCollectionXmlElement() {
153-
Class<?> classUnderTest = Boy.class;
154-
List<Class<?>> classes = new ArrayList<>();
155-
classes.add( classUnderTest );
156-
List<String> configFiles = new ArrayList<>();
157-
configFiles.add( "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Boy.xml" );
158-
SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
159-
assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
160-
factory.close();
91+
@ServiceRegistry
92+
@DomainModel(annotatedClasses = {Cook.class, Knive.class}, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Cook.xml")
93+
@SessionFactory
94+
public void testAccessOnEmbeddedXmlElement(SessionFactoryScope factoryScope) {
95+
assertAccessType( factoryScope.getSessionFactory(), Cook.class, AccessType.PROPERTY );
16196
}
16297

163-
private SessionFactoryImplementor buildSessionFactory(List<Class<?>> classesUnderTest, List<String> configFiles) {
164-
assert classesUnderTest != null;
165-
assert configFiles != null;
166-
Configuration cfg = new Configuration();
167-
for ( Class<?> clazz : classesUnderTest ) {
168-
cfg.addAnnotatedClass( clazz );
169-
}
170-
ServiceRegistryUtil.applySettings( cfg.getStandardServiceRegistryBuilder() );
171-
for ( String configFile : configFiles ) {
172-
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile )) {
173-
cfg.addInputStream( is );
174-
}
175-
catch (IOException e) {
176-
throw new IllegalArgumentException( e );
177-
}
178-
}
179-
return (SessionFactoryImplementor) cfg.buildSessionFactory();
98+
@Test
99+
@ServiceRegistry
100+
@DomainModel(annotatedClasses = Boy.class, xmlMappings = "org/hibernate/orm/test/bootstrap/binding.annotations.access.xml/Boy.xml")
101+
@SessionFactory
102+
public void testAccessOnElementCollectionXmlElement(SessionFactoryScope factoryScope) {
103+
assertAccessType( factoryScope.getSessionFactory(), Boy.class, AccessType.PROPERTY );
180104
}
181105

182-
// uses the first getter of the tupelizer for the assertions
183106

184107
private void assertAccessType(SessionFactoryImplementor factory, Class<?> classUnderTest, AccessType accessType) {
185108
final EntityPersister entityDescriptor = factory.getRuntimeMetamodels()

0 commit comments

Comments
 (0)