From 3334534216653fd219856fac01e2ccb54b31d24f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 26 Mar 2024 20:31:09 -0500 Subject: [PATCH] HHH-17460 - Ongoing JPA 32 work HHH-17892 - Remove @Persister HHH-17893 - Remove MetadataContributor HHH-17894 - Remove AdditionalJaxbMappingProducer --- .../userguide/chapters/domain/entity.adoc | 31 ------ .../process/spi/MetadataBuildingProcess.java | 59 ++---------- .../boot/models/HibernateAnnotations.java | 1 - .../spi/AdditionalJaxbMappingProducer.java | 28 ------ .../spi/AdditionalMappingContributions.java | 2 + .../boot/spi/MetadataContributor.java | 33 ------- .../orm/test/annotations/persister/Card.java | 28 ------ .../persister/CollectionPersister.java | 26 ----- .../orm/test/annotations/persister/Deck.java | 29 ------ .../persister/EntityPersister.java | 27 ------ .../contributed/BasicContributorTests.java | 94 +++--------------- .../mapping/contributed/ContributorImpl.java | 57 +++++++++++ .../contributed/EntityHidingTests.java | 20 ++-- .../test/mapping/contributed/MainEntity.java | 46 +++++++++ .../custom/CustomTypeConverterTest.java | 93 ++++-------------- .../hibernate/orm/test/persister/Author.java | 55 ----------- .../hibernate/orm/test/persister/Book.java | 61 ------------ .../test/persister/CollectionPersister.java | 32 ------- .../orm/test/persister/EntityPersister.java | 34 ------- .../CustomSqlSchemaResolvingIdentityTest.java | 5 +- .../entity/CustomSqlSchemaResolvingTest.java | 5 +- .../AdditionalJaxbMappingProducerImpl.java | 96 ------------------- .../AdditionalMappingContributorImpl.java | 2 +- .../EnversMetadataBuildingContextImpl.java | 9 +- .../envers/boot/internal/EnversService.java | 6 +- .../boot/internal/EnversServiceImpl.java | 7 +- .../OSGI-INF/blueprint/blueprint.xml | 4 +- .../src/test/resources/log4j2.properties | 4 +- migration-guide.adoc | 5 +- 29 files changed, 177 insertions(+), 722 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Card.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/CollectionPersister.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Deck.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/EntityPersister.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/ContributorImpl.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/MainEntity.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/persister/Author.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/persister/Book.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/persister/CollectionPersister.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/persister/EntityPersister.java delete mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/entity.adoc b/documentation/src/main/asciidoc/userguide/chapters/domain/entity.adoc index 0f543a7f63..fe3108487b 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/entity.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/entity.adoc @@ -552,34 +552,3 @@ include::{example-dir-proxy}/concrete/AbstractConcreteProxyTest.java[tag=entity- include::{extrasdir}/entity/entity-concrete-proxy-reference.sql[] ---- ==== - -[[entity-persister]] -==== Define a custom entity persister - -The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/annotations/Persister.html[`@Persister`] annotation is used to specify a custom entity or collection persister. - -For entities, the custom persister must implement the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/persister/entity/EntityPersister.html[`EntityPersister`] interface. - -For collections, the custom persister must implement the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/persister/collection/CollectionPersister.html[`CollectionPersister`] interface. - -NOTE: Supplying a custom persister has been allowed historically, but has never been fully supported. -Hibernate 6 provides better, alternative ways to accomplish the use cases for a custom persister. As -of 6.2 `@Persister` has been formally deprecated. - - -[[entity-persister-mapping]] -.Entity persister mapping -==== -[source,java] ----- -include::{example-dir-persister}/Author.java[tag=entity-persister-mapping,indent=0] ----- - -[source,java] ----- -include::{example-dir-persister}/Book.java[tag=entity-persister-mapping,indent=0] ----- -==== - -By providing your own `EntityPersister` and `CollectionPersister` implementations, -you can control how entities and collections are persisted into the database. diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index 2863877cba..ad48ead06a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -59,14 +59,13 @@ import org.hibernate.boot.models.xml.spi.XmlProcessor; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; -import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; import org.hibernate.boot.spi.AdditionalMappingContributions; import org.hibernate.boot.spi.AdditionalMappingContributor; import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.EffectiveMappingDefaults; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MetadataBuildingOptions; -import org.hibernate.boot.spi.MetadataContributor; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.MetadataSourceType; @@ -236,7 +235,6 @@ public class MetadataBuildingProcess { ); processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext ); - processAdditionalJaxbMappingProducer( metadataCollector, options, jandexView, classLoaderService, rootMetadataBuildingContext ); applyExtraQueryImports( managedResources, metadataCollector ); @@ -381,11 +379,6 @@ public class MetadataBuildingProcess { processor.processResultSetMappings(); - for ( MetadataContributor contributor : classLoaderService.loadJavaServices( MetadataContributor.class ) ) { - log.tracef( "Calling MetadataContributor : %s", contributor ); - contributor.contribute( metadataCollector, jandexView ); - } - metadataCollector.processSecondPasses( rootMetadataBuildingContext ); // Make sure collections are fully bound before processing named queries as hbm result set mappings require it @@ -759,6 +752,11 @@ public class MetadataBuildingProcess { metadataCollector.addAuxiliaryDatabaseObject( auxiliaryDatabaseObject ); } + @Override + public EffectiveMappingDefaults getEffectiveMappingDefaults() { + return rootMetadataBuildingContext.getEffectiveDefaults(); + } + public void complete() { // annotations / orm.xml if ( additionalEntityClasses != null || additionalClassDetails != null || additionalJaxbMappings != null ) { @@ -781,51 +779,6 @@ public class MetadataBuildingProcess { } } - private static void processAdditionalJaxbMappingProducer( - InFlightMetadataCollectorImpl metadataCollector, - MetadataBuildingOptions options, - IndexView jandexView, - ClassLoaderService classLoaderService, - MetadataBuildingContextRootImpl rootMetadataBuildingContext) { - if ( options.isXmlMappingEnabled() ) { - final Iterable producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); - if ( producers != null ) { - final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); - final MappingBinder mappingBinder = new MappingBinder( - classLoaderService, - new MappingBinder.Options() { - @Override - public boolean validateMappings() { - return false; - } - - @Override - public boolean transformHbmMappings() { - return false; - } - } - ); - //noinspection deprecation - for ( AdditionalJaxbMappingProducer producer : producers ) { - log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer ); - Collection additionalMappings = producer.produceAdditionalMappings( - metadataCollector, - jandexView, - mappingBinder, - rootMetadataBuildingContext - ); - for ( MappingDocument mappingDocument : additionalMappings ) { - hierarchyBuilder.indexMappingDocument( mappingDocument ); - } - } - - ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); - for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { - binder.bindEntityHierarchy( entityHierarchySource ); - } - } - } - } private static void applyExtraQueryImports( ManagedResources managedResources, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java index 5ce89c6c38..15bc24eeec 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java @@ -140,7 +140,6 @@ public interface HibernateAnnotations { AnnotationDescriptor PARAMETER = createOrmDescriptor( Parameter.class ); AnnotationDescriptor PARENT = createOrmDescriptor( Parent.class ); AnnotationDescriptor PARTITION_KEY = createOrmDescriptor( PartitionKey.class ); - AnnotationDescriptor PERSISTER = createOrmDescriptor( Persister.class ); AnnotationDescriptor POLYMORPHISM = createOrmDescriptor( Polymorphism.class ); AnnotationDescriptor PROXY = createOrmDescriptor( Proxy.class ); AnnotationDescriptor ROW_ID = createOrmDescriptor( RowId.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java deleted file mode 100644 index 56bb2d9c3a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalJaxbMappingProducer.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.boot.spi; - -import java.util.Collection; - -import org.hibernate.boot.jaxb.internal.MappingBinder; -import org.hibernate.boot.model.source.internal.hbm.MappingDocument; - -import org.jboss.jandex.IndexView; - -/** - * @author Steve Ebersole - * - * @deprecated Use {@linkplain AdditionalMappingContributor} instead - */ -@Deprecated -public interface AdditionalJaxbMappingProducer { - Collection produceAdditionalMappings( - MetadataImplementor metadata, - IndexView jandexIndex, - MappingBinder mappingBinder, - MetadataBuildingContext buildingContext); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalMappingContributions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalMappingContributions.java index 1d0b5fd378..541d407b9f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalMappingContributions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AdditionalMappingContributions.java @@ -69,4 +69,6 @@ public interface AdditionalMappingContributions { * Contribute a materialized AuxiliaryDatabaseObject */ void contributeAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject); + + EffectiveMappingDefaults getEffectiveMappingDefaults(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java deleted file mode 100644 index 12984e8916..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataContributor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.boot.spi; - -import org.jboss.jandex.IndexView; - -/** - * Contract for contributing to {@link org.hibernate.boot.Metadata} ({@link InFlightMetadataCollector}). - *

- * This hook occurs just after all processing of all {@link org.hibernate.boot.MetadataSources}, - * and just before {@link AdditionalJaxbMappingProducer}. - * - * @author Steve Ebersole - * - * @since 5.0 - * - * @deprecated Use {@link AdditionalMappingContributor} or {@link org.hibernate.boot.model.TypeContributor} - * instead depending on need - */ -@Deprecated(forRemoval = true) -public interface MetadataContributor { - /** - * Perform the contributions. - * - * @param metadataCollector The metadata collector, representing the in-flight metadata being built - * @param jandexIndex The Jandex index - */ - void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex); -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Card.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Card.java deleted file mode 100644 index f02c57b4e0..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Card.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.orm.test.annotations.persister; -import org.hibernate.annotations.Persister; - -import java.io.Serializable; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; - -/** - * @author Shawn Clowater - */ -@Entity -@Persister( impl = org.hibernate.persister.entity.SingleTableEntityPersister.class ) -public class Card implements Serializable { - @Id - public Integer id; - - @ManyToOne() - @JoinColumn() - public Deck deck; -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/CollectionPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/CollectionPersister.java deleted file mode 100644 index b37ea8b71c..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/CollectionPersister.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.orm.test.annotations.persister; - -import org.hibernate.MappingException; -import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.access.CollectionDataAccess; -import org.hibernate.mapping.Collection; -import org.hibernate.persister.collection.OneToManyPersister; -import org.hibernate.persister.spi.PersisterCreationContext; - -/** - * @author Shawn Clowater - */ -public class CollectionPersister extends OneToManyPersister { - public CollectionPersister( - Collection collectionBinding, - CollectionDataAccess cacheAccessStrategy, - PersisterCreationContext creationContext) throws MappingException, CacheException { - super( collectionBinding, cacheAccessStrategy, creationContext ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Deck.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Deck.java deleted file mode 100644 index a2e1ec484d..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/Deck.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.orm.test.annotations.persister; -import java.io.Serializable; -import java.util.Set; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; - -import org.hibernate.annotations.Persister; - - -/** - * @author Shawn Clowater - */ -@Entity -@Persister( impl = EntityPersister.class ) -public class Deck implements Serializable { - @Id - public Integer id; - - @OneToMany( mappedBy = "deck" ) - @Persister( impl = CollectionPersister.class ) - public Set cards; -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/EntityPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/EntityPersister.java deleted file mode 100644 index af8d4e585c..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/persister/EntityPersister.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.orm.test.annotations.persister; - -import org.hibernate.HibernateException; -import org.hibernate.cache.spi.access.EntityDataAccess; -import org.hibernate.cache.spi.access.NaturalIdDataAccess; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.persister.entity.SingleTableEntityPersister; -import org.hibernate.persister.spi.PersisterCreationContext; - -/** - * @author Shawn Clowater - */ -public class EntityPersister extends SingleTableEntityPersister { - public EntityPersister( - PersistentClass persistentClass, - EntityDataAccess cache, - NaturalIdDataAccess naturalIdRegionAccessStrategy, - PersisterCreationContext creationContext) throws HibernateException { - super( persistentClass, cache, naturalIdRegionAccessStrategy, creationContext ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/BasicContributorTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/BasicContributorTests.java index a4d899d299..2c5c860be8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/BasicContributorTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/BasicContributorTests.java @@ -6,24 +6,10 @@ */ package org.hibernate.orm.test.mapping.contributed; -import java.io.InputStream; -import java.util.Collection; -import java.util.Collections; import java.util.Map; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import org.hibernate.boot.jaxb.Origin; -import org.hibernate.boot.jaxb.SourceType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; -import org.hibernate.boot.jaxb.internal.MappingBinder; -import org.hibernate.boot.jaxb.spi.Binding; -import org.hibernate.boot.model.source.internal.hbm.MappingDocument; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; -import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.AdditionalMappingContributor; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; @@ -47,8 +33,6 @@ import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModelScope; import org.junit.jupiter.api.Test; -import org.jboss.jandex.IndexView; - import org.hamcrest.Matchers; import static org.hamcrest.MatcherAssert.assertThat; @@ -58,9 +42,9 @@ import static org.hamcrest.Matchers.not; * @author Steve Ebersole */ @BootstrapServiceRegistry( - javaServices = @JavaService( role = AdditionalJaxbMappingProducer.class, impl = BasicContributorTests.Contributor.class ) + javaServices = @JavaService( role = AdditionalMappingContributor.class, impl = ContributorImpl.class ) ) -@DomainModel( annotatedClasses = BasicContributorTests.MainEntity.class ) +@DomainModel( annotatedClasses = MainEntity.class ) public class BasicContributorTests { @Test @@ -178,7 +162,14 @@ public class BasicContributorTests { // filter by `orm` targetDescriptor.clear(); - schemaDropper.doDrop( metadata, options, contributed -> "orm".equals( contributed.getContributor() ), dialect, sourceDescriptor, targetDescriptor ); + schemaDropper.doDrop( + metadata, + options, + contributed -> "orm".equals( contributed.getContributor() ), + dialect, + sourceDescriptor, + targetDescriptor + ); assertThat( targetDescriptor.getCommands(), CollectionElementMatcher.hasAllOf( not( CaseInsensitiveStartsWithMatcher.startsWith( "drop table DynamicEntity" ) ) ) @@ -194,67 +185,4 @@ public class BasicContributorTests { } - @Entity( name = "MainEntity" ) - @Table( name = "main_table" ) - static class MainEntity { - @Id - private Integer id; - String name; - - private MainEntity() { - } - - public MainEntity(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } - - public static class Contributor implements AdditionalJaxbMappingProducer { - public Contributor() { - } - - @Override - public Collection produceAdditionalMappings( - MetadataImplementor metadata, - IndexView jandexIndex, - MappingBinder mappingBinder, - MetadataBuildingContext buildingContext) { - return Collections.singletonList( createMappingDocument( mappingBinder, buildingContext ) ); - } - - private MappingDocument createMappingDocument(MappingBinder mappingBinder, MetadataBuildingContext buildingContext) { - final Origin origin = new Origin( SourceType.OTHER, "test" ); - - final ClassLoaderService classLoaderService = buildingContext.getBootstrapContext() - .getServiceRegistry() - .getService( ClassLoaderService.class ); - final InputStream inputStream = classLoaderService.locateResourceStream( "org/hibernate/orm/test/mapping/contributed/BasicContributorTests.hbm.xml" ); - final Binding jaxbBinding = mappingBinder.bind( inputStream, origin ); - final JaxbHbmHibernateMapping jaxbRoot = jaxbBinding.getRoot(); - - return new MappingDocument( - "test", - jaxbRoot, - origin, - buildingContext - ); - } - } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/ContributorImpl.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/ContributorImpl.java new file mode 100644 index 0000000000..e3aec09d02 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/ContributorImpl.java @@ -0,0 +1,57 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.mapping.contributed; + +import java.io.InputStream; + +import org.hibernate.boot.ResourceStreamLocator; +import org.hibernate.boot.jaxb.Origin; +import org.hibernate.boot.jaxb.SourceType; +import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; +import org.hibernate.boot.jaxb.internal.MappingBinder; +import org.hibernate.boot.jaxb.spi.Binding; +import org.hibernate.boot.model.source.internal.hbm.MappingDocument; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.AdditionalMappingContributions; +import org.hibernate.boot.spi.AdditionalMappingContributor; +import org.hibernate.boot.spi.InFlightMetadataCollector; +import org.hibernate.boot.spi.MetadataBuildingContext; + +/** + * @author Steve Ebersole + */ +public class ContributorImpl implements AdditionalMappingContributor { + public ContributorImpl() { + } + + @Override + public String getContributorName() { + return "test"; + } + + @Override + public void contribute( + AdditionalMappingContributions contributions, + InFlightMetadataCollector metadata, + ResourceStreamLocator resourceStreamLocator, + MetadataBuildingContext buildingContext) { + final Origin origin = new Origin( SourceType.OTHER, "test" ); + + final ClassLoaderService classLoaderService = buildingContext.getBootstrapContext() + .getServiceRegistry() + .getService( ClassLoaderService.class ); + final InputStream inputStream = classLoaderService.locateResourceStream( + "org/hibernate/orm/test/mapping/contributed/BasicContributorTests.hbm.xml" ); + + final MappingBinder mappingBinder = new MappingBinder( buildingContext.getBootstrapContext().getServiceRegistry() ); + final Binding jaxbBinding = mappingBinder.bind( inputStream, origin ); + final JaxbHbmHibernateMapping jaxbRoot = jaxbBinding.getRoot(); + + contributions.contributeBinding( jaxbRoot ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/EntityHidingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/EntityHidingTests.java index e262c2552a..aa52900c18 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/EntityHidingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/EntityHidingTests.java @@ -6,7 +6,7 @@ */ package org.hibernate.orm.test.mapping.contributed; -import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; +import org.hibernate.boot.spi.AdditionalMappingContributor; import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.RuntimeMetamodels; @@ -14,6 +14,7 @@ import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry.JavaService; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.NotImplementedYet; import org.hibernate.testing.orm.junit.ServiceRegistry; @@ -28,16 +29,15 @@ import static org.hamcrest.Matchers.nullValue; /** * @author Steve Ebersole */ -@BootstrapServiceRegistry( - javaServices = @BootstrapServiceRegistry.JavaService( role = AdditionalJaxbMappingProducer.class, impl = BasicContributorTests.Contributor.class ) +@BootstrapServiceRegistry( javaServices = @JavaService( + role = AdditionalMappingContributor.class, + impl = ContributorImpl.class ) ) -@ServiceRegistry( - settings = @Setting( - name = AvailableSettings.JPA_METAMODEL_POPULATION, - value = "ignoreUnsupported" - ) -) -@DomainModel( annotatedClasses = BasicContributorTests.MainEntity.class ) +@ServiceRegistry( settings = @Setting( + name = AvailableSettings.JPA_METAMODEL_POPULATION, + value = "ignoreUnsupported" +) ) +@DomainModel( annotatedClasses = MainEntity.class ) @SessionFactory public class EntityHidingTests { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/MainEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/MainEntity.java new file mode 100644 index 0000000000..c014d2caf8 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/MainEntity.java @@ -0,0 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.mapping.contributed; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +/** + * @author Steve Ebersole + */ +@Entity(name = "MainEntity") +@Table(name = "main_table") +class MainEntity { + @Id + private Integer id; + String name; + + private MainEntity() { + } + + public MainEntity(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/CustomTypeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/CustomTypeConverterTest.java index c4239fd87b..02a38e2350 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/CustomTypeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/custom/CustomTypeConverterTest.java @@ -6,31 +6,19 @@ */ package org.hibernate.orm.test.mapping.converted.converter.custom; -import java.util.List; - import org.hibernate.boot.MetadataSources; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributor; -import org.hibernate.boot.registry.BootstrapServiceRegistry; -import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuilderImplementor; -import org.hibernate.boot.spi.MetadataContributor; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.ServiceRegistry; -import org.hibernate.tool.schema.Action; import org.hibernate.type.spi.TypeConfiguration; -import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService; -import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService.JavaServiceDescriptor; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.util.ServiceRegistryUtil; -import org.junit.Test; - -import org.jboss.jandex.IndexView; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry.JavaService; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,31 +26,21 @@ import static org.hamcrest.MatcherAssert.assertThat; /** * @author Steve Ebersole */ -public class CustomTypeConverterTest extends BaseUnitTestCase { +public class CustomTypeConverterTest { + @Test - public void testConverterAppliedScopedRegistration() { - final List> services = List.of( - new JavaServiceDescriptor<>( - MetadataContributor.class, - PayloadWrapperMetadataContributor.class - ) - ); - final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().enableAutoClose() - .applyClassLoaderService( new ExtraJavaServicesClassLoaderService( services ) ) - .build(); - try (final StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder( bsr ) - .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) - .build() ) { - final MetadataSources metadataSources = new MetadataSources( ssr ) - .addAnnotatedClass( PayloadWrapperConverter.class ) - .addAnnotatedClass( MyEntity.class ); - final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder(); - - // now the new scoped way - final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration(); - - performAssertions( metadataBuilder, bootTypeConfiguration ); - } + @BootstrapServiceRegistry( javaServices = @JavaService( + role = TypeContributor.class, + impl = PayloadWrapperTypeContributorImpl.class + ) ) + @SuppressWarnings("JUnitMalformedDeclaration") + public void testConverterAppliedScopedContributions(ServiceRegistryScope registryScope) { + final MetadataSources metadataSources = new MetadataSources( registryScope.getRegistry() ) + .addAnnotatedClass( PayloadWrapperConverter.class ) + .addAnnotatedClass( MyEntity.class ); + final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder(); + final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration(); + performAssertions( metadataBuilder, bootTypeConfiguration ); } protected void performAssertions( @@ -89,41 +67,6 @@ public class CustomTypeConverterTest extends BaseUnitTestCase { } } - @Test - public void testConverterAppliedScopedContributions() { - final List> services = List.of( - new JavaServiceDescriptor<>( TypeContributor.class, PayloadWrapperTypeContributorImpl.class ) - ); - - final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().enableAutoClose() - .applyClassLoaderService( new ExtraJavaServicesClassLoaderService( services ) ) - .build(); - try ( final StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder( bsr ) - .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) - .build() ) { - final MetadataSources metadataSources = new MetadataSources( ssr ) - .addAnnotatedClass( PayloadWrapperConverter.class ) - .addAnnotatedClass( MyEntity.class ); - final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder(); - - // now the new scoped way - final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration(); - - performAssertions( metadataBuilder, bootTypeConfiguration ); - } - } - - public static class PayloadWrapperMetadataContributor implements MetadataContributor { - @Override - public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) { - final TypeConfiguration typeConfiguration = metadataCollector.getTypeConfiguration(); - typeConfiguration.getJavaTypeRegistry() - .addDescriptor( PayloadWrapperJavaType.INSTANCE ); - typeConfiguration.getJdbcTypeRegistry() - .addDescriptor( PayloadWrapperJdbcType.INSTANCE ); - } - } - public static class PayloadWrapperTypeContributorImpl implements TypeContributor { @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Author.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Author.java deleted file mode 100644 index 9dd80c5ce2..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Author.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.persister; - -import java.util.HashSet; -import java.util.Set; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; - -import org.hibernate.annotations.Persister; - - -/** - * @author Shawn Clowater - */ -//tag::entity-persister-mapping[] -@Entity -@Persister(impl = EntityPersister.class) -public class Author { - - @Id - public Integer id; - - @OneToMany(mappedBy = "author") - @Persister(impl = CollectionPersister.class) - public Set books = new HashSet<>(); - - //Getters and setters omitted for brevity - - //end::entity-persister-mapping[] - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Set getBooks() { - return books; - } - - //tag::entity-persister-mapping[] - public void addBook(Book book) { - this.books.add(book); - book.setAuthor(this); - } -} -//end::entity-persister-mapping[] diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Book.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Book.java deleted file mode 100644 index e20a7f357c..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/Book.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.persister; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; - -import org.hibernate.annotations.Persister; - -/** - * @author Shawn Clowater - */ -//tag::entity-persister-mapping[] - -@Entity -@Persister(impl = EntityPersister.class) -public class Book { - - @Id - public Integer id; - - private String title; - - @ManyToOne(fetch = FetchType.LAZY) - public Author author; - - //Getters and setters omitted for brevity - //end::entity-persister-mapping[] - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Author getAuthor() { - return author; - } - - public void setAuthor(Author author) { - this.author = author; - } -//tag::entity-persister-mapping[] -} -//end::entity-persister-mapping[] diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/CollectionPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/CollectionPersister.java deleted file mode 100644 index 44bcd02901..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/CollectionPersister.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.persister; - -import org.hibernate.MappingException; -import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.access.CollectionDataAccess; -import org.hibernate.mapping.Collection; -import org.hibernate.metamodel.spi.RuntimeModelCreationContext; -import org.hibernate.persister.collection.OneToManyPersister; - -/** - * @author Shawn Clowater - */ -//tag::entity-persister-mapping[] - -public class CollectionPersister - extends OneToManyPersister { - - public CollectionPersister( - Collection collectionBinding, - CollectionDataAccess cacheAccessStrategy, - RuntimeModelCreationContext creationContext) - throws MappingException, CacheException { - super(collectionBinding, cacheAccessStrategy, creationContext); - } -} -//end::entity-persister-mapping[] diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/EntityPersister.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/EntityPersister.java deleted file mode 100644 index 544e8f0864..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/EntityPersister.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.persister; - -import org.hibernate.HibernateException; -import org.hibernate.cache.spi.access.EntityDataAccess; -import org.hibernate.cache.spi.access.NaturalIdDataAccess; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.spi.RuntimeModelCreationContext; -import org.hibernate.persister.entity.SingleTableEntityPersister; - -/** - * @author Shawn Clowater - */ -//tag::entity-persister-mapping[] - -public class EntityPersister - extends SingleTableEntityPersister { - - public EntityPersister( - PersistentClass persistentClass, - EntityDataAccess cache, - NaturalIdDataAccess naturalIdRegionAccessStrategy, - RuntimeModelCreationContext creationContext) - throws HibernateException { - super(persistentClass, cache, naturalIdRegionAccessStrategy, creationContext); - } -} -//end::entity-persister-mapping[] - diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingIdentityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingIdentityTest.java index 81ef0b3968..1e022f6b6e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingIdentityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingIdentityTest.java @@ -2,20 +2,18 @@ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ package org.hibernate.orm.test.persister.entity; import org.hibernate.annotations.Loader; import org.hibernate.annotations.NamedNativeQuery; -import org.hibernate.annotations.Persister; import org.hibernate.annotations.ResultCheckStyle; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLInsert; import org.hibernate.annotations.SQLUpdate; import org.hibernate.dialect.H2Dialect; import org.hibernate.persister.entity.AbstractEntityPersister; -import org.hibernate.persister.entity.SingleTableEntityPersister; import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.testing.orm.junit.DomainModel; @@ -89,7 +87,6 @@ public class CustomSqlSchemaResolvingIdentityTest { } @Entity(name = "CardWithCustomSQL") - @Persister( impl = SingleTableEntityPersister.class ) @Loader(namedQuery = "find_foo_by_id") @NamedNativeQuery( name = "find_foo_by_id", diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingTest.java index b0c9804562..f0e54f3624 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/persister/entity/CustomSqlSchemaResolvingTest.java @@ -2,19 +2,17 @@ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ package org.hibernate.orm.test.persister.entity; import org.hibernate.annotations.Loader; import org.hibernate.annotations.NamedNativeQuery; -import org.hibernate.annotations.Persister; import org.hibernate.annotations.ResultCheckStyle; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLInsert; import org.hibernate.annotations.SQLUpdate; import org.hibernate.persister.entity.AbstractEntityPersister; -import org.hibernate.persister.entity.SingleTableEntityPersister; import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.testing.orm.junit.DomainModel; @@ -83,7 +81,6 @@ public class CustomSqlSchemaResolvingTest { } @Entity(name = "CardWithCustomSQL") - @Persister( impl = SingleTableEntityPersister.class ) @Loader(namedQuery = "find_foo_by_id") @NamedNativeQuery( name = "find_foo_by_id", diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java deleted file mode 100644 index a9f62688b6..0000000000 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalJaxbMappingProducerImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.envers.boot.internal; - -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -import org.hibernate.HibernateException; -import org.hibernate.boot.jaxb.Origin; -import org.hibernate.boot.jaxb.SourceType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; -import org.hibernate.boot.jaxb.internal.MappingBinder; -import org.hibernate.boot.model.source.internal.hbm.MappingDocument; -import org.hibernate.boot.spi.AdditionalJaxbMappingProducer; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.boot.spi.MetadataBuildingOptions; -import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.envers.boot.EnversBootLogger; -import org.hibernate.envers.configuration.internal.MappingCollector; -import org.hibernate.service.ServiceRegistry; - -import org.jboss.jandex.IndexView; -import org.jboss.logging.Logger; - -import static org.hibernate.cfg.AvailableSettings.XML_MAPPING_ENABLED; - -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; -import jakarta.xml.bind.Marshaller; - -/** - * @author Steve Ebersole - * @author Chris Cranford - */ -public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingProducer { - private static final Logger log = Logger.getLogger( AdditionalJaxbMappingProducerImpl.class ); - - @Override - public Collection produceAdditionalMappings( - final MetadataImplementor metadata, - IndexView jandexIndex, - final MappingBinder mappingBinder, - final MetadataBuildingContext buildingContext) { - MetadataBuildingOptions metadataBuildingOptions = metadata.getMetadataBuildingOptions(); - final ServiceRegistry serviceRegistry = metadataBuildingOptions.getServiceRegistry(); - final EnversService enversService = serviceRegistry.getService( EnversService.class ); - - if ( !enversService.isEnabled() ) { - // short-circuit if envers integration has been disabled. - return Collections.emptyList(); - } - - if ( !metadataBuildingOptions.isXmlMappingEnabled() ) { - throw new HibernateException( "Hibernate Envers currently requires XML mapping to be enabled." - + " Please don't disable setting `" + XML_MAPPING_ENABLED - + "`; alternatively disable Hibernate Envers." ); - } - - final ArrayList additionalMappingDocuments = new ArrayList<>(); - - // atm we do not have distinct origin info for envers - final Origin origin = new Origin( SourceType.OTHER, "envers" ); - - final MappingCollector mappingCollector = new MappingCollector() { - @Override - public void addDocument(JaxbHbmHibernateMapping mapping) { - log.infof( "Adding JAXB document mapping" ); - try { - JAXBContext context = JAXBContext.newInstance( JaxbHbmHibernateMapping.class ); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty ( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); - - StringWriter sw = new StringWriter(); - marshaller.marshal( mapping, sw ); - - EnversBootLogger.BOOT_LOGGER.jaxbContribution( sw.toString() ); - log.trace( "------------------------------------------------------------" ); - } - catch (JAXBException e) { - throw new RuntimeException( "Error dumping enhanced class", e ); - } - additionalMappingDocuments.add( new MappingDocument( "envers", mapping, origin, buildingContext ) ); - } - }; - - enversService.initialize( metadata, mappingCollector ); - - return additionalMappingDocuments; - } -} diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalMappingContributorImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalMappingContributorImpl.java index 01bdfdb356..dbf14c2697 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalMappingContributorImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/AdditionalMappingContributorImpl.java @@ -47,6 +47,6 @@ public class AdditionalMappingContributorImpl implements AdditionalMappingContri + "`; alternatively disable Hibernate Envers." ); } - enversService.initialize( metadata, contributions::contributeBinding ); + enversService.initialize( metadata, contributions::contributeBinding, contributions.getEffectiveMappingDefaults() ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversMetadataBuildingContextImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversMetadataBuildingContextImpl.java index a519560cfd..6d37a6f5c4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversMetadataBuildingContextImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversMetadataBuildingContextImpl.java @@ -10,8 +10,8 @@ import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.boot.model.TypeDefinitionRegistry; import org.hibernate.boot.model.naming.ObjectNameNormalizer; import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.EffectiveMappingDefaults; import org.hibernate.boot.spi.InFlightMetadataCollector; -import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.envers.boot.spi.EnversMetadataBuildingContext; @@ -30,6 +30,7 @@ public class EnversMetadataBuildingContextImpl implements EnversMetadataBuilding private final Configuration configuration; private final InFlightMetadataCollector metadataCollector; + private final EffectiveMappingDefaults effectiveMappingDefaults; private final MappingCollector mappingCollector; private final ObjectNameNormalizer objectNameNormalizer; private final AuditEntityNameRegister auditEntityNameRegistry; @@ -38,9 +39,11 @@ public class EnversMetadataBuildingContextImpl implements EnversMetadataBuilding public EnversMetadataBuildingContextImpl( Configuration configuration, InFlightMetadataCollector metadataCollector, + EffectiveMappingDefaults effectiveMappingDefaults, MappingCollector mappingCollector) { this.configuration = configuration; this.metadataCollector = metadataCollector; + this.effectiveMappingDefaults = effectiveMappingDefaults; this.mappingCollector = mappingCollector; this.auditEntityNameRegistry = new AuditEntityNameRegister(); this.auditEntityConfigurationRegistry = new AuditEntityConfigurationRegistry(); @@ -64,8 +67,8 @@ public class EnversMetadataBuildingContextImpl implements EnversMetadataBuilding } @Override - public MappingDefaults getEffectiveDefaults() { - return metadataCollector.getMetadataBuildingOptions().getMappingDefaults(); + public EffectiveMappingDefaults getEffectiveDefaults() { + return effectiveMappingDefaults; } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java index 8297edca5c..1bd8295fb7 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversService.java @@ -7,6 +7,7 @@ package org.hibernate.envers.boot.internal; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.EffectiveMappingDefaults; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.envers.configuration.Configuration; import org.hibernate.envers.configuration.internal.MappingCollector; @@ -53,7 +54,10 @@ public interface EnversService extends Service { */ boolean isInitialized(); - void initialize(MetadataImplementor metadata, MappingCollector mappingCollector); + void initialize( + MetadataImplementor metadata, + MappingCollector mappingCollector, + EffectiveMappingDefaults effectiveMappingDefaults); Configuration getConfig(); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java index 60fea845d9..ac81276b85 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/internal/EnversServiceImpl.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Properties; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.EffectiveMappingDefaults; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.config.spi.ConfigurationService; @@ -87,7 +88,10 @@ public class EnversServiceImpl implements EnversService, Configurable, Stoppable } @Override - public void initialize(MetadataImplementor metadata, MappingCollector mappingCollector) { + public void initialize( + MetadataImplementor metadata, + MappingCollector mappingCollector, + EffectiveMappingDefaults effectiveMappingDefaults) { if ( initialized ) { throw new UnsupportedOperationException( "EnversService#initialize should be called only once" ); } @@ -107,6 +111,7 @@ public class EnversServiceImpl implements EnversService, Configurable, Stoppable final EnversMetadataBuildingContext metadataBuildingContext = new EnversMetadataBuildingContextImpl( configuration, (InFlightMetadataCollector) metadata, + effectiveMappingDefaults, mappingCollector ); diff --git a/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 2c4bb2c28d..3776c747ef 100644 --- a/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/hibernate-envers/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -22,8 +22,8 @@ - - + + diff --git a/hibernate-envers/src/test/resources/log4j2.properties b/hibernate-envers/src/test/resources/log4j2.properties index 69566b404b..9cc13eb844 100644 --- a/hibernate-envers/src/test/resources/log4j2.properties +++ b/hibernate-envers/src/test/resources/log4j2.properties @@ -39,5 +39,5 @@ logger.jdbc-bind.level=trace logger.jdbc-extract.name=org.hibernate.orm.jdbc.extract logger.jdbc-extract.level=trace -logger.additional-jaxb-mapping-producer-impl.name=org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl -logger.additional-jaxb-mapping-producer-impl.level=trace +logger.envers-mappings-producer.name=org.hibernate.envers.boot.internal.AdditionalMappingContributorImpl +logger.envers-mappings-producer.level=trace diff --git a/migration-guide.adoc b/migration-guide.adoc index c076a529da..62f5f1074a 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -2,7 +2,7 @@ :toc: :toclevels: 4 :docsBase: https://docs.jboss.org/hibernate/orm -:versionDocBase: {docsBase}/6.4 +:versionDocBase: {docsBase}/7.0 :userGuideBase: {versionDocBase}/userguide/html_single/Hibernate_User_Guide.html :javadocsBase: {versionDocBase}/javadocs @@ -67,6 +67,8 @@ private Employee manager; == Some Cleanup * Removed `SqmQualifiedJoin`. All joins are qualified. +* Removed `AdditionalJaxbMappingProducer`, deprecated in favor of `AdditionalMappingContributor` +* Removed `MetadataContributor`, deprecated in favor of `AdditionalMappingContributor` [[todo]] @@ -74,7 +76,6 @@ private Employee manager; NOTE:: Look for `// todo (jpa 3.2)` -* Deprecate `SqmQualifiedJoin` in 6.x * {@linkplain SqmCrossJoin} and its offspring are largely de-typed to account for {@linkplain SqmCrossJoin} having only one type argument for the right-hand side. To properly handle the type parameters in the hierarchy we need to change this to