Merge remote-tracking branch 'upstream/main' into wip/6.0_merge
This commit is contained in:
commit
badc99705a
|
@ -51,12 +51,11 @@ public class BasicTypeCollectionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructAndConfigureConfiguration() {
|
||||
Configuration configuration = super.constructAndConfigureConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
|
||||
typeContributions.contributeType( new CommaDelimitedStringsType() );
|
||||
} );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
//tag::collections-comma-delimited-collection-example[]
|
||||
|
|
|
@ -32,14 +32,13 @@ public class BitSetTypeTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructAndConfigureConfiguration() {
|
||||
Configuration configuration = super.constructAndConfigureConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
//tag::basic-custom-type-register-BasicType-example[]
|
||||
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
|
||||
typeContributions.contributeType( BitSetType.INSTANCE );
|
||||
} );
|
||||
//end::basic-custom-type-register-BasicType-example[]
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -36,14 +36,13 @@ public class BitSetUserTypeTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructAndConfigureConfiguration() {
|
||||
Configuration configuration = super.constructAndConfigureConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
//tag::basic-custom-type-register-UserType-example[]
|
||||
configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> {
|
||||
typeContributions.contributeType( BitSetUserType.INSTANCE, "bitset");
|
||||
} );
|
||||
//end::basic-custom-type-register-UserType-example[]
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -202,6 +202,11 @@ xjc {
|
|||
xjcBinding = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
|
||||
xjcExtensions = ['inheritance', 'simplify']
|
||||
}
|
||||
mapping {
|
||||
xsd = file( 'src/main/resources/org/hibernate/jpa/orm_2_2.xsd' )
|
||||
xjcBinding = file( 'src/main/xjb/mapping-bindings.xjb' )
|
||||
xjcExtensions = ['inheritance']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -388,6 +388,18 @@ public class MetadataSources implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add XML mapping bindings created from an arbitrary source by the {@link #getXmlMappingBinderAccess() binder}.
|
||||
*
|
||||
* @param binding The binding.
|
||||
*
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public MetadataSources addXmlBinding(Binding<?> binding) {
|
||||
getXmlBindingsForWrite().add( binding );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link #addCacheableFile(java.io.File)} for description
|
||||
*
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.boot.spi.ClassLoaderAccess;
|
|||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenMetadataProvider;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
|
@ -319,7 +320,13 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
|
||||
private JavaReflectionManager generateHcannReflectionManager() {
|
||||
final JavaReflectionManager reflectionManager = new JavaReflectionManager();
|
||||
if ( metadataBuildingOptions.getXmlMappingOptions().isPreferJaxb() ) {
|
||||
reflectionManager.setMetadataProvider( new JPAXMLOverriddenMetadataProvider( this ) );
|
||||
}
|
||||
else {
|
||||
// Legacy implementation based on DOM4J, for backwards compatibility.
|
||||
reflectionManager.setMetadataProvider( new JPAMetadataProvider( this ) );
|
||||
}
|
||||
return reflectionManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
|||
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
||||
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
||||
import org.hibernate.boot.cfgxml.spi.MappingReference;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
|
@ -554,7 +555,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
private IdGeneratorInterpreterImpl idGenerationTypeInterpreter = new IdGeneratorInterpreterImpl();
|
||||
|
||||
private String schemaCharset;
|
||||
private boolean xmlMappingEnabled;
|
||||
private final XmlMappingOptions xmlMappingOptions;
|
||||
|
||||
public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
@ -566,11 +567,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
|
||||
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
|
||||
|
||||
this.xmlMappingEnabled = configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
xmlMappingOptions = XmlMappingOptions.get( serviceRegistry );
|
||||
|
||||
this.implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting(
|
||||
AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
|
||||
|
@ -843,8 +840,8 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isXmlMappingEnabled() {
|
||||
return xmlMappingEnabled;
|
||||
public XmlMappingOptions getXmlMappingOptions() {
|
||||
return xmlMappingOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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.boot.jaxb.internal;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
|
||||
public class DefaultXmlMappingOptions implements XmlMappingOptions {
|
||||
}
|
|
@ -20,7 +20,9 @@ import org.hibernate.boot.jaxb.Origin;
|
|||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||
import org.hibernate.boot.jaxb.internal.stax.HbmEventReader;
|
||||
import org.hibernate.boot.jaxb.internal.stax.JpaOrmXmlEventReader;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.xsd.MappingXsdSupport;
|
||||
import org.hibernate.internal.util.config.ConfigurationException;
|
||||
|
@ -39,15 +41,14 @@ public class MappingBinder extends AbstractBinder {
|
|||
|
||||
private final XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
|
||||
|
||||
private final XmlMappingOptions options;
|
||||
|
||||
private JAXBContext hbmJaxbContext;
|
||||
private JAXBContext entityMappingsJaxbContext;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public MappingBinder(ClassLoaderService classLoaderService) {
|
||||
this( classLoaderService, true );
|
||||
}
|
||||
|
||||
public MappingBinder(ClassLoaderService classLoaderService, boolean validateXml) {
|
||||
public MappingBinder(ClassLoaderService classLoaderService, boolean validateXml, XmlMappingOptions options) {
|
||||
super( classLoaderService, validateXml );
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,13 +67,21 @@ public class MappingBinder extends AbstractBinder {
|
|||
return new Binding<>( hbmBindings, origin );
|
||||
}
|
||||
else {
|
||||
// final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader );
|
||||
// return jaxb( reader, LocalSchema.MAPPING.getSchema(), JaxbEntityMappings.class, origin );
|
||||
|
||||
try {
|
||||
if ( options.isPreferJaxb() ) {
|
||||
log.debugf( "Performing JAXB binding of orm.xml document : %s", origin.toString() );
|
||||
|
||||
XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory );
|
||||
JaxbEntityMappings bindingRoot = jaxb( reader, MappingXsdSupport.INSTANCE.latestJpaDescriptor().getSchema(), entityMappingsJaxbContext(), origin );
|
||||
return new Binding<>( bindingRoot, origin );
|
||||
}
|
||||
else {
|
||||
log.debugf( "Performing DOM4J binding of orm.xml document : %s", origin.toString() );
|
||||
|
||||
final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory );
|
||||
return new Binding<>( toDom4jDocument( reader, origin ), origin );
|
||||
}
|
||||
}
|
||||
catch (JpaOrmXmlEventReader.BadVersionException e) {
|
||||
throw new UnsupportedOrmXsdVersionException( e.getRequestedVersion(), origin );
|
||||
}
|
||||
|
@ -91,6 +100,18 @@ public class MappingBinder extends AbstractBinder {
|
|||
return hbmJaxbContext;
|
||||
}
|
||||
|
||||
private JAXBContext entityMappingsJaxbContext() {
|
||||
if ( entityMappingsJaxbContext == null ) {
|
||||
try {
|
||||
entityMappingsJaxbContext = JAXBContext.newInstance( JaxbEntityMappings.class );
|
||||
}
|
||||
catch ( JAXBException e ) {
|
||||
throw new ConfigurationException( "Unable to build orm.xml JAXBContext", e );
|
||||
}
|
||||
}
|
||||
return entityMappingsJaxbContext;
|
||||
}
|
||||
|
||||
private Document toDom4jDocument(XMLEventReader jpaOrmXmlEventReader, Origin origin) {
|
||||
// todo : do we need to build a DocumentFactory instance for use here?
|
||||
// historically we did that to set TCCL since, iirc, dom4j uses TCCL
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.AccessType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA AccessType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class AccessTypeMarshalling {
|
||||
public static AccessType fromXml(String name) {
|
||||
return AccessType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(AccessType accessType) {
|
||||
return accessType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.ConstraintMode;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA ConstraintMode enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ConstraintModeMarshalling {
|
||||
public static ConstraintMode fromXml(String name) {
|
||||
return ConstraintMode.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(ConstraintMode accessType) {
|
||||
return accessType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.DiscriminatorType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA DiscriminatorType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DiscriminatorTypeMarshalling {
|
||||
public static DiscriminatorType fromXml(String name) {
|
||||
return DiscriminatorType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(DiscriminatorType discriminatorType) {
|
||||
return discriminatorType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.EnumType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA EnumType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EnumTypeMarshalling {
|
||||
public static EnumType fromXml(String name) {
|
||||
return EnumType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(EnumType enumType) {
|
||||
return enumType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA FetchType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class FetchTypeMarshalling {
|
||||
public static FetchType fromXml(String name) {
|
||||
return FetchType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(FetchType fetchType) {
|
||||
return fetchType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.GenerationType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA GenerationType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class GenerationTypeMarshalling {
|
||||
public static GenerationType fromXml(String name) {
|
||||
return GenerationType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(GenerationType accessType) {
|
||||
return accessType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA InheritanceType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class InheritanceTypeMarshalling {
|
||||
public static InheritanceType fromXml(String name) {
|
||||
return InheritanceType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(InheritanceType accessType) {
|
||||
return accessType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.LockModeType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA LockModeType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class LockModeTypeMarshalling {
|
||||
public static LockModeType fromXml(String name) {
|
||||
return LockModeType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(LockModeType lockModeType) {
|
||||
return lockModeType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.ParameterMode;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA ParameterMode enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ParameterModeMarshalling {
|
||||
public static ParameterMode fromXml(String name) {
|
||||
return ParameterMode.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(ParameterMode parameterMode) {
|
||||
return parameterMode.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.internal;
|
||||
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
* Marshalling support for dealing with JPA TemporalType enums. Plugged into JAXB for binding
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TemporalTypeMarshalling {
|
||||
public static TemporalType fromXml(String name) {
|
||||
return TemporalType.valueOf( name );
|
||||
}
|
||||
|
||||
public static String toXml(TemporalType temporalType) {
|
||||
return temporalType.name();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JAXB for JPA's {@code orm.xml} mapping schema.
|
||||
*/
|
||||
package org.hibernate.boot.jaxb.mapping;
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
public interface AssociationAttribute extends PersistentAttribute, FetchableAttribute {
|
||||
|
||||
JaxbJoinTable getJoinTable();
|
||||
|
||||
void setJoinTable(JaxbJoinTable value);
|
||||
|
||||
JaxbCascadeType getCascade();
|
||||
|
||||
void setCascade(JaxbCascadeType value);
|
||||
|
||||
String getTargetEntity();
|
||||
|
||||
void setTargetEntity(String value);
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings which are containers of attributes.
|
||||
*
|
||||
* @author Strong Liu
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributesContainer {
|
||||
|
||||
List<JaxbTransient> getTransient();
|
||||
|
||||
List<JaxbBasic> getBasic();
|
||||
|
||||
List<JaxbElementCollection> getElementCollection();
|
||||
|
||||
List<JaxbEmbedded> getEmbedded();
|
||||
|
||||
List<JaxbManyToMany> getManyToMany();
|
||||
|
||||
List<JaxbManyToOne> getManyToOne();
|
||||
|
||||
List<JaxbOneToMany> getOneToMany();
|
||||
|
||||
List<JaxbOneToOne> getOneToOne();
|
||||
|
||||
}
|
|
@ -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.boot.jaxb.mapping.spi;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/**
|
||||
* Common interface for Jaxb bindings that represent persistent collection attributes.
|
||||
*
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface CollectionAttribute extends FetchableAttribute {
|
||||
|
||||
String getOrderBy();
|
||||
|
||||
void setOrderBy(String value);
|
||||
|
||||
JaxbOrderColumn getOrderColumn();
|
||||
|
||||
void setOrderColumn(JaxbOrderColumn value);
|
||||
|
||||
JaxbMapKey getMapKey();
|
||||
|
||||
void setMapKey(JaxbMapKey value);
|
||||
|
||||
JaxbMapKeyClass getMapKeyClass();
|
||||
|
||||
void setMapKeyClass(JaxbMapKeyClass value);
|
||||
|
||||
TemporalType getMapKeyTemporal();
|
||||
|
||||
void setMapKeyTemporal(TemporalType value);
|
||||
|
||||
EnumType getMapKeyEnumerated();
|
||||
|
||||
void setMapKeyEnumerated(EnumType value);
|
||||
|
||||
List<JaxbAttributeOverride> getMapKeyAttributeOverride();
|
||||
|
||||
List<JaxbConvert> getMapKeyConvert();
|
||||
|
||||
JaxbMapKeyColumn getMapKeyColumn();
|
||||
|
||||
void setMapKeyColumn(JaxbMapKeyColumn value);
|
||||
|
||||
List<JaxbMapKeyJoinColumn> getMapKeyJoinColumn();
|
||||
|
||||
JaxbForeignKey getMapKeyForeignKey();
|
||||
|
||||
void setMapKeyForeignKey(JaxbForeignKey value);
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings representing entities and mapped-superclasses.
|
||||
*/
|
||||
public interface EntityOrMappedSuperclass extends ManagedType, LifecycleCallbackContainer {
|
||||
|
||||
JaxbIdClass getIdClass();
|
||||
|
||||
void setIdClass(JaxbIdClass value);
|
||||
|
||||
JaxbEmptyType getExcludeDefaultListeners();
|
||||
|
||||
void setExcludeDefaultListeners(JaxbEmptyType value);
|
||||
|
||||
JaxbEmptyType getExcludeSuperclassListeners();
|
||||
|
||||
void setExcludeSuperclassListeners(JaxbEmptyType value);
|
||||
|
||||
JaxbEntityListeners getEntityListeners();
|
||||
|
||||
void setEntityListeners(JaxbEntityListeners value);
|
||||
|
||||
JaxbPrePersist getPrePersist();
|
||||
|
||||
void setPrePersist(JaxbPrePersist value);
|
||||
|
||||
JaxbPostPersist getPostPersist();
|
||||
|
||||
void setPostPersist(JaxbPostPersist value);
|
||||
|
||||
JaxbPreRemove getPreRemove();
|
||||
|
||||
void setPreRemove(JaxbPreRemove value);
|
||||
|
||||
JaxbPostRemove getPostRemove();
|
||||
|
||||
void setPostRemove(JaxbPostRemove value);
|
||||
|
||||
JaxbPreUpdate getPreUpdate();
|
||||
|
||||
void setPreUpdate(JaxbPreUpdate value);
|
||||
|
||||
JaxbPostUpdate getPostUpdate();
|
||||
|
||||
void setPostUpdate(JaxbPostUpdate value);
|
||||
|
||||
JaxbPostLoad getPostLoad();
|
||||
|
||||
void setPostLoad(JaxbPostLoad value);
|
||||
|
||||
JaxbAttributes getAttributes();
|
||||
|
||||
void setAttributes(JaxbAttributes value);
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings that represent attributes with laziness and fetch style.
|
||||
*
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public interface FetchableAttribute {
|
||||
|
||||
FetchType getFetch();
|
||||
|
||||
void setFetch(FetchType value);
|
||||
|
||||
}
|
|
@ -0,0 +1,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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.boot.jaxb.mapping.spi;
|
||||
|
||||
/**
|
||||
* Common interface for all the JAXB bindings representing lifecycle callbacks.
|
||||
*
|
||||
* @author Strong Liu
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface LifecycleCallback {
|
||||
String getMethodName();
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
public interface LifecycleCallbackContainer {
|
||||
String getDescription();
|
||||
|
||||
void setDescription(String value);
|
||||
|
||||
JaxbPrePersist getPrePersist();
|
||||
|
||||
void setPrePersist(JaxbPrePersist value);
|
||||
|
||||
JaxbPostPersist getPostPersist();
|
||||
|
||||
void setPostPersist(JaxbPostPersist value);
|
||||
|
||||
JaxbPreRemove getPreRemove();
|
||||
|
||||
void setPreRemove(JaxbPreRemove value);
|
||||
|
||||
JaxbPostRemove getPostRemove();
|
||||
|
||||
void setPostRemove(JaxbPostRemove value);
|
||||
|
||||
JaxbPreUpdate getPreUpdate();
|
||||
|
||||
void setPreUpdate(JaxbPreUpdate value);
|
||||
|
||||
JaxbPostUpdate getPostUpdate();
|
||||
|
||||
void setPostUpdate(JaxbPostUpdate value);
|
||||
|
||||
JaxbPostLoad getPostLoad();
|
||||
|
||||
void setPostLoad(JaxbPostLoad value);
|
||||
|
||||
String getClazz();
|
||||
|
||||
void setClazz(String value);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
import javax.persistence.AccessType;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings representing entities, mapped-superclasses and embeddables (JPA collective
|
||||
* calls these "managed types" in terms of its Metamodel api).
|
||||
*
|
||||
* @author Strong Liu
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ManagedType {
|
||||
|
||||
String getDescription();
|
||||
|
||||
void setDescription(String value);
|
||||
|
||||
String getClazz();
|
||||
|
||||
void setClazz(String className);
|
||||
|
||||
Boolean isMetadataComplete();
|
||||
|
||||
void setMetadataComplete(Boolean isMetadataComplete);
|
||||
|
||||
AccessType getAccess();
|
||||
|
||||
void setAccess(AccessType value);
|
||||
|
||||
AttributesContainer getAttributes();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import javax.persistence.LockModeType;
|
||||
|
||||
public interface NamedQuery extends Serializable {
|
||||
String getDescription();
|
||||
|
||||
void setDescription(String value);
|
||||
|
||||
String getQuery();
|
||||
|
||||
void setQuery(String value);
|
||||
|
||||
LockModeType getLockMode();
|
||||
|
||||
void setLockMode(LockModeType value);
|
||||
|
||||
List<JaxbQueryHint> getHint();
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String value);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
import javax.persistence.AccessType;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings that represent persistent attributes.
|
||||
*
|
||||
* @author Strong Liu
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PersistentAttribute {
|
||||
String getName();
|
||||
|
||||
AccessType getAccess();
|
||||
|
||||
void setAccess(AccessType accessType);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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.boot.jaxb.mapping.spi;
|
||||
|
||||
/**
|
||||
* Common interface for JAXB bindings that understand database schema (tables, sequences, etc).
|
||||
*
|
||||
* @author Strong Liu
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SchemaAware {
|
||||
String getSchema();
|
||||
|
||||
void setSchema(String schema);
|
||||
|
||||
String getCatalog();
|
||||
|
||||
void setCatalog(String catalog);
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.boot.jaxb.spi;
|
||||
|
||||
import org.hibernate.boot.jaxb.internal.DefaultXmlMappingOptions;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* The options of XML mapping.
|
||||
* <p>
|
||||
* We're using an interface instead of simply configuration properties,
|
||||
* so that we can override the options easily in integrations (Quarkus)
|
||||
* and tests (to run the tests multiple times with different options).
|
||||
*/
|
||||
public interface XmlMappingOptions {
|
||||
|
||||
String DEFAULT_NAME = "default";
|
||||
|
||||
static XmlMappingOptions get(ServiceRegistry serviceRegistry) {
|
||||
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||
|
||||
// The config service may be null if we're using a BootstrapServiceRegistry,
|
||||
// since configuration properties are unknown at that point.
|
||||
// That can happen with MetadataSources in particular,
|
||||
// because for some reason we allow MetadataSources to be built before the StandardServiceRegistry
|
||||
// (and Quarkus relies on that).
|
||||
// That's why we prefer to rely on strategies (see below):
|
||||
// they can be customized without relying on configuration properties
|
||||
// through the service loader.
|
||||
boolean xmlMappingEnabled = configService == null || configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
|
||||
XmlMappingOptions result;
|
||||
if ( !xmlMappingEnabled ) {
|
||||
result = new XmlMappingOptions() {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
|
||||
result = strategySelector.resolveDefaultableStrategy(
|
||||
XmlMappingOptions.class,
|
||||
XmlMappingOptions.DEFAULT_NAME,
|
||||
new DefaultXmlMappingOptions()
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to skip processing of XML Mapping.
|
||||
* This is for people using exclusively annotations to define their model, and might
|
||||
* be able to improve efficiency of booting Hibernate ORM.
|
||||
* By default, the XML mapping is taken into account.
|
||||
*/
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to prefer JAXB implementations for XML parsing,
|
||||
* or to rely on legacy behavior (JAXB for hbm.xml, DOM4J for orm.xml and Envers).
|
||||
* <p>
|
||||
* This option will be removed in a future major version (probably ORM 6.0)
|
||||
* where JAXB will always be used.
|
||||
*/
|
||||
default boolean isPreferJaxb() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.hibernate.boot.MetadataSources;
|
|||
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
|
||||
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
||||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
import org.hibernate.boot.model.process.internal.ManagedResourcesImpl;
|
||||
|
@ -32,11 +33,8 @@ import org.hibernate.boot.spi.BootstrapContext;
|
|||
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;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.BasicTypeRegistry;
|
||||
|
@ -97,16 +95,11 @@ public class MetadataBuildingProcess {
|
|||
final MetadataSources sources,
|
||||
final BootstrapContext bootstrapContext) {
|
||||
final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext );
|
||||
final ConfigurationService configService = bootstrapContext.getServiceRegistry().getService( ConfigurationService.class );
|
||||
final boolean xmlMappingEnabled = configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
XmlMappingOptions xmlMappingOptions = XmlMappingOptions.get( bootstrapContext.getServiceRegistry() );
|
||||
ScanningCoordinator.INSTANCE.coordinateScan(
|
||||
managedResources,
|
||||
bootstrapContext,
|
||||
xmlMappingEnabled ? sources.getXmlMappingBinderAccess() : null
|
||||
xmlMappingOptions.isEnabled() ? sources.getXmlMappingBinderAccess() : null
|
||||
);
|
||||
return managedResources;
|
||||
}
|
||||
|
@ -153,7 +146,7 @@ public class MetadataBuildingProcess {
|
|||
|
||||
final MetadataSourceProcessor processor = new MetadataSourceProcessor() {
|
||||
private final MetadataSourceProcessor hbmProcessor =
|
||||
options.isXmlMappingEnabled()
|
||||
options.getXmlMappingOptions().isEnabled()
|
||||
? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext )
|
||||
: new NoOpMetadataSourceProcessorImpl();
|
||||
|
||||
|
@ -290,13 +283,14 @@ public class MetadataBuildingProcess {
|
|||
|
||||
metadataCollector.processSecondPasses( rootMetadataBuildingContext );
|
||||
|
||||
if ( options.isXmlMappingEnabled() ) {
|
||||
final XmlMappingOptions xmlMappingOptions = options.getXmlMappingOptions();
|
||||
if ( xmlMappingOptions.isEnabled() ) {
|
||||
final Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class );
|
||||
if ( producers != null ) {
|
||||
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
|
||||
// final MappingBinder mappingBinder = new MappingBinder( true );
|
||||
// We need to disable validation here. It seems Envers is not producing valid (according to schema) XML
|
||||
final MappingBinder mappingBinder = new MappingBinder( classLoaderService, false );
|
||||
final MappingBinder mappingBinder = new MappingBinder( classLoaderService, false, xmlMappingOptions );
|
||||
for ( AdditionalJaxbMappingProducer producer : producers ) {
|
||||
log.tracef( "Calling AdditionalJaxbMappingProducer : %s", producer );
|
||||
Collection<MappingDocument> additionalMappings = producer.produceAdditionalMappings(
|
||||
|
|
|
@ -22,17 +22,21 @@ import org.hibernate.annotations.common.reflection.ReflectionManager;
|
|||
import org.hibernate.annotations.common.reflection.XClass;
|
||||
import org.hibernate.boot.AttributeConverterInfo;
|
||||
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
|
||||
import org.hibernate.boot.model.process.spi.ManagedResources;
|
||||
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware;
|
||||
import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware.JpaOrmXmlPersistenceUnitDefaults;
|
||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.cfg.AnnotationBinder;
|
||||
import org.hibernate.cfg.InheritanceState;
|
||||
import org.hibernate.cfg.annotations.reflection.AttributeConverterDefinitionCollector;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenMetadataProvider;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
|
@ -75,21 +79,32 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
|||
final AttributeConverterManager attributeConverterManager = new AttributeConverterManager( rootMetadataBuildingContext );
|
||||
this.classLoaderService = rootMetadataBuildingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
|
||||
|
||||
if ( rootMetadataBuildingContext.getBuildingOptions().isXmlMappingEnabled() ) {
|
||||
|
||||
MetadataBuildingOptions metadataBuildingOptions = rootMetadataBuildingContext.getBuildingOptions();
|
||||
XmlMappingOptions xmlMappingOptions = metadataBuildingOptions.getXmlMappingOptions();
|
||||
if ( xmlMappingOptions.isEnabled() ) {
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Ewww. This is temporary until we migrate to Jandex + StAX for annotation binding
|
||||
if ( xmlMappingOptions.isPreferJaxb() ) {
|
||||
final JPAXMLOverriddenMetadataProvider jpaMetadataProvider = (JPAXMLOverriddenMetadataProvider) ( (MetadataProviderInjector) reflectionManager )
|
||||
.getMetadataProvider();
|
||||
for ( Binding<?> xmlBinding : managedResources.getXmlMappingBindings() ) {
|
||||
Object root = xmlBinding.getRoot();
|
||||
if ( !(root instanceof JaxbEntityMappings) ) {
|
||||
continue;
|
||||
}
|
||||
JaxbEntityMappings entityMappings = (JaxbEntityMappings) xmlBinding.getRoot();
|
||||
|
||||
final List<String> classNames = jpaMetadataProvider.getXMLContext().addDocument( entityMappings );
|
||||
for ( String className : classNames ) {
|
||||
xClasses.add( toXClass( className, reflectionManager, classLoaderService ) );
|
||||
}
|
||||
}
|
||||
jpaMetadataProvider.getXMLContext().applyDiscoveredAttributeConverters( attributeConverterManager );
|
||||
}
|
||||
else {
|
||||
final JPAMetadataProvider jpaMetadataProvider = (JPAMetadataProvider) ( (MetadataProviderInjector) reflectionManager )
|
||||
.getMetadataProvider();
|
||||
for ( Binding xmlBinding : managedResources.getXmlMappingBindings() ) {
|
||||
// if ( !MappingBinder.DelayedOrmXmlData.class.isInstance( xmlBinding.getRoot() ) ) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // convert the StAX representation in delayedOrmXmlData to DOM because that's what commons-annotations needs
|
||||
// final MappingBinder.DelayedOrmXmlData delayedOrmXmlData = (MappingBinder.DelayedOrmXmlData) xmlBinding.getRoot();
|
||||
// org.dom4j.Document dom4jDocument = toDom4jDocument( delayedOrmXmlData );
|
||||
if ( !org.dom4j.Document.class.isInstance( xmlBinding.getRoot() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -101,6 +116,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
|||
}
|
||||
}
|
||||
jpaMetadataProvider.getXMLContext().applyDiscoveredAttributeConverters( attributeConverterManager );
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
}
|
||||
|
||||
|
@ -138,22 +154,6 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
|||
return reflectionManager.toXClass( cls.classForName( className ) );
|
||||
}
|
||||
|
||||
// private Document toDom4jDocument(MappingBinder.DelayedOrmXmlData delayedOrmXmlData) {
|
||||
// // todo : do we need to build a DocumentFactory instance for use here?
|
||||
// // historically we did that to set TCCL since, iirc, dom4j uses TCCL
|
||||
// org.dom4j.io.STAXEventReader staxToDom4jReader = new STAXEventReader();
|
||||
// try {
|
||||
// return staxToDom4jReader.readDocument( delayedOrmXmlData.getStaxEventReader() );
|
||||
// }
|
||||
// catch (XMLStreamException e) {
|
||||
// throw new MappingException(
|
||||
// "An error occurred transforming orm.xml document from StAX to dom4j representation ",
|
||||
// e,
|
||||
// delayedOrmXmlData.getOrigin()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
// use any persistence-unit-defaults defined in orm.xml
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.boot.registry.selector.internal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.jaxb.internal.DefaultXmlMappingOptions;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
|
||||
|
@ -103,6 +105,8 @@ public class StrategySelectorBuilder {
|
|||
addSqmMultiTableMutationStrategies( strategySelector );
|
||||
addImplicitNamingStrategies( strategySelector );
|
||||
addCacheKeysFactories( strategySelector );
|
||||
strategySelector.registerStrategyImplementor( XmlMappingOptions.class, XmlMappingOptions.DEFAULT_NAME,
|
||||
DefaultXmlMappingOptions.class );
|
||||
|
||||
// apply auto-discovered registrations
|
||||
for ( StrategyRegistrationProvider provider : classLoaderService.loadJavaServices( StrategyRegistrationProvider.class ) ) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.hibernate.boot.CacheRegionDefinition;
|
|||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
||||
|
@ -184,8 +185,8 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isXmlMappingEnabled() {
|
||||
return delegate.isXmlMappingEnabled();
|
||||
public XmlMappingOptions getXmlMappingOptions() {
|
||||
return delegate.getXmlMappingOptions();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.boot.CacheRegionDefinition;
|
|||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
||||
|
@ -260,7 +261,7 @@ public interface MetadataBuildingOptions {
|
|||
return null;
|
||||
}
|
||||
|
||||
default boolean isXmlMappingEnabled() {
|
||||
return true;
|
||||
default XmlMappingOptions getXmlMappingOptions() {
|
||||
return XmlMappingOptions.get( getServiceRegistry() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,11 @@ import org.hibernate.boot.jaxb.internal.InputStreamXmlSource;
|
|||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.internal.UrlXmlSource;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -37,10 +41,12 @@ public class XmlMappingBinderAccess {
|
|||
public XmlMappingBinderAccess(ServiceRegistry serviceRegistry) {
|
||||
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||
|
||||
XmlMappingOptions xmlMappingOptions = XmlMappingOptions.get( serviceRegistry );
|
||||
|
||||
// NOTE : The boolean here indicates whether or not to perform validation as we load XML documents.
|
||||
// Should we expose this setting? Disabling would speed up JAXP and JAXB at runtime, but potentially
|
||||
// at the cost of less obvious errors when a document is not valid.
|
||||
this.mappingBinder = new MappingBinder( serviceRegistry.getService( ClassLoaderService.class ), true );
|
||||
this.mappingBinder = new MappingBinder( classLoaderService, true, xmlMappingOptions );
|
||||
}
|
||||
|
||||
public MappingBinder getMappingBinder() {
|
||||
|
|
|
@ -35,13 +35,13 @@ public class MappingXsdSupport {
|
|||
private final XsdDescriptor jpa21 = LocalXsdResolver.buildXsdDescriptor(
|
||||
"org/hibernate/jpa/orm_2_1.xsd",
|
||||
"2.1",
|
||||
"http://xmlns.jcp.org/xml/ns/persistence"
|
||||
"http://xmlns.jcp.org/xml/ns/persistence/orm"
|
||||
);
|
||||
|
||||
private final XsdDescriptor jpa22 = LocalXsdResolver.buildXsdDescriptor(
|
||||
"org/hibernate/jpa/orm_2_2.xsd",
|
||||
"2.2",
|
||||
"http://xmlns.jcp.org/xml/ns/persistence"
|
||||
"http://xmlns.jcp.org/xml/ns/persistence/orm"
|
||||
);
|
||||
|
||||
private final XsdDescriptor jpa30 = LocalXsdResolver.buildXsdDescriptor(
|
||||
|
|
|
@ -741,7 +741,6 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
|||
*/
|
||||
String XML_MAPPING_ENABLED = "hibernate.xml_mapping_enabled";
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// SessionFactoryBuilder level settings
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.boot.MetadataBuilder;
|
|||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.boot.internal.ClassmateContext;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
|
||||
import org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor;
|
||||
|
@ -47,6 +48,7 @@ import org.hibernate.boot.query.NamedHqlQueryDefinition;
|
|||
import org.hibernate.boot.query.NamedNativeQueryDefinition;
|
||||
import org.hibernate.boot.query.NamedProcedureCallDefinition;
|
||||
import org.hibernate.boot.query.NamedResultSetMappingDescriptor;
|
||||
import org.hibernate.boot.spi.XmlMappingBinderAccess;
|
||||
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
|
||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
@ -372,6 +374,13 @@ public class Configuration {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An object capable of parsing XML mapping files that can then be passed to {@link #addXmlMapping(Binding)}.
|
||||
*/
|
||||
public XmlMappingBinderAccess getXmlMappingBinderAccess() {
|
||||
return metadataSources.getXmlMappingBinderAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No longer supported.
|
||||
*/
|
||||
|
@ -379,6 +388,17 @@ public class Configuration {
|
|||
public void add(XmlDocument metadataXml) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read mappings that were parsed using {@link #getXmlMappingBinderAccess()}.
|
||||
*
|
||||
* @param binding the parsed mapping
|
||||
* @return this (for method chaining purposes)
|
||||
*/
|
||||
public Configuration addXmlMapping(Binding<?> binding) {
|
||||
metadataSources.addXmlBinding( binding );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cached mapping file. A cached file is a serialized representation
|
||||
* of the DOM structure of a particular mapping. It is saved from a previous
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.boot.spi.ClassLoaderAccess;
|
|||
import org.hibernate.boot.spi.ClassLoaderAccessDelegateImpl;
|
||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenMetadataProvider;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
|
@ -38,7 +39,13 @@ import org.dom4j.Element;
|
|||
* MetadataProvider aware of the JPA Deployment descriptor
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*
|
||||
* @deprecated This class is not API: do not use it from application code.
|
||||
* This class will be removed in Hibernate ORM 6.0.
|
||||
* For implementation code, use {@link JPAXMLOverriddenMetadataProvider}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class JPAMetadataProvider implements MetadataProvider {
|
||||
|
||||
|
@ -75,12 +82,12 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
return delegate;
|
||||
}
|
||||
},
|
||||
metadataBuildingOptions.isXmlMappingEnabled() );
|
||||
metadataBuildingOptions.getXmlMappingOptions().isEnabled() );
|
||||
}
|
||||
|
||||
public JPAMetadataProvider(BootstrapContext bootstrapContext) {
|
||||
this( bootstrapContext.getClassLoaderAccess(),
|
||||
bootstrapContext.getMetadataBuildingOptions().isXmlMappingEnabled() );
|
||||
bootstrapContext.getMetadataBuildingOptions().getXmlMappingOptions().isEnabled() );
|
||||
}
|
||||
|
||||
JPAMetadataProvider(ClassLoaderAccess classLoaderAccess, boolean xmlMetadataEnabled) {
|
||||
|
@ -148,7 +155,8 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
defaults.put( SequenceGenerator.class, sequenceGenerators );
|
||||
}
|
||||
for ( Element subelement : elements ) {
|
||||
sequenceGenerators.add( JPAOverriddenAnnotationReader.buildSequenceGeneratorAnnotation( subelement ) );
|
||||
sequenceGenerators.add( JPAOverriddenAnnotationReader
|
||||
.buildSequenceGeneratorAnnotation( subelement ) );
|
||||
}
|
||||
|
||||
elements = element.elements( "table-generator" );
|
||||
|
@ -170,7 +178,8 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
namedQueries = new ArrayList<>();
|
||||
defaults.put( NamedQuery.class, namedQueries );
|
||||
}
|
||||
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader.buildNamedQueries(
|
||||
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader
|
||||
.buildNamedQueries(
|
||||
element,
|
||||
false,
|
||||
xmlDefaults,
|
||||
|
@ -183,7 +192,8 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
namedNativeQueries = new ArrayList<>();
|
||||
defaults.put( NamedNativeQuery.class, namedNativeQueries );
|
||||
}
|
||||
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader.buildNamedQueries(
|
||||
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader
|
||||
.buildNamedQueries(
|
||||
element,
|
||||
true,
|
||||
xmlDefaults,
|
||||
|
@ -198,7 +208,8 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
sqlResultSetMappings = new ArrayList<>();
|
||||
defaults.put( SqlResultSetMapping.class, sqlResultSetMappings );
|
||||
}
|
||||
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader.buildSqlResultsetMappings(
|
||||
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader
|
||||
.buildSqlResultsetMappings(
|
||||
element,
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
|
@ -210,7 +221,8 @@ public final class JPAMetadataProvider implements MetadataProvider {
|
|||
namedStoredProcedureQueries = new ArrayList<>( );
|
||||
defaults.put( NamedStoredProcedureQuery.class, namedStoredProcedureQueries );
|
||||
}
|
||||
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader.buildNamedStoreProcedureQueries(
|
||||
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader
|
||||
.buildNamedStoreProcedureQueries(
|
||||
element,
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
|
|
|
@ -126,6 +126,7 @@ import org.hibernate.annotations.common.reflection.ReflectionUtil;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -141,7 +142,13 @@ import org.dom4j.Element;
|
|||
* @author Davide Marchignoli
|
||||
* @author Emmanuel Bernard
|
||||
* @author Hardy Ferentschik
|
||||
*
|
||||
* @deprecated This class is not API: do not use it from application code.
|
||||
* This class will be removed in Hibernate ORM 6.0.
|
||||
* For implementation code, use {@link JPAXMLOverriddenAnnotationReader}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JPAOverriddenAnnotationReader.class );
|
||||
|
@ -239,12 +246,12 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
annotationToXml.put( ConstructorResult.class, "constructor-result" );
|
||||
}
|
||||
|
||||
private XMLContext xmlContext;
|
||||
private final XMLContext xmlContext;
|
||||
private final ClassLoaderAccess classLoaderAccess;
|
||||
private final AnnotatedElement element;
|
||||
private String className;
|
||||
private String propertyName;
|
||||
private PropertyType propertyType;
|
||||
private final String className;
|
||||
private final String propertyName;
|
||||
private final PropertyType propertyType;
|
||||
private transient Annotation[] annotations;
|
||||
private transient Map<Class, Annotation> annotationsMap;
|
||||
private transient List<Element> elementsForProperty;
|
||||
|
@ -264,6 +271,8 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
if ( el instanceof Class ) {
|
||||
Class clazz = (Class) el;
|
||||
className = clazz.getName();
|
||||
propertyName = null;
|
||||
propertyType = null;
|
||||
}
|
||||
else if ( el instanceof Field ) {
|
||||
Field field = (Field) el;
|
||||
|
@ -283,18 +292,18 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
else if ( el instanceof Method ) {
|
||||
Method method = (Method) el;
|
||||
className = method.getDeclaringClass().getName();
|
||||
propertyName = method.getName();
|
||||
String methodName = method.getName();
|
||||
|
||||
// YUCK! The null here is the 'boundType', we'd rather get the TypeEnvironment()
|
||||
if ( ReflectionUtil.isProperty( method, null, PersistentAttributeFilter.INSTANCE ) ) {
|
||||
if ( propertyName.startsWith( "get" ) ) {
|
||||
propertyName = Introspector.decapitalize( propertyName.substring( "get".length() ) );
|
||||
if ( methodName.startsWith( "get" ) ) {
|
||||
propertyName = Introspector.decapitalize( methodName.substring( "get".length() ) );
|
||||
}
|
||||
else if ( propertyName.startsWith( "is" ) ) {
|
||||
propertyName = Introspector.decapitalize( propertyName.substring( "is".length() ) );
|
||||
else if ( methodName.startsWith( "is" ) ) {
|
||||
propertyName = Introspector.decapitalize( methodName.substring( "is".length() ) );
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException( "Method " + propertyName + " is not a property getter" );
|
||||
throw new RuntimeException( "Method " + methodName + " is not a property getter" );
|
||||
}
|
||||
propertyType = PropertyType.PROPERTY;
|
||||
try {
|
||||
|
@ -305,12 +314,14 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
}
|
||||
}
|
||||
else {
|
||||
propertyName = methodName;
|
||||
propertyType = PropertyType.METHOD;
|
||||
}
|
||||
}
|
||||
else {
|
||||
className = null;
|
||||
propertyName = null;
|
||||
propertyType = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -881,7 +892,7 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
* field or property. Thus, any methods which might in some contexts merge
|
||||
* with annotations must not do so in this context.
|
||||
*
|
||||
* @see #getElementCollection(List, org.hibernate.cfg.annotations.reflection.XMLContext.Default)
|
||||
* @see #getElementCollection(List, XMLContext.Default)
|
||||
*/
|
||||
private void getAssociation(
|
||||
Class<? extends Annotation> annotationType, List<Annotation> annotationList, XMLContext.Default defaults
|
||||
|
@ -2690,7 +2701,8 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
|||
AnnotationDescriptor ad = new AnnotationDescriptor( IdClass.class );
|
||||
Class clazz;
|
||||
try {
|
||||
clazz = classLoaderAccess.classForName( XMLContext.buildSafeClassName( attr.getValue(), defaults )
|
||||
clazz = classLoaderAccess.classForName( XMLContext
|
||||
.buildSafeClassName( attr.getValue(), defaults )
|
||||
);
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
|
|
|
@ -32,7 +32,12 @@ import org.dom4j.Element;
|
|||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Brett Meyer
|
||||
*
|
||||
* @deprecated This class is not API: do not use it from application code.
|
||||
* This class will be removed in Hibernate ORM 6.0.
|
||||
* For implementation code, use {@link org.hibernate.cfg.annotations.reflection.internal.XMLContext} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class XMLContext implements Serializable {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( XMLContext.class );
|
||||
|
||||
|
@ -222,7 +227,7 @@ public class XMLContext implements Serializable {
|
|||
return className;
|
||||
}
|
||||
|
||||
public static String buildSafeClassName(String className, XMLContext.Default defaults) {
|
||||
public static String buildSafeClassName(String className, Default defaults) {
|
||||
return buildSafeClassName( className, defaults.getPackageName() );
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,198 @@
|
|||
/*
|
||||
* 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.cfg.annotations.reflection.internal;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.NamedNativeQuery;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.NamedStoredProcedureQuery;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.SqlResultSetMapping;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.annotations.common.reflection.AnnotationReader;
|
||||
import org.hibernate.annotations.common.reflection.MetadataProvider;
|
||||
import org.hibernate.annotations.common.reflection.java.JavaMetadataProvider;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGenerator;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbTableGenerator;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||
|
||||
/**
|
||||
* MetadataProvider aware of the JPA Deployment descriptor (orm.xml, ...).
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider {
|
||||
|
||||
private static final MetadataProvider STATELESS_BASE_DELEGATE = new JavaMetadataProvider();
|
||||
|
||||
private final ClassLoaderAccess classLoaderAccess;
|
||||
private final XMLContext xmlContext;
|
||||
|
||||
/**
|
||||
* We allow fully disabling XML sources so to improve the efficiency of
|
||||
* the boot process for those not using it.
|
||||
*/
|
||||
private final XmlMappingOptions xmlMappingOptions;
|
||||
|
||||
private Map<Object, Object> defaults;
|
||||
private Map<AnnotatedElement, AnnotationReader> cache;
|
||||
|
||||
public JPAXMLOverriddenMetadataProvider(BootstrapContext bootstrapContext) {
|
||||
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
||||
this.xmlContext = new XMLContext( classLoaderAccess );
|
||||
this.xmlMappingOptions = bootstrapContext.getMetadataBuildingOptions().getXmlMappingOptions();
|
||||
}
|
||||
|
||||
//all of the above can be safely rebuilt from XMLContext: only XMLContext this object is serialized
|
||||
@Override
|
||||
public AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement) {
|
||||
if ( cache == null ) {
|
||||
cache = new HashMap<>(50 );
|
||||
}
|
||||
AnnotationReader reader = cache.get( annotatedElement );
|
||||
if (reader == null) {
|
||||
if ( xmlContext.hasContext() ) {
|
||||
reader = new JPAXMLOverriddenAnnotationReader( annotatedElement, xmlContext, classLoaderAccess );
|
||||
}
|
||||
else {
|
||||
reader = STATELESS_BASE_DELEGATE.getAnnotationReader( annotatedElement );
|
||||
}
|
||||
cache.put( annotatedElement, reader );
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// FIXME this method was introduced in HCANN 5.1.1: we can't mark it as @Override yet,
|
||||
// but it's expected to be invoked when we're running with the right HCANN version.
|
||||
public void reset() {
|
||||
//It's better to remove the HashMap, as it could grow rather large:
|
||||
//when doing a clear() the internal buckets array is not scaled down.
|
||||
this.cache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> getDefaults() {
|
||||
if ( !xmlMappingOptions.isEnabled() ) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
else {
|
||||
if ( defaults == null ) {
|
||||
defaults = new HashMap<>();
|
||||
XMLContext.Default xmlDefaults = xmlContext.getDefault( null );
|
||||
|
||||
defaults.put( "schema", xmlDefaults.getSchema() );
|
||||
defaults.put( "catalog", xmlDefaults.getCatalog() );
|
||||
defaults.put( "delimited-identifier", xmlDefaults.getDelimitedIdentifier() );
|
||||
defaults.put( "cascade-persist", xmlDefaults.getCascadePersist() );
|
||||
List<Class> entityListeners = new ArrayList<Class>();
|
||||
for ( String className : xmlContext.getDefaultEntityListeners() ) {
|
||||
try {
|
||||
entityListeners.add( classLoaderAccess.classForName( className ) );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
throw new IllegalStateException( "Default entity listener class not found: " + className );
|
||||
}
|
||||
}
|
||||
defaults.put( EntityListeners.class, entityListeners );
|
||||
for ( JaxbEntityMappings entityMappings : xmlContext.getAllDocuments() ) {
|
||||
List<JaxbSequenceGenerator> jaxbSequenceGenerators = entityMappings.getSequenceGenerator();
|
||||
List<SequenceGenerator> sequenceGenerators = ( List<SequenceGenerator> ) defaults.get( SequenceGenerator.class );
|
||||
if ( sequenceGenerators == null ) {
|
||||
sequenceGenerators = new ArrayList<>();
|
||||
defaults.put( SequenceGenerator.class, sequenceGenerators );
|
||||
}
|
||||
for ( JaxbSequenceGenerator element : jaxbSequenceGenerators ) {
|
||||
sequenceGenerators.add( JPAXMLOverriddenAnnotationReader.buildSequenceGeneratorAnnotation( element ) );
|
||||
}
|
||||
|
||||
List<JaxbTableGenerator> jaxbTableGenerators = entityMappings.getTableGenerator();
|
||||
List<TableGenerator> tableGenerators = ( List<TableGenerator> ) defaults.get( TableGenerator.class );
|
||||
if ( tableGenerators == null ) {
|
||||
tableGenerators = new ArrayList<>();
|
||||
defaults.put( TableGenerator.class, tableGenerators );
|
||||
}
|
||||
for ( JaxbTableGenerator element : jaxbTableGenerators ) {
|
||||
tableGenerators.add(
|
||||
JPAXMLOverriddenAnnotationReader.buildTableGeneratorAnnotation(
|
||||
element, xmlDefaults
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
List<NamedQuery> namedQueries = ( List<NamedQuery> ) defaults.get( NamedQuery.class );
|
||||
if ( namedQueries == null ) {
|
||||
namedQueries = new ArrayList<>();
|
||||
defaults.put( NamedQuery.class, namedQueries );
|
||||
}
|
||||
List<NamedQuery> currentNamedQueries = JPAXMLOverriddenAnnotationReader.buildNamedQueries(
|
||||
entityMappings.getNamedQuery(),
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
);
|
||||
namedQueries.addAll( currentNamedQueries );
|
||||
|
||||
List<NamedNativeQuery> namedNativeQueries = ( List<NamedNativeQuery> ) defaults.get( NamedNativeQuery.class );
|
||||
if ( namedNativeQueries == null ) {
|
||||
namedNativeQueries = new ArrayList<>();
|
||||
defaults.put( NamedNativeQuery.class, namedNativeQueries );
|
||||
}
|
||||
List<NamedNativeQuery> currentNamedNativeQueries = JPAXMLOverriddenAnnotationReader.buildNamedNativeQueries(
|
||||
entityMappings.getNamedNativeQuery(),
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
);
|
||||
namedNativeQueries.addAll( currentNamedNativeQueries );
|
||||
|
||||
List<SqlResultSetMapping> sqlResultSetMappings = ( List<SqlResultSetMapping> ) defaults.get(
|
||||
SqlResultSetMapping.class
|
||||
);
|
||||
if ( sqlResultSetMappings == null ) {
|
||||
sqlResultSetMappings = new ArrayList<>();
|
||||
defaults.put( SqlResultSetMapping.class, sqlResultSetMappings );
|
||||
}
|
||||
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAXMLOverriddenAnnotationReader.buildSqlResultsetMappings(
|
||||
entityMappings.getSqlResultSetMapping(),
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
);
|
||||
sqlResultSetMappings.addAll( currentSqlResultSetMappings );
|
||||
|
||||
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>)defaults.get( NamedStoredProcedureQuery.class );
|
||||
if(namedStoredProcedureQueries==null){
|
||||
namedStoredProcedureQueries = new ArrayList<>( );
|
||||
defaults.put( NamedStoredProcedureQuery.class, namedStoredProcedureQueries );
|
||||
}
|
||||
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAXMLOverriddenAnnotationReader
|
||||
.buildNamedStoreProcedureQueries(
|
||||
entityMappings.getNamedStoredProcedureQuery(),
|
||||
xmlDefaults,
|
||||
classLoaderAccess
|
||||
);
|
||||
namedStoredProcedureQueries.addAll( currentNamedStoredProcedureQueries );
|
||||
}
|
||||
}
|
||||
return defaults;
|
||||
}
|
||||
}
|
||||
|
||||
public XMLContext getXMLContext() {
|
||||
return xmlContext;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* 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.cfg.annotations.reflection.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.hibernate.boot.jaxb.mapping.spi.AttributesContainer;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributes;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbBasic;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedId;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbId;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToMany;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOne;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToMany;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOne;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPostLoad;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPostPersist;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPostRemove;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPostUpdate;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPrePersist;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPreRemove;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPreUpdate;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbTransient;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbVersion;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.LifecycleCallbackContainer;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Reproduces what we used to do with a {@code List<Element>} in {@link JPAXMLOverriddenAnnotationReader},
|
||||
* with the following constraints:
|
||||
* <ul>
|
||||
* <li>Preserve type safety</li>
|
||||
* <li>Only create lists if we actually have elements (most lists should be empty in most cases)</li>
|
||||
* </ul>
|
||||
*/
|
||||
final class PropertyMappingElementCollector {
|
||||
static final Function<PersistentAttribute, String> PERSISTENT_ATTRIBUTE_NAME = PersistentAttribute::getName;
|
||||
static final Function<JaxbTransient, String> JAXB_TRANSIENT_NAME = JaxbTransient::getName;
|
||||
static final Function<LifecycleCallback, String> LIFECYCLE_CALLBACK_NAME = LifecycleCallback::getMethodName;
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
private List<JaxbId> id;
|
||||
private List<JaxbEmbeddedId> embeddedId;
|
||||
private List<JaxbBasic> basic;
|
||||
private List<JaxbVersion> version;
|
||||
private List<JaxbManyToOne> manyToOne;
|
||||
private List<JaxbOneToMany> oneToMany;
|
||||
private List<JaxbOneToOne> oneToOne;
|
||||
private List<JaxbManyToMany> manyToMany;
|
||||
private List<JaxbElementCollection> elementCollection;
|
||||
private List<JaxbEmbedded> embedded;
|
||||
private List<JaxbTransient> _transient;
|
||||
|
||||
private List<JaxbPrePersist> prePersist;
|
||||
private List<JaxbPostPersist> postPersist;
|
||||
private List<JaxbPreRemove> preRemove;
|
||||
private List<JaxbPostRemove> postRemove;
|
||||
private List<JaxbPreUpdate> preUpdate;
|
||||
private List<JaxbPostUpdate> postUpdate;
|
||||
private List<JaxbPostLoad> postLoad;
|
||||
|
||||
PropertyMappingElementCollector(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return allNullOrEmpty( id, embeddedId, basic, version, manyToOne, oneToMany, oneToOne, manyToMany,
|
||||
elementCollection, embedded, _transient,
|
||||
prePersist, postPersist, preRemove, postRemove, preUpdate, postUpdate, postLoad );
|
||||
}
|
||||
|
||||
private boolean allNullOrEmpty(List<?>... lists) {
|
||||
for ( List<?> list : lists ) {
|
||||
if ( list != null && !list.isEmpty() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private <T> List<T> defaultToEmpty(List<T> list) {
|
||||
return list == null ? Collections.emptyList() : list;
|
||||
}
|
||||
|
||||
public void collectPersistentAttributesIfMatching(AttributesContainer container) {
|
||||
if ( container instanceof JaxbAttributes ) {
|
||||
JaxbAttributes jaxbAttributes = (JaxbAttributes) container;
|
||||
id = collectIfMatching( id, jaxbAttributes.getId(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
embeddedId = collectIfMatching( embeddedId, jaxbAttributes.getEmbeddedId(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
version = collectIfMatching( version, jaxbAttributes.getVersion(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
}
|
||||
basic = collectIfMatching( basic, container.getBasic(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
manyToOne = collectIfMatching( manyToOne, container.getManyToOne(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
oneToMany = collectIfMatching( oneToMany, container.getOneToMany(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
oneToOne = collectIfMatching( oneToOne, container.getOneToOne(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
manyToMany = collectIfMatching( manyToMany, container.getManyToMany(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
elementCollection = collectIfMatching( elementCollection, container.getElementCollection(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
embedded = collectIfMatching( embedded, container.getEmbedded(), PERSISTENT_ATTRIBUTE_NAME );
|
||||
_transient = collectIfMatching( _transient, container.getTransient(), JAXB_TRANSIENT_NAME );
|
||||
}
|
||||
|
||||
public void collectLifecycleCallbacksIfMatching(LifecycleCallbackContainer container) {
|
||||
prePersist = collectIfMatching( prePersist, container.getPrePersist(), LIFECYCLE_CALLBACK_NAME );
|
||||
postPersist = collectIfMatching( postPersist, container.getPostPersist(), LIFECYCLE_CALLBACK_NAME );
|
||||
preRemove = collectIfMatching( preRemove, container.getPreRemove(), LIFECYCLE_CALLBACK_NAME );
|
||||
postRemove = collectIfMatching( postRemove, container.getPostRemove(), LIFECYCLE_CALLBACK_NAME );
|
||||
preUpdate = collectIfMatching( preUpdate, container.getPreUpdate(), LIFECYCLE_CALLBACK_NAME );
|
||||
postUpdate = collectIfMatching( postUpdate, container.getPostUpdate(), LIFECYCLE_CALLBACK_NAME );
|
||||
postLoad = collectIfMatching( postLoad, container.getPostLoad(), LIFECYCLE_CALLBACK_NAME );
|
||||
}
|
||||
|
||||
private <T> List<T> collectIfMatching(List<T> collected, List<T> candidates,
|
||||
Function<? super T, String> nameGetter) {
|
||||
List<T> result = collected;
|
||||
for ( T candidate : candidates ) {
|
||||
result = collectIfMatching( result, candidate, nameGetter );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private <T> List<T> collectIfMatching(List<T> collected, T candidate, Function<? super T, String> nameGetter) {
|
||||
List<T> result = collected;
|
||||
if ( candidate != null && propertyName.equals( nameGetter.apply( candidate ) ) ) {
|
||||
if ( result == null ) {
|
||||
result = new ArrayList<>();
|
||||
}
|
||||
result.add( candidate );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<JaxbId> getId() {
|
||||
return defaultToEmpty( id );
|
||||
}
|
||||
|
||||
public List<JaxbEmbeddedId> getEmbeddedId() {
|
||||
return defaultToEmpty( embeddedId );
|
||||
}
|
||||
|
||||
public List<JaxbBasic> getBasic() {
|
||||
return defaultToEmpty( basic );
|
||||
}
|
||||
|
||||
public List<JaxbVersion> getVersion() {
|
||||
return defaultToEmpty( version );
|
||||
}
|
||||
|
||||
public List<JaxbManyToOne> getManyToOne() {
|
||||
return defaultToEmpty( manyToOne );
|
||||
}
|
||||
|
||||
public List<JaxbOneToMany> getOneToMany() {
|
||||
return defaultToEmpty( oneToMany );
|
||||
}
|
||||
|
||||
public List<JaxbOneToOne> getOneToOne() {
|
||||
return defaultToEmpty( oneToOne );
|
||||
}
|
||||
|
||||
public List<JaxbManyToMany> getManyToMany() {
|
||||
return defaultToEmpty( manyToMany );
|
||||
}
|
||||
|
||||
public List<JaxbElementCollection> getElementCollection() {
|
||||
return defaultToEmpty( elementCollection );
|
||||
}
|
||||
|
||||
public List<JaxbEmbedded> getEmbedded() {
|
||||
return defaultToEmpty( embedded );
|
||||
}
|
||||
|
||||
public List<JaxbTransient> getTransient() {
|
||||
return defaultToEmpty( _transient );
|
||||
}
|
||||
|
||||
public List<JaxbPrePersist> getPrePersist() {
|
||||
return defaultToEmpty( prePersist );
|
||||
}
|
||||
|
||||
public List<JaxbPostPersist> getPostPersist() {
|
||||
return defaultToEmpty( postPersist );
|
||||
}
|
||||
|
||||
public List<JaxbPreRemove> getPreRemove() {
|
||||
return defaultToEmpty( preRemove );
|
||||
}
|
||||
|
||||
public List<JaxbPostRemove> getPostRemove() {
|
||||
return defaultToEmpty( postRemove );
|
||||
}
|
||||
|
||||
public List<JaxbPreUpdate> getPreUpdate() {
|
||||
return defaultToEmpty( preUpdate );
|
||||
}
|
||||
|
||||
public List<JaxbPostUpdate> getPostUpdate() {
|
||||
return defaultToEmpty( postUpdate );
|
||||
}
|
||||
|
||||
public List<JaxbPostLoad> getPostLoad() {
|
||||
return defaultToEmpty( postLoad );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* 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.cfg.annotations.reflection.internal;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeConverter;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.boot.AttributeConverterInfo;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbConverter;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListeners;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclass;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.ManagedType;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||
import org.hibernate.cfg.AttributeConverterDefinition;
|
||||
import org.hibernate.cfg.annotations.reflection.AttributeConverterDefinitionCollector;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* A helper for consuming orm.xml mappings.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class XMLContext implements Serializable {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( XMLContext.class );
|
||||
|
||||
private final ClassLoaderAccess classLoaderAccess;
|
||||
|
||||
private Default globalDefaults;
|
||||
private final Map<String, ManagedType> managedTypeOverride = new HashMap<>();
|
||||
private final Map<String, JaxbEntityListener> entityListenerOverride = new HashMap<>();
|
||||
private final Map<String, Default> defaultsOverride = new HashMap<>();
|
||||
private final List<JaxbEntityMappings> defaultElements = new ArrayList<>();
|
||||
private final List<String> defaultEntityListeners = new ArrayList<>();
|
||||
private boolean hasContext = false;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link org.hibernate.cfg.annotations.reflection.XMLContext#XMLContext(BootstrapContext)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public XMLContext(ClassLoaderAccess classLoaderAccess) {
|
||||
this.classLoaderAccess = classLoaderAccess;
|
||||
}
|
||||
|
||||
public XMLContext(BootstrapContext bootstrapContext) {
|
||||
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityMappings The xml document to add
|
||||
* @return Add an xml document to this context and return the list of added class names.
|
||||
*/
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public List<String> addDocument(JaxbEntityMappings entityMappings) {
|
||||
hasContext = true;
|
||||
List<String> addedClasses = new ArrayList<>();
|
||||
//global defaults
|
||||
JaxbPersistenceUnitMetadata metadata = entityMappings.getPersistenceUnitMetadata();
|
||||
if ( metadata != null ) {
|
||||
if ( globalDefaults == null ) {
|
||||
globalDefaults = new Default();
|
||||
globalDefaults.setMetadataComplete(
|
||||
metadata.getXmlMappingMetadataComplete() != null ?
|
||||
Boolean.TRUE :
|
||||
null
|
||||
);
|
||||
JaxbPersistenceUnitDefaults defaultElement = metadata.getPersistenceUnitDefaults();
|
||||
if ( defaultElement != null ) {
|
||||
globalDefaults.setSchema( defaultElement.getSchema() );
|
||||
globalDefaults.setCatalog( defaultElement.getCatalog() );
|
||||
globalDefaults.setAccess( defaultElement.getAccess() );
|
||||
globalDefaults.setCascadePersist( defaultElement.getCascadePersist() != null ? Boolean.TRUE : null );
|
||||
globalDefaults.setDelimitedIdentifiers( defaultElement.getDelimitedIdentifiers() != null ? Boolean.TRUE : null );
|
||||
defaultEntityListeners.addAll( addEntityListenerClasses( defaultElement.getEntityListeners(), null, addedClasses ) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG.duplicateMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
//entity mapping default
|
||||
Default entityMappingDefault = new Default();
|
||||
String packageName = entityMappings.getPackage();
|
||||
entityMappingDefault.setPackageName( packageName );
|
||||
entityMappingDefault.setSchema( entityMappings.getSchema() );
|
||||
entityMappingDefault.setCatalog( entityMappings.getCatalog() );
|
||||
entityMappingDefault.setAccess( entityMappings.getAccess() );
|
||||
defaultElements.add( entityMappings );
|
||||
|
||||
setLocalAttributeConverterDefinitions( entityMappings.getConverter() );
|
||||
|
||||
addClass( entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses );
|
||||
|
||||
addClass( entityMappings.getMappedSuperclass(), packageName, entityMappingDefault, addedClasses );
|
||||
|
||||
addClass( entityMappings.getEmbeddable(), packageName, entityMappingDefault, addedClasses );
|
||||
|
||||
return addedClasses;
|
||||
}
|
||||
|
||||
private void addClass(List<? extends ManagedType> managedTypes, String packageName, Default defaults, List<String> addedClasses) {
|
||||
for (ManagedType element : managedTypes) {
|
||||
String className = buildSafeClassName( element.getClazz(), packageName );
|
||||
if ( managedTypeOverride.containsKey( className ) ) {
|
||||
//maybe switch it to warn?
|
||||
throw new IllegalStateException( "Duplicate XML entry for " + className );
|
||||
}
|
||||
addedClasses.add( className );
|
||||
managedTypeOverride.put( className, element );
|
||||
Default localDefault = new Default();
|
||||
localDefault.override( defaults );
|
||||
localDefault.setMetadataComplete( element.isMetadataComplete() );
|
||||
localDefault.setAccess( element.getAccess() );
|
||||
defaultsOverride.put( className, localDefault );
|
||||
|
||||
LOG.debugf( "Adding XML overriding information for %s", className );
|
||||
if ( element instanceof JaxbEntity ) {
|
||||
addEntityListenerClasses( ( (JaxbEntity) element ).getEntityListeners(), packageName, addedClasses );
|
||||
}
|
||||
else if ( element instanceof JaxbMappedSuperclass ) {
|
||||
addEntityListenerClasses( ( (JaxbMappedSuperclass) element ).getEntityListeners(), packageName, addedClasses );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> addEntityListenerClasses(JaxbEntityListeners listeners, String packageName, List<String> addedClasses) {
|
||||
List<String> localAddedClasses = new ArrayList<>();
|
||||
if ( listeners != null ) {
|
||||
List<JaxbEntityListener> elements = listeners.getEntityListener();
|
||||
for (JaxbEntityListener listener : elements) {
|
||||
String listenerClassName = buildSafeClassName( listener.getClazz(), packageName );
|
||||
if ( entityListenerOverride.containsKey( listenerClassName ) ) {
|
||||
LOG.duplicateListener( listenerClassName );
|
||||
continue;
|
||||
}
|
||||
localAddedClasses.add( listenerClassName );
|
||||
entityListenerOverride.put( listenerClassName, listener );
|
||||
}
|
||||
}
|
||||
LOG.debugf( "Adding XML overriding information for listeners: %s", localAddedClasses );
|
||||
addedClasses.addAll( localAddedClasses );
|
||||
return localAddedClasses;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converterElements) {
|
||||
for ( JaxbConverter converterElement : converterElements ) {
|
||||
final String className = converterElement.getClazz();
|
||||
final boolean autoApply = Boolean.TRUE.equals( converterElement.isAutoApply() );
|
||||
|
||||
try {
|
||||
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
|
||||
className
|
||||
);
|
||||
attributeConverterInfoList.add(
|
||||
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )
|
||||
);
|
||||
}
|
||||
catch (ClassLoadingException e) {
|
||||
throw new AnnotationException( "Unable to locate specified AttributeConverter implementation class : " + className, e );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AnnotationException( "Unable to instantiate specified AttributeConverter implementation class : " + className, e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String buildSafeClassName(String className, String defaultPackageName) {
|
||||
if ( className.indexOf( '.' ) < 0 && StringHelper.isNotEmpty( defaultPackageName ) ) {
|
||||
className = StringHelper.qualify( defaultPackageName, className );
|
||||
}
|
||||
return className;
|
||||
}
|
||||
|
||||
public static String buildSafeClassName(String className, Default defaults) {
|
||||
return buildSafeClassName( className, defaults.getPackageName() );
|
||||
}
|
||||
|
||||
public Default getDefault(String className) {
|
||||
Default xmlDefault = new Default();
|
||||
xmlDefault.override( globalDefaults );
|
||||
if ( className != null ) {
|
||||
Default entityMappingOverriding = defaultsOverride.get( className );
|
||||
xmlDefault.override( entityMappingOverriding );
|
||||
}
|
||||
return xmlDefault;
|
||||
}
|
||||
|
||||
public ManagedType getManagedTypeOverride(String className) {
|
||||
return managedTypeOverride.get( className );
|
||||
}
|
||||
|
||||
public JaxbEntityListener getEntityListenerOverride(String className) {
|
||||
return entityListenerOverride.get( className );
|
||||
}
|
||||
|
||||
public List<JaxbEntityMappings> getAllDocuments() {
|
||||
return defaultElements;
|
||||
}
|
||||
|
||||
public boolean hasContext() {
|
||||
return hasContext;
|
||||
}
|
||||
|
||||
private List<AttributeConverterInfo> attributeConverterInfoList = new ArrayList<>();
|
||||
|
||||
public void applyDiscoveredAttributeConverters(AttributeConverterDefinitionCollector collector) {
|
||||
for ( AttributeConverterInfo info : attributeConverterInfoList ) {
|
||||
collector.addAttributeConverter( info );
|
||||
}
|
||||
attributeConverterInfoList.clear();
|
||||
}
|
||||
|
||||
public static class Default implements Serializable {
|
||||
private AccessType access;
|
||||
private String packageName;
|
||||
private String schema;
|
||||
private String catalog;
|
||||
private Boolean metadataComplete;
|
||||
private Boolean cascadePersist;
|
||||
private Boolean delimitedIdentifier;
|
||||
|
||||
public AccessType getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
protected void setAccess(AccessType access) {
|
||||
this.access = access;
|
||||
}
|
||||
|
||||
public String getCatalog() {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
protected void setCatalog(String catalog) {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
protected void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
protected void setSchema(String schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public Boolean getMetadataComplete() {
|
||||
return metadataComplete;
|
||||
}
|
||||
|
||||
public boolean canUseJavaAnnotations() {
|
||||
return metadataComplete == null || !metadataComplete;
|
||||
}
|
||||
|
||||
protected void setMetadataComplete(Boolean metadataComplete) {
|
||||
this.metadataComplete = metadataComplete;
|
||||
}
|
||||
|
||||
public Boolean getCascadePersist() {
|
||||
return cascadePersist;
|
||||
}
|
||||
|
||||
void setCascadePersist(Boolean cascadePersist) {
|
||||
this.cascadePersist = cascadePersist;
|
||||
}
|
||||
|
||||
public void override(Default globalDefault) {
|
||||
if ( globalDefault != null ) {
|
||||
if ( globalDefault.getAccess() != null ) {
|
||||
access = globalDefault.getAccess();
|
||||
}
|
||||
if ( globalDefault.getPackageName() != null ) {
|
||||
packageName = globalDefault.getPackageName();
|
||||
}
|
||||
if ( globalDefault.getSchema() != null ) {
|
||||
schema = globalDefault.getSchema();
|
||||
}
|
||||
if ( globalDefault.getCatalog() != null ) {
|
||||
catalog = globalDefault.getCatalog();
|
||||
}
|
||||
if ( globalDefault.getDelimitedIdentifier() != null ) {
|
||||
delimitedIdentifier = globalDefault.getDelimitedIdentifier();
|
||||
}
|
||||
if ( globalDefault.getMetadataComplete() != null ) {
|
||||
metadataComplete = globalDefault.getMetadataComplete();
|
||||
}
|
||||
//TODO fix that in stone if cascade-persist is set already?
|
||||
if ( globalDefault.getCascadePersist() != null ) cascadePersist = globalDefault.getCascadePersist();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDelimitedIdentifiers(Boolean delimitedIdentifier) {
|
||||
this.delimitedIdentifier = delimitedIdentifier;
|
||||
}
|
||||
|
||||
public Boolean getDelimitedIdentifier() {
|
||||
return delimitedIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getDefaultEntityListeners() {
|
||||
return defaultEntityListeners;
|
||||
}
|
||||
}
|
|
@ -265,7 +265,8 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
|
|||
public void afterTransaction() {
|
||||
transactionTimeOutInstant = -1;
|
||||
if ( getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ||
|
||||
getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION ) {
|
||||
getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION ||
|
||||
getConnectionReleaseMode() == ConnectionReleaseMode.BEFORE_TRANSACTION_COMPLETION ) {
|
||||
this.logicalConnection.afterTransaction();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.StringTokenizer;
|
|||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.model.CustomSql;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
|
@ -754,6 +755,16 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
|
|||
return properties.iterator();
|
||||
}
|
||||
|
||||
public void setCustomSqlInsert(CustomSql customSql) {
|
||||
if ( customSql != null ) {
|
||||
setCustomSQLInsert(
|
||||
customSql.getSql(),
|
||||
customSql.isCallable(),
|
||||
customSql.getCheckStyle()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomSQLInsert(String customSQLInsert, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
|
||||
this.customSQLInsert = customSQLInsert;
|
||||
this.customInsertCallable = callable;
|
||||
|
@ -772,6 +783,16 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
|
|||
return insertCheckStyle;
|
||||
}
|
||||
|
||||
public void setCustomSqlUpdate(CustomSql customSql) {
|
||||
if ( customSql != null ) {
|
||||
setCustomSQLUpdate(
|
||||
customSql.getSql(),
|
||||
customSql.isCallable(),
|
||||
customSql.getCheckStyle()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomSQLUpdate(String customSQLUpdate, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
|
||||
this.customSQLUpdate = customSQLUpdate;
|
||||
this.customUpdateCallable = callable;
|
||||
|
@ -790,6 +811,16 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl
|
|||
return updateCheckStyle;
|
||||
}
|
||||
|
||||
public void setCustomSqlDelete(CustomSql customSql) {
|
||||
if ( customSql != null ) {
|
||||
setCustomSQLDelete(
|
||||
customSql.getSql(),
|
||||
customSql.isCallable(),
|
||||
customSql.getCheckStyle()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomSQLDelete(String customSQLDelete, boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
|
||||
this.customSQLDelete = customSQLDelete;
|
||||
this.customDeleteCallable = callable;
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.AttributeConverter;
|
||||
|
@ -411,6 +413,18 @@ public abstract class SimpleValue implements KeyValue {
|
|||
this.identifierGeneratorProperties = identifierGeneratorProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifierGeneratorProperties.
|
||||
* @param identifierGeneratorProperties The identifierGeneratorProperties to set
|
||||
*/
|
||||
public void setIdentifierGeneratorProperties(Map identifierGeneratorProperties) {
|
||||
if ( identifierGeneratorProperties != null ) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( identifierGeneratorProperties );
|
||||
setIdentifierGeneratorProperties( properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifierGeneratorStrategy.
|
||||
* @param identifierGeneratorStrategy The identifierGeneratorStrategy to set
|
||||
|
@ -703,6 +717,14 @@ public abstract class SimpleValue implements KeyValue {
|
|||
this.typeParameters = parameterMap;
|
||||
}
|
||||
|
||||
public void setTypeParameters(Map<String, String> parameters) {
|
||||
if ( parameters != null ) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( parameters );
|
||||
setTypeParameters( properties );
|
||||
}
|
||||
}
|
||||
|
||||
public Properties getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
|
|
@ -166,8 +166,10 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple
|
|||
super.afterTransaction();
|
||||
|
||||
if ( connectionHandlingMode.getReleaseMode() != ConnectionReleaseMode.ON_CLOSE ) {
|
||||
// NOTE : we check for !ON_CLOSE here (rather than AFTER_TRANSACTION) to also catch AFTER_STATEMENT cases
|
||||
// that were circumvented due to held resources
|
||||
// NOTE : we check for !ON_CLOSE here (rather than AFTER_TRANSACTION) to also catch:
|
||||
// - AFTER_STATEMENT cases that were circumvented due to held resources
|
||||
// - BEFORE_TRANSACTION_COMPLETION cases that were circumvented because a rollback occurred
|
||||
// (we don't get a beforeTransactionCompletion event on rollback).
|
||||
log.debug( "Initiating JDBC connection release from afterTransaction" );
|
||||
releaseConnection();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,193 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
|
||||
extensionBindingPrefixes="inheritance"
|
||||
version="2.1">
|
||||
|
||||
<bindings schemaLocation="../resources/org/hibernate/jpa/orm_2_2.xsd" node="/xsd:schema">
|
||||
<schemaBindings>
|
||||
<package name="org.hibernate.boot.jaxb.mapping.spi" />
|
||||
<nameXmlTransform>
|
||||
<typeName prefix="Jaxb" />
|
||||
<elementName prefix="Jaxb" />
|
||||
<modelGroupName prefix="Jaxb" />
|
||||
<anonymousTypeName prefix="Jaxb" />
|
||||
</nameXmlTransform>
|
||||
</schemaBindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='access-type']">
|
||||
<javaType name="javax.persistence.AccessType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.AccessTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.AccessTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='discriminator-type']">
|
||||
<javaType name="javax.persistence.DiscriminatorType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.DiscriminatorTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.DiscriminatorTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='enum-type']">
|
||||
<javaType name="javax.persistence.EnumType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.EnumTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.EnumTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='fetch-type']">
|
||||
<javaType name="javax.persistence.FetchType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.FetchTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.FetchTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='lock-mode-type']">
|
||||
<javaType name="javax.persistence.LockModeType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.LockModeTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.LockModeTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='parameter-mode']">
|
||||
<javaType name="javax.persistence.ParameterMode"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.ParameterModeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.ParameterModeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='temporal-type']">
|
||||
<javaType name="javax.persistence.TemporalType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.TemporalTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.TemporalTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='inheritance-type']">
|
||||
<javaType name="javax.persistence.InheritanceType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.InheritanceTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.InheritanceTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='generation-type']">
|
||||
<javaType name="javax.persistence.GenerationType"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.GenerationTypeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.GenerationTypeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:simpleType[@name='constraint-mode']">
|
||||
<javaType name="javax.persistence.ConstraintMode"
|
||||
parseMethod="org.hibernate.boot.jaxb.mapping.internal.ConstraintModeMarshalling.fromXml"
|
||||
printMethod="org.hibernate.boot.jaxb.mapping.internal.ConstraintModeMarshalling.toXml" />
|
||||
</bindings>
|
||||
|
||||
|
||||
<bindings node="//xsd:complexType[@name='secondary-table']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='table']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='join-table']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='collection-table']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='table-generator']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='sequence-generator']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.SchemaAware</inheritance:implements>
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:complexType[@name='entity']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.ManagedType</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.EntityOrMappedSuperclass</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallbackContainer</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='embeddable']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.ManagedType</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='mapped-superclass']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.ManagedType</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.EntityOrMappedSuperclass</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallbackContainer</inheritance:implements>
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:complexType[@name='entity-listener']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallbackContainer</inheritance:implements>
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:complexType[@name='id']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='version']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='basic']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='many-to-one']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.FetchableAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AssociationAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='one-to-many']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.CollectionAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AssociationAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='one-to-one']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.FetchableAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AssociationAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='embedded-id']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='embedded']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='many-to-many']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.CollectionAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AssociationAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='element-collection']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.PersistentAttribute</inheritance:implements>
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.CollectionAttribute</inheritance:implements>
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:complexType[@name='pre-persist']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='pre-remove']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='pre-update']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='post-load']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='post-remove']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='post-update']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='post-persist']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.LifecycleCallback</inheritance:implements>
|
||||
</bindings>
|
||||
|
||||
<bindings node="//xsd:complexType[@name='attributes']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AttributesContainer</inheritance:implements>
|
||||
</bindings>
|
||||
<bindings node="//xsd:complexType[@name='embeddable-attributes']">
|
||||
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.AttributesContainer</inheritance:implements>
|
||||
</bindings>
|
||||
</bindings>
|
||||
|
||||
<!-- All bindings need to be serializable for cached metadata sources. -->
|
||||
<globalBindings>
|
||||
<serializable />
|
||||
</globalBindings>
|
||||
|
||||
</bindings>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
version="2.1">
|
||||
|
||||
<jaxb:bindings schemaLocation="../resources/org/hibernate/jpa/orm_2_0.xsd" node="/xsd:schema">
|
||||
<jaxb:schemaBindings>
|
||||
<jaxb:nameXmlTransform>
|
||||
<jaxb:typeName prefix="Jaxb"/>
|
||||
<jaxb:elementName prefix="Jaxb"/>
|
||||
<jaxb:modelGroupName prefix="Jaxb"/>
|
||||
<jaxb:anonymousTypeName prefix="Jaxb"/>
|
||||
</jaxb:nameXmlTransform>
|
||||
</jaxb:schemaBindings>
|
||||
</jaxb:bindings>
|
||||
|
||||
</jaxb:bindings>
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.internal.util.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hibernate.boot.jaxb.Origin;
|
||||
import org.hibernate.boot.jaxb.SourceType;
|
||||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* A small helper class for parsing XML mappings, to be used in unit tests.
|
||||
*/
|
||||
public final class XMLMappingHelper {
|
||||
private final MappingBinder binder;
|
||||
|
||||
public XMLMappingHelper(XmlMappingOptions xmlMappingOptions) {
|
||||
binder = new MappingBinder( ClassLoaderServiceTestingImpl.INSTANCE, true, xmlMappingOptions );
|
||||
}
|
||||
|
||||
public JaxbEntityMappings readOrmXmlMappings(String name) throws IOException {
|
||||
try (InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream( name )) {
|
||||
return readOrmXmlMappings( is, name );
|
||||
}
|
||||
}
|
||||
|
||||
public JaxbEntityMappings readOrmXmlMappings(InputStream is, String name) {
|
||||
try {
|
||||
Assert.assertNotNull( "Resource not found: " + name, is );
|
||||
Binding<?> binding = binder.bind( is, new Origin( SourceType.JAR, name ) );
|
||||
return (JaxbEntityMappings) binding.getRoot();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw new IllegalStateException( "Could not parse orm.xml mapping '" + name + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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.internal.util.xml;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistration;
|
||||
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* A strategy registration provider that allows running the whole test suite with different XML mapping options.
|
||||
* <p>
|
||||
* By default, this provider does nothing.
|
||||
* In some CI jobs, we set the system property {@value STRATEGY_PROPERTY_KEY}
|
||||
* to re-run the whole test suite using JAXB for orm.xml parsing instead of dom4j.
|
||||
*/
|
||||
public class XmlMappingOptionsStrategyRegistrationProvider implements StrategyRegistrationProvider {
|
||||
|
||||
protected final Logger log = Logger.getLogger( getClass() );
|
||||
|
||||
private static final String STRATEGY_PROPERTY_KEY = "testing.mapping.xml.strategy";
|
||||
|
||||
public static void applyJaxbStrategy(BootstrapServiceRegistryBuilder builder) {
|
||||
builder.applyStrategySelector( XmlMappingOptions.class, XmlMappingOptions.DEFAULT_NAME,
|
||||
PreferJaxbXmlMappingOptions.class
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<StrategyRegistration> getStrategyRegistrations() {
|
||||
switch ( getStrategyFromSystemProperties() ) {
|
||||
case "jaxb":
|
||||
log.warn( "Overriding the default configuration because of a test system property:"
|
||||
+ " will favor jaxb when parsing XML mapping." );
|
||||
return Collections.singleton(
|
||||
new SimpleStrategyRegistrationImpl<>( XmlMappingOptions.class,
|
||||
PreferJaxbXmlMappingOptions.class,
|
||||
XmlMappingOptions.DEFAULT_NAME )
|
||||
);
|
||||
case "default":
|
||||
default:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getStrategyFromSystemProperties() {
|
||||
String strategy = System.getProperty( STRATEGY_PROPERTY_KEY );
|
||||
return strategy == null || strategy.isEmpty() ? "default" : strategy;
|
||||
}
|
||||
|
||||
public static class PreferJaxbXmlMappingOptions implements XmlMappingOptions {
|
||||
@Override
|
||||
public boolean isPreferJaxb() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,10 +55,9 @@ import static org.junit.Assert.assertTrue;
|
|||
public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.reflection;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -13,9 +16,15 @@ import org.junit.Test;
|
|||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@TestForIssue( jiraKey = "HHH-11924")
|
||||
@TestForIssue(jiraKey = {"HHH-11924", "HHH-14529"})
|
||||
public class ElementCollectionConverterTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
XmlMappingOptionsStrategyRegistrationProvider.applyJaxbStrategy( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
|
@ -0,0 +1,419 @@
|
|||
/*
|
||||
* 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.test.annotations.reflection;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.hibernate.annotations.Columns;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.XMLContext;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the new {@link JPAXMLOverriddenAnnotationReader},
|
||||
* which will be replacing {@link JPAOverriddenAnnotationReader}.
|
||||
* {@link JPAOverriddenAnnotationReader} is still the default implementation,
|
||||
* but we want to switch to {@link JPAXMLOverriddenAnnotationReader}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see LegacyJPAOverriddenAnnotationReaderTest
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testMappedSuperclassAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Organization.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Default value in xml entity should not override @Entity.name", "JavaAdministration",
|
||||
reader.getAnnotation( Entity.class ).name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table not overridden", "tbl_admin", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Default schema not overridden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
assertEquals(
|
||||
"Proper @Table.uniqueConstraints", 2,
|
||||
reader.getAnnotation( Table.class ).uniqueConstraints()[0].columnNames().length
|
||||
);
|
||||
String columnName = reader.getAnnotation( Table.class ).uniqueConstraints()[0].columnNames()[0];
|
||||
assertTrue(
|
||||
"Proper @Table.uniqueConstraints", "firstname".equals( columnName ) || "lastname".equals( columnName )
|
||||
);
|
||||
assertNull( "Both Java and XML used", reader.getAnnotation( SecondaryTable.class ) );
|
||||
assertNotNull( "XML does not work", reader.getAnnotation( SecondaryTables.class ) );
|
||||
SecondaryTable[] tables = reader.getAnnotation( SecondaryTables.class ).value();
|
||||
assertEquals( 1, tables.length );
|
||||
assertEquals( "admin2", tables[0].name() );
|
||||
assertEquals( "unique constraints ignored", 1, tables[0].uniqueConstraints().length );
|
||||
assertEquals( "pk join column ignored", 1, tables[0].pkJoinColumns().length );
|
||||
assertEquals( "pk join column ignored", "admin_id", tables[0].pkJoinColumns()[0].name() );
|
||||
assertNotNull( "Sequence Overriding not working", reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertEquals(
|
||||
"wrong sequence name", "seqhilo", reader.getAnnotation( SequenceGenerator.class ).sequenceName()
|
||||
);
|
||||
assertEquals( "default fails", 50, reader.getAnnotation( SequenceGenerator.class ).allocationSize() );
|
||||
assertNotNull( "TableOverriding not working", reader.getAnnotation( TableGenerator.class ) );
|
||||
assertEquals( "wrong tble name", "tablehilo", reader.getAnnotation( TableGenerator.class ).table() );
|
||||
assertEquals( "no schema overriding", "myschema", reader.getAnnotation( TableGenerator.class ).schema() );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals(
|
||||
"Java annotation not taken into account", "matchtable", reader.getAnnotation( Table.class ).name()
|
||||
);
|
||||
assertEquals(
|
||||
"Java annotation not taken into account", "matchschema", reader.getAnnotation( Table.class ).schema()
|
||||
);
|
||||
assertEquals( "Overriding not taken into account", "mycatalog", reader.getAnnotation( Table.class ).catalog() );
|
||||
assertNotNull( "SecondaryTable swallowed", reader.getAnnotation( SecondaryTables.class ) );
|
||||
assertEquals(
|
||||
"Default schema not taken into account", "myschema",
|
||||
reader.getAnnotation( SecondaryTables.class ).value()[0].schema()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Inheritance.class ) );
|
||||
assertEquals(
|
||||
"inheritance strategy not overriden", InheritanceType.JOINED,
|
||||
reader.getAnnotation( Inheritance.class ).strategy()
|
||||
);
|
||||
assertNotNull( "NamedQuery not overriden", reader.getAnnotation( NamedQueries.class ) );
|
||||
assertEquals( "No deduplication", 3, reader.getAnnotation( NamedQueries.class ).value().length );
|
||||
assertEquals(
|
||||
"deduplication kept the Java version", 1,
|
||||
reader.getAnnotation( NamedQueries.class ).value()[1].hints().length
|
||||
);
|
||||
assertEquals(
|
||||
"org.hibernate.timeout", reader.getAnnotation( NamedQueries.class ).value()[1].hints()[0].name()
|
||||
);
|
||||
assertNotNull( "NamedNativeQuery not overriden", reader.getAnnotation( NamedNativeQueries.class ) );
|
||||
assertEquals( "No deduplication", 3, reader.getAnnotation( NamedNativeQueries.class ).value().length );
|
||||
assertEquals(
|
||||
"deduplication kept the Java version", 1,
|
||||
reader.getAnnotation( NamedNativeQueries.class ).value()[1].hints().length
|
||||
);
|
||||
assertEquals(
|
||||
"org.hibernate.timeout", reader.getAnnotation( NamedNativeQueries.class ).value()[1].hints()[0].name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( SqlResultSetMappings.class ) );
|
||||
assertEquals(
|
||||
"competitor1Point", reader.getAnnotation( SqlResultSetMappings.class ).value()[0].columns()[0].name()
|
||||
);
|
||||
assertEquals(
|
||||
"competitor1Point",
|
||||
reader.getAnnotation( SqlResultSetMappings.class ).value()[0].entities()[0].fields()[0].column()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( ExcludeSuperclassListeners.class ) );
|
||||
assertNotNull( reader.getAnnotation( ExcludeDefaultListeners.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( "Mutualize PKJC into PKJCs", reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
assertEquals(
|
||||
"PrimaryKeyJoinColumn overrden", "id",
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class ).value()[0].name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||
assertEquals( "Wrong deduplication", 3, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
assertEquals(
|
||||
"Wrong priority (XML vs java annotations)", "fld_net",
|
||||
reader.getAnnotation( AttributeOverrides.class ).value()[0].column().name()
|
||||
);
|
||||
assertEquals(
|
||||
"Column mapping", 2, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().scale()
|
||||
);
|
||||
assertEquals(
|
||||
"Column mapping", true, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().unique()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( AssociationOverrides.class ) );
|
||||
assertEquals( "no XML processing", 1, reader.getAnnotation( AssociationOverrides.class ).value().length );
|
||||
assertEquals(
|
||||
"wrong xml processing", "id",
|
||||
reader.getAnnotation( AssociationOverrides.class ).value()[0].joinColumns()[0].referencedColumnName()
|
||||
);
|
||||
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityPhysicalAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() );
|
||||
assertEquals(
|
||||
"discriminator-value not used", "Physical", reader.getAnnotation( DiscriminatorValue.class ).value()
|
||||
);
|
||||
assertNotNull( "discriminator-column not used", reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||
assertEquals(
|
||||
"discriminator-column.name default value broken", "DTYPE",
|
||||
reader.getAnnotation( DiscriminatorColumn.class ).name()
|
||||
);
|
||||
assertEquals(
|
||||
"discriminator-column.length broken", 34, reader.getAnnotation( DiscriminatorColumn.class ).length()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Metadata complete should ignore java annotations", "", reader.getAnnotation( Entity.class ).name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Default schema not overriden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Overriding not taken into account", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
assertEquals( "Overriding not taken into account", "mycatalog", reader.getAnnotation( Table.class ).catalog() );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( SecondaryTable.class ) );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( SecondaryTables.class ) );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( Inheritance.class ) );
|
||||
assertNull( reader.getAnnotation( NamedQueries.class ) );
|
||||
assertNull( reader.getAnnotation( NamedNativeQueries.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityMoralAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorValue.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||
assertNull( reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertNull( reader.getAnnotation( TableGenerator.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( Id.class ) );
|
||||
assertNull( reader.getAnnotation( Column.class ) );
|
||||
Field field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Id.class ) );
|
||||
assertNotNull( reader.getAnnotation( GeneratedValue.class ) );
|
||||
assertEquals( GenerationType.SEQUENCE, reader.getAnnotation( GeneratedValue.class ).strategy() );
|
||||
assertEquals( "generator", reader.getAnnotation( GeneratedValue.class ).generator() );
|
||||
assertNotNull( reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertEquals( "seq", reader.getAnnotation( SequenceGenerator.class ).sequenceName() );
|
||||
assertNotNull( reader.getAnnotation( Columns.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( Columns.class ).columns().length );
|
||||
assertEquals( "fld_id", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||
assertEquals( TemporalType.DATE, reader.getAnnotation( Temporal.class ).value() );
|
||||
|
||||
context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
method = Administration.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
|
||||
method = BusTrip.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
field = BusTrip.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
Field field = BusTrip.class.getDeclaredField( "status" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Enumerated.class ) );
|
||||
assertEquals( EnumType.STRING, reader.getAnnotation( Enumerated.class ).value() );
|
||||
assertEquals( false, reader.getAnnotation( Basic.class ).optional() );
|
||||
field = BusTrip.class.getDeclaredField( "serial" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Lob.class ) );
|
||||
assertEquals( "serialbytes", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||
field = BusTrip.class.getDeclaredField( "terminusTime" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||
assertEquals( TemporalType.TIMESTAMP, reader.getAnnotation( Temporal.class ).value() );
|
||||
assertEquals( FetchType.LAZY, reader.getAnnotation( Basic.class ).fetch() );
|
||||
|
||||
field = BusTripPk.class.getDeclaredField( "busDriver" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
|
||||
Field field = Match.class.getDeclaredField( "version" );
|
||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "transientField" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Transient.class ) );
|
||||
assertNull( reader.getAnnotation( Basic.class ) );
|
||||
|
||||
field = Match.class.getDeclaredField( "playerASSN" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssociationRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "defaultBusTrip" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( OneToOne.class ) );
|
||||
assertNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
assertEquals( "pk", reader.getAnnotation( PrimaryKeyJoinColumns.class ).value()[0].name() );
|
||||
assertEquals( 5, reader.getAnnotation( OneToOne.class ).cascade().length );
|
||||
assertEquals( FetchType.LAZY, reader.getAnnotation( OneToOne.class ).fetch() );
|
||||
assertEquals( "test", reader.getAnnotation( OneToOne.class ).mappedBy() );
|
||||
|
||||
context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
field = BusTrip.class.getDeclaredField( "players" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( OneToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertEquals( 2, reader.getAnnotation( JoinColumns.class ).value().length );
|
||||
assertEquals( "driver", reader.getAnnotation( JoinColumns.class ).value()[0].name() );
|
||||
assertNotNull( reader.getAnnotation( MapKey.class ) );
|
||||
assertEquals( "name", reader.getAnnotation( MapKey.class ).name() );
|
||||
|
||||
field = BusTrip.class.getDeclaredField( "roads" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( ManyToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinTable.class ) );
|
||||
assertEquals( "bus_road", reader.getAnnotation( JoinTable.class ).name() );
|
||||
assertEquals( 2, reader.getAnnotation( JoinTable.class ).joinColumns().length );
|
||||
assertEquals( 1, reader.getAnnotation( JoinTable.class ).inverseJoinColumns().length );
|
||||
assertEquals( 2, reader.getAnnotation( JoinTable.class ).uniqueConstraints()[0].columnNames().length );
|
||||
assertNotNull( reader.getAnnotation( OrderBy.class ) );
|
||||
assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11924")
|
||||
public void testElementCollectionConverter() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Company.class.getDeclaredField( "organizations" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( ElementCollection.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ).value() );
|
||||
assertTrue( reader.getAnnotation( Converts.class ).value().length == 1 );
|
||||
assertEquals(OrganizationConverter.class, reader.getAnnotation( Converts.class ).value()[0].converter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityListeners() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Method method = Administration.class.getDeclaredMethod( "calculate" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( EntityListeners.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
|
||||
assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "noLog", Object.class );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PostLoad.class ) );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "log", Object.class );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
assertFalse( reader.isAnnotationPresent( PostPersist.class ) );
|
||||
|
||||
assertEquals( 1, context.getDefaultEntityListeners().size() );
|
||||
assertEquals( OtherLogListener.class.getName(), context.getDefaultEntityListeners().get( 0 ) );
|
||||
}
|
||||
|
||||
private XMLContext buildContext(String ormfile) throws IOException {
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper( new XmlMappingOptions() {
|
||||
@Override
|
||||
public boolean isPreferJaxb() {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( ormfile );
|
||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
context.addDocument( mappings );
|
||||
return context;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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.test.annotations.reflection;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link JPAOverriddenAnnotationReader},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}.
|
||||
* {@link JPAOverriddenAnnotationReader} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see JPAXMLOverriddenAnnotationReaderTest
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
@TestForIssue( jiraKey = "HHH-11924")
|
||||
public class LegacyElementCollectionConverterTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Company.class,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/reflection/element-collection-converter-orm.xml" };
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterIsAppliedToElementCollection() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
Company company = new Company();
|
||||
company.setId( 1L );
|
||||
|
||||
Organization org1 = new Organization();
|
||||
org1.setOrganizationId( "ACME" );
|
||||
|
||||
company.getOrganizations().add( org1 );
|
||||
|
||||
session.persist( company );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
String organizationId = (String) session
|
||||
.createNativeQuery( "select organizations from Company_organizations" )
|
||||
.getSingleResult();
|
||||
assertEquals( "ORG-ACME", organizationId );
|
||||
|
||||
Company company = session.find( Company.class, 1L );
|
||||
|
||||
assertEquals( 1, company.getOrganizations().size() );
|
||||
assertEquals( "ACME" , company.getOrganizations().get( 0 ).getOrganizationId());
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -6,8 +6,61 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.reflection;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.persistence.AssociationOverrides;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Converts;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.ExcludeDefaultListeners;
|
||||
import javax.persistence.ExcludeSuperclassListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.NamedNativeQueries;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.PostLoad;
|
||||
import javax.persistence.PostPersist;
|
||||
import javax.persistence.PrePersist;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.SecondaryTables;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.SqlResultSetMappings;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.hibernate.annotations.Columns;
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
@ -15,28 +68,37 @@ import org.hibernate.cfg.annotations.reflection.XMLContext;
|
|||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link JPAOverriddenAnnotationReader},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}.
|
||||
* {@link JPAOverriddenAnnotationReader} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see JPAXMLOverriddenAnnotationReaderTest
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
public class JPAOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
@Deprecated
|
||||
public class LegacyJPAOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testMappedSuperclassAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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.test.annotations.reflection;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link XMLContext},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.XMLContext}.
|
||||
* {@link XMLContext} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.XMLContext}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see XMLContextTest
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link XMLContext}.
|
||||
*/
|
||||
public class LegacyXMLContextTest {
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
final XMLHelper xmlHelper = new XMLHelper();
|
||||
final XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
|
||||
InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream(
|
||||
"org/hibernate/test/annotations/reflection/orm.xml"
|
||||
);
|
||||
Assert.assertNotNull( "ORM.xml not found", is );
|
||||
|
||||
final ErrorLogger errorLogger = new ErrorLogger();
|
||||
final SAXReader saxReader = xmlHelper.createSAXReader( errorLogger, EJB3DTDEntityResolver.INSTANCE );
|
||||
|
||||
try {
|
||||
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
|
||||
}
|
||||
catch ( SAXNotSupportedException e ) {
|
||||
saxReader.setValidation( false );
|
||||
}
|
||||
org.dom4j.Document doc;
|
||||
try {
|
||||
doc = saxReader.read( new InputSource( new BufferedInputStream( is ) ) );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch ( IOException ioe ) {
|
||||
//log.warn( "Could not close input stream", ioe );
|
||||
}
|
||||
}
|
||||
Assert.assertFalse( errorLogger.hasErrors() );
|
||||
context.addDocument( doc );
|
||||
}
|
||||
}
|
|
@ -6,60 +6,37 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.reflection;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.XMLContext;
|
||||
import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests the new {@link XMLContext},
|
||||
* which will be replacing {@link org.hibernate.cfg.annotations.reflection.XMLContext}.
|
||||
* {@link org.hibernate.cfg.annotations.reflection.XMLContext} is still the default implementation,
|
||||
* but we want to switch to {@link XMLContext}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class XMLContextTest {
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
final XMLHelper xmlHelper = new XMLHelper();
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper( new XmlMappingOptions() {
|
||||
@Override
|
||||
public boolean isPreferJaxb() {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
final XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
|
||||
InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream(
|
||||
"org/hibernate/test/annotations/reflection/orm.xml"
|
||||
);
|
||||
Assert.assertNotNull( "ORM.xml not found", is );
|
||||
|
||||
final ErrorLogger errorLogger = new ErrorLogger();
|
||||
final SAXReader saxReader = xmlHelper.createSAXReader( errorLogger, EJB3DTDEntityResolver.INSTANCE );
|
||||
|
||||
try {
|
||||
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
|
||||
}
|
||||
catch ( SAXNotSupportedException e ) {
|
||||
saxReader.setValidation( false );
|
||||
}
|
||||
org.dom4j.Document doc;
|
||||
try {
|
||||
doc = saxReader.read( new InputSource( new BufferedInputStream( is ) ) );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch ( IOException ioe ) {
|
||||
//log.warn( "Could not close input stream", ioe );
|
||||
}
|
||||
}
|
||||
Assert.assertFalse( errorLogger.hasErrors() );
|
||||
context.addDocument( doc );
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
context.addDocument( mappings );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,14 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
|
|
|
@ -29,12 +29,14 @@ import javax.persistence.OrderColumn;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlManyToManyTest extends Ejb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
|
|
|
@ -18,12 +18,14 @@ import javax.persistence.ManyToOne;
|
|||
import javax.persistence.MapsId;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoJoins() throws Exception {
|
||||
|
|
|
@ -29,12 +29,14 @@ import javax.persistence.OrderColumn;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlOneToManyTest extends Ejb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
|
|
|
@ -20,12 +20,14 @@ import javax.persistence.PrimaryKeyJoinColumn;
|
|||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
|
|
|
@ -13,12 +13,15 @@ import org.hibernate.Session;
|
|||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.TeradataDialect;
|
||||
import org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider;
|
||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -28,7 +31,15 @@ import static org.junit.Assert.assertNotNull;
|
|||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
XmlMappingOptionsStrategyRegistrationProvider.applyJaxbStrategy( builder );
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(value = {PostgreSQL81Dialect.class, PostgreSQLDialect.class, CockroachDialect.class},
|
||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
||||
|
|
|
@ -10,11 +10,11 @@ import java.io.InputStream;
|
|||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.internal.XMLContext;
|
||||
import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
@ -28,8 +28,12 @@ import static org.junit.Assert.assertTrue;
|
|||
* XML to JPA annotations. The configuration is built within each test, and no
|
||||
* database is used. Thus, no schema generation or cleanup will be performed.
|
||||
*/
|
||||
abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||
protected JPAOverriddenAnnotationReader reader;
|
||||
public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||
|
||||
protected JPAXMLOverriddenAnnotationReader reader;
|
||||
|
||||
protected Ejb3XmlTestCase() {
|
||||
}
|
||||
|
||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||
assertTrue(
|
||||
|
@ -45,11 +49,11 @@ abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
protected JPAOverriddenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName)
|
||||
protected JPAXMLOverriddenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName)
|
||||
throws Exception {
|
||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||
XMLContext xmlContext = getContext( ormResourceName );
|
||||
return new JPAOverriddenAnnotationReader( el, xmlContext, BootstrapContextImpl.INSTANCE );
|
||||
return new JPAXMLOverriddenAnnotationReader( el, xmlContext, BootstrapContextImpl.INSTANCE );
|
||||
}
|
||||
|
||||
protected AnnotatedElement getAnnotatedElement(Class<?> entityClass, String fieldName) throws Exception {
|
||||
|
@ -59,17 +63,19 @@ abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
|||
protected XMLContext getContext(String resourceName) throws Exception {
|
||||
InputStream is = getClass().getResourceAsStream( resourceName );
|
||||
assertNotNull( "Could not load resource " + resourceName, is );
|
||||
return getContext( is );
|
||||
return getContext( is, resourceName );
|
||||
}
|
||||
|
||||
protected XMLContext getContext(InputStream is) throws Exception {
|
||||
XMLContext xmlContext = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
SAXReader reader = new SAXReader();
|
||||
reader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-general-entities", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-parameter-entities", false );
|
||||
Document doc = reader.read( is );
|
||||
xmlContext.addDocument( doc );
|
||||
return xmlContext;
|
||||
protected XMLContext getContext(InputStream is, String resourceName) throws Exception {
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper( new XmlMappingOptions() {
|
||||
@Override
|
||||
public boolean isPreferJaxb() {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( is, resourceName );
|
||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
context.addDocument( mappings );
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,716 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AssociationOverride;
|
||||
import javax.persistence.AssociationOverrides;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlElementCollectionTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlElementCollectionTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( Column.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationNotPresent( AttributeOverrides.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationNotPresent( AssociationOverrides.class );
|
||||
assertAnnotationNotPresent( CollectionTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ElementCollection relAnno = reader.getAnnotation( ElementCollection.class );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( void.class, relAnno.targetClass() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Column.class );
|
||||
Column column = reader.getAnnotation( Column.class );
|
||||
assertEquals( "", column.name() );
|
||||
assertFalse( column.unique() );
|
||||
assertTrue( column.nullable() );
|
||||
assertTrue( column.insertable() );
|
||||
assertTrue( column.updatable() );
|
||||
assertEquals( "", column.columnDefinition() );
|
||||
assertEquals( "", column.table() );
|
||||
assertEquals( 255, column.length() );
|
||||
assertEquals( 0, column.precision() );
|
||||
assertEquals( 0, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Column.class );
|
||||
Column column = reader.getAnnotation( Column.class );
|
||||
assertEquals( "col1", column.name() );
|
||||
assertTrue( column.unique() );
|
||||
assertFalse( column.nullable() );
|
||||
assertFalse( column.insertable() );
|
||||
assertFalse( column.updatable() );
|
||||
assertEquals( "int", column.columnDefinition() );
|
||||
assertEquals( "table1", column.table() );
|
||||
assertEquals( 50, column.length() );
|
||||
assertEquals( 2, column.precision() );
|
||||
assertEquals( 1, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
Temporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
Enumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLob() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationPresent( Lob.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single attribute override, we still wrap it with an
|
||||
* AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that map-key-attribute-override and attribute-override elements
|
||||
* both end up in the AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testMixedAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col2", overrides[1].column().name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single association override, we still wrap it with an
|
||||
* AssociationOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAssociationOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationPresent( AssociationOverrides.class );
|
||||
AssociationOverrides overridesAnno = reader.getAnnotation( AssociationOverrides.class );
|
||||
AssociationOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "association1", overrides[0].name() );
|
||||
assertEquals( 0, overrides[0].joinColumns().length );
|
||||
assertEquals( "", overrides[0].joinTable().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAssociationOverridesJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationPresent( AssociationOverrides.class );
|
||||
AssociationOverrides overridesAnno = reader.getAnnotation( AssociationOverrides.class );
|
||||
AssociationOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
//First, an association using join table
|
||||
assertEquals( "association1", overrides[0].name() );
|
||||
assertEquals( 0, overrides[0].joinColumns().length );
|
||||
|
||||
JoinTable joinTableAnno = overrides[0].joinTable();
|
||||
assertEquals( "catalog1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
//JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
//InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
//UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
|
||||
//Second, an association using join columns
|
||||
assertEquals( "association2", overrides[1].name() );
|
||||
|
||||
//JoinColumns
|
||||
joinColumns = overrides[1].joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col8", joinColumns[1].name() );
|
||||
assertEquals( "col9", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table4", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( CollectionTable.class );
|
||||
CollectionTable tableAnno = reader.getAnnotation( CollectionTable.class );
|
||||
assertEquals( "", tableAnno.name() );
|
||||
assertEquals( "", tableAnno.catalog() );
|
||||
assertEquals( "", tableAnno.schema() );
|
||||
assertEquals( 0, tableAnno.joinColumns().length );
|
||||
assertEquals( 0, tableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( CollectionTable.class );
|
||||
CollectionTable tableAnno = reader.getAnnotation( CollectionTable.class );
|
||||
assertEquals( "table1", tableAnno.name() );
|
||||
assertEquals( "catalog1", tableAnno.catalog() );
|
||||
assertEquals( "schema1", tableAnno.schema() );
|
||||
|
||||
//JoinColumns
|
||||
JoinColumn[] joinColumns = tableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
//UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = tableAnno.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col3", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col4", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( Column.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationNotPresent( AttributeOverrides.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationNotPresent( AssociationOverrides.class );
|
||||
assertAnnotationNotPresent( CollectionTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ElementCollection relAnno = reader.getAnnotation( ElementCollection.class );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( Entity3.class, relAnno.targetClass() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,508 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlManyToManyTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlManyToManyTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlManyToOneTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlManyToOneTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoJoins() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Id.class );
|
||||
assertAnnotationNotPresent( MapsId.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertTrue( relAnno.optional() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Id.class );
|
||||
assertAnnotationPresent( MapsId.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertFalse( relAnno.optional() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,561 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlOneToManyTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlOneToManyTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertFalse( relAnno.orphanRemoval() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertTrue( relAnno.orphanRemoval() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,309 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlOneToOneTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlOneToOneTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( MapsId.class );
|
||||
assertAnnotationNotPresent( Id.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertTrue( relAnno.optional() );
|
||||
assertFalse( relAnno.orphanRemoval() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single primary key join column, we still wrap it with
|
||||
* a PrimaryKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSinglePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationPresent( PrimaryKeyJoinColumns.class );
|
||||
PrimaryKeyJoinColumns joinColumnsAnno =
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
PrimaryKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "int", joinColumns[0].columnDefinition() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
PrimaryKeyJoinColumns joinColumnsAnno =
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class );
|
||||
PrimaryKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationPresent( MapsId.class );
|
||||
assertAnnotationPresent( Id.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertFalse( relAnno.optional() );
|
||||
assertTrue( relAnno.orphanRemoval() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
assertEquals(
|
||||
"field3", reader.getAnnotation( MapsId.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.TeradataDialect;
|
||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
@SkipForDialect(value = {PostgreSQL81Dialect.class, PostgreSQLDialect.class, CockroachDialect.class},
|
||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
||||
@SkipForDialect(value = TeradataDialect.class,
|
||||
jiraKey = "HHH-8190",
|
||||
comment = "uses Teradata reserved word - year")
|
||||
public void testEjb3Xml() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
CarModel model = new CarModel();
|
||||
model.setYear( new Date() );
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
//s.persist( manufacturer );
|
||||
model.setManufacturer( manufacturer );
|
||||
manufacturer.getModels().add( model );
|
||||
s.persist( model );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
model.setYear( new Date() );
|
||||
manufacturer = (Manufacturer) s.get( Manufacturer.class, manufacturer.getId() );
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||
.setParameter( "manufacturer", manufacturer )
|
||||
.list();
|
||||
assertEquals( 1, cars.size() );
|
||||
for ( Model car : cars ) {
|
||||
assertNotNull( car.getManufacturer() );
|
||||
s.delete( manufacturer );
|
||||
s.delete( car );
|
||||
}
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXMLEntityHandled() throws Exception {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Lighter l = new Lighter();
|
||||
l.name = "Blue";
|
||||
l.power = "400F";
|
||||
s.persist( l );
|
||||
s.flush();
|
||||
s.getTransaction().rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlDefaultOverriding() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
s.persist( manufacturer );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapXMLSupport() throws Exception {
|
||||
Session s = openSession();
|
||||
SessionFactory sf = s.getSessionFactory();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
// Verify that we can persist an object with a couple Map mappings
|
||||
VicePresident vpSales = new VicePresident();
|
||||
vpSales.name = "Dwight";
|
||||
Company company = new Company();
|
||||
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
||||
company.organization.put( "sales", vpSales );
|
||||
s.persist( company );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
// For the element-collection, check that the orm.xml entries are honored.
|
||||
// This includes: map-key-column/column/collection-table/join-column
|
||||
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf.getCollectionMetadata( Company.class.getName() + ".conferenceRoomExtensions" );
|
||||
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
||||
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
CarModel.class,
|
||||
Manufacturer.class,
|
||||
Model.class,
|
||||
Light.class
|
||||
//Lighter.class xml only entuty
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return new String[] {
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm2.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm3.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm4.xml"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test superclass to provide utility methods for testing the mapping of JPA
|
||||
* XML to JPA annotations. The configuration is built within each test, and no
|
||||
* database is used. Thus, no schema generation or cleanup will be performed.
|
||||
* <p>
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
abstract class LegacyEjb3XmlTestCase extends BaseUnitTestCase {
|
||||
protected JPAOverriddenAnnotationReader reader;
|
||||
|
||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||
assertTrue(
|
||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||
reader.isAnnotationPresent( annotationType )
|
||||
);
|
||||
}
|
||||
|
||||
protected void assertAnnotationNotPresent(Class<? extends Annotation> annotationType) {
|
||||
assertFalse(
|
||||
"Unexpected annotation " + annotationType.getSimpleName() + " was present",
|
||||
reader.isAnnotationPresent( annotationType )
|
||||
);
|
||||
}
|
||||
|
||||
protected JPAOverriddenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName)
|
||||
throws Exception {
|
||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||
XMLContext xmlContext = getContext( ormResourceName );
|
||||
return new JPAOverriddenAnnotationReader( el, xmlContext, BootstrapContextImpl.INSTANCE );
|
||||
}
|
||||
|
||||
protected AnnotatedElement getAnnotatedElement(Class<?> entityClass, String fieldName) throws Exception {
|
||||
return entityClass.getDeclaredField( fieldName );
|
||||
}
|
||||
|
||||
protected XMLContext getContext(String resourceName) throws Exception {
|
||||
InputStream is = getClass().getResourceAsStream( resourceName );
|
||||
assertNotNull( "Could not load resource " + resourceName, is );
|
||||
return getContext( is );
|
||||
}
|
||||
|
||||
protected XMLContext getContext(InputStream is) throws Exception {
|
||||
XMLContext xmlContext = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
SAXReader reader = new SAXReader();
|
||||
reader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-general-entities", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-parameter-entities", false );
|
||||
Document doc = reader.read( is );
|
||||
xmlContext.addDocument( doc );
|
||||
return xmlContext;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import org.hibernate.InvalidMappingException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.NonExistentOrmVersionTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
public class LegacyNonExistentOrmVersionTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testNonExistentOrmVersion() {
|
||||
try {
|
||||
new MetadataSources()
|
||||
.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" )
|
||||
.buildMetadata();
|
||||
fail( "Expecting failure due to unsupported xsd version" );
|
||||
}
|
||||
catch ( InvalidMappingException expected ) {
|
||||
}
|
||||
catch ( UnsupportedOrmXsdVersionException expected ) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.OrmVersion1SupportedTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
public class LegacyOrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
ErrorLogger.class.getName()
|
||||
)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testOrm1Support() {
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH00196" );
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Light light = new Light();
|
||||
light.name = "the light at the end of the tunnel";
|
||||
s.persist( light );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "find.the.light" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getOrmXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/xml/ejb3/orm2.xml" };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.xml.ejb3.PreParsedOrmXmlTest.NonAnnotatedEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.PreParsedOrmXmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14530")
|
||||
public class LegacyPreParsedOrmXmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addMappings(Configuration configuration) {
|
||||
super.addMappings( configuration );
|
||||
try (InputStream xmlStream = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream( "org/hibernate/test/annotations/xml/ejb3/pre-parsed-orm.xml" )) {
|
||||
Binding<?> parsed = configuration.getXmlMappingBinderAccess().bind( xmlStream );
|
||||
configuration.addXmlMapping( parsed );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreParsedOrmXml() {
|
||||
// Just check that the entity can be persisted, which means the mapping file was taken into account
|
||||
NonAnnotatedEntity persistedEntity = new NonAnnotatedEntity( "someName" );
|
||||
inTransaction( s -> s.persist( persistedEntity ) );
|
||||
inTransaction( s -> {
|
||||
NonAnnotatedEntity retrievedEntity = s.find( NonAnnotatedEntity.class, persistedEntity.getId() );
|
||||
assertThat( retrievedEntity ).extracting( NonAnnotatedEntity::getName )
|
||||
.isEqualTo( persistedEntity.getName() );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -8,7 +8,9 @@ package org.hibernate.test.annotations.xml.ejb3;
|
|||
|
||||
import org.hibernate.InvalidMappingException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||
import org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
@ -16,12 +18,14 @@ import org.junit.Test;
|
|||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
@TestForIssue(jiraKey = {"HHH-6271", "HHH-14529"})
|
||||
public class NonExistentOrmVersionTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testNonExistentOrmVersion() {
|
||||
try {
|
||||
new MetadataSources()
|
||||
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
XmlMappingOptionsStrategyRegistrationProvider.applyJaxbStrategy( builder );
|
||||
new MetadataSources( builder.build() )
|
||||
.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" )
|
||||
.buildMetadata();
|
||||
fail( "Expecting failure due to unsupported xsd version" );
|
||||
|
|
|
@ -8,8 +8,10 @@ package org.hibernate.test.annotations.xml.ejb3;
|
|||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
@ -23,9 +25,15 @@ import org.jboss.logging.Logger;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
@TestForIssue(jiraKey = {"HHH-6271", "HHH-14529"})
|
||||
public class OrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
XmlMappingOptionsStrategyRegistrationProvider.applyJaxbStrategy( builder );
|
||||
}
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
Logger.getMessageLogger(
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.ejb3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@TestForIssue(jiraKey = {"HHH-14530", "HHH-14529"})
|
||||
public class PreParsedOrmXmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
||||
super.prepareBootstrapRegistryBuilder( builder );
|
||||
XmlMappingOptionsStrategyRegistrationProvider.applyJaxbStrategy( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMappings(Configuration configuration) {
|
||||
super.addMappings( configuration );
|
||||
try (InputStream xmlStream = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream( "org/hibernate/test/annotations/xml/ejb3/pre-parsed-orm.xml" )) {
|
||||
Binding<?> parsed = configuration.getXmlMappingBinderAccess().bind( xmlStream );
|
||||
configuration.addXmlMapping( parsed );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreParsedOrmXml() {
|
||||
// Just check that the entity can be persisted, which means the mapping file was taken into account
|
||||
NonAnnotatedEntity persistedEntity = new NonAnnotatedEntity( "someName" );
|
||||
inTransaction( s -> s.persist( persistedEntity ) );
|
||||
inTransaction( s -> {
|
||||
NonAnnotatedEntity retrievedEntity = s.find( NonAnnotatedEntity.class, persistedEntity.getId() );
|
||||
assertThat( retrievedEntity ).extracting( NonAnnotatedEntity::getName )
|
||||
.isEqualTo( persistedEntity.getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
public static class NonAnnotatedEntity {
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public NonAnnotatedEntity() {
|
||||
}
|
||||
|
||||
public NonAnnotatedEntity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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.test.annotations.xml.hbm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14530")
|
||||
public class PreParsedHbmXmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addMappings(Configuration configuration) {
|
||||
super.addMappings( configuration );
|
||||
try (InputStream xmlStream = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream( "org/hibernate/test/annotations/xml/hbm/pre-parsed-hbm.xml" )) {
|
||||
Binding<?> parsed = configuration.getXmlMappingBinderAccess().bind( xmlStream );
|
||||
configuration.addXmlMapping( parsed );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreParsedHbmXml() {
|
||||
// Just check that the entity can be persisted, which means the mapping file was taken into account
|
||||
NonAnnotatedEntity persistedEntity = new NonAnnotatedEntity( "someName" );
|
||||
inTransaction( s -> s.persist( persistedEntity ) );
|
||||
inTransaction( s -> {
|
||||
NonAnnotatedEntity retrievedEntity = s.find( NonAnnotatedEntity.class, persistedEntity.getId() );
|
||||
assertThat( retrievedEntity ).extracting( NonAnnotatedEntity::getName )
|
||||
.isEqualTo( persistedEntity.getName() );
|
||||
} );
|
||||
}
|
||||
|
||||
public static class NonAnnotatedEntity {
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public NonAnnotatedEntity() {
|
||||
}
|
||||
|
||||
public NonAnnotatedEntity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
version="1.0"
|
||||
>
|
||||
<table-generator name="EMP_GEN" table="GENERATOR_TABLE"
|
||||
pk-column-name="pkey" pk-column-value="EMP"
|
||||
value-column-name="hi" allocation-size="20"/>
|
||||
</entity-mappings>
|
|
@ -110,11 +110,11 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest
|
|||
@Test
|
||||
@TestForIssue(jiraKey = {"HHH-13976", "HHH-14326"})
|
||||
public void testResourcesReleasedThenConnectionClosedThenCommit() throws SQLException, XAException {
|
||||
try (SessionImplementor s = (SessionImplementor) openSession()) {
|
||||
XAResource transactionSpy = mock( XAResource.class );
|
||||
Connection[] connectionSpies = new Connection[1];
|
||||
Statement statementMock = Mockito.mock( Statement.class );
|
||||
|
||||
try (SessionImplementor s = (SessionImplementor) openSession()) {
|
||||
TransactionUtil2.inTransaction( s, session -> {
|
||||
spyOnTransaction( transactionSpy );
|
||||
|
||||
|
@ -126,7 +126,9 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest
|
|||
logicalConnection.getResourceRegistry().register( statementMock, true );
|
||||
connectionSpies[0] = logicalConnection.getPhysicalConnection();
|
||||
} );
|
||||
}
|
||||
|
||||
// Note: all this must happen BEFORE the session is closed;
|
||||
// it's particularly important when reusing the session.
|
||||
|
||||
Connection connectionSpy = connectionSpies[0];
|
||||
|
||||
|
@ -135,7 +137,51 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest
|
|||
inOrder.verify( statementMock ).close();
|
||||
inOrder.verify( connectionSpy ).close();
|
||||
inOrder.verify( transactionSpy ).commit( any(), anyBoolean() );
|
||||
Mockito.reset( connectionSpy );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = {"HHH-14557"})
|
||||
public void testResourcesReleasedThenConnectionClosedOnEachRollback() throws SQLException {
|
||||
try (SessionImplementor s = (SessionImplementor) openSession()) {
|
||||
Connection[] connectionSpies = new Connection[1];
|
||||
Statement statementMock = Mockito.mock( Statement.class );
|
||||
RuntimeException rollbackException = new RuntimeException("Rollback");
|
||||
|
||||
try {
|
||||
TransactionUtil2.inTransaction( s, session -> {
|
||||
Thing thing = new Thing();
|
||||
thing.setId( 1 );
|
||||
session.persist( thing );
|
||||
|
||||
LogicalConnectionImplementor logicalConnection = session.getJdbcCoordinator().getLogicalConnection();
|
||||
logicalConnection.getResourceRegistry().register( statementMock, true );
|
||||
connectionSpies[0] = logicalConnection.getPhysicalConnection();
|
||||
|
||||
throw rollbackException;
|
||||
} );
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if ( e != rollbackException ) {
|
||||
throw e;
|
||||
}
|
||||
// Else: ignore, that was expected.
|
||||
}
|
||||
|
||||
// Note: all this must happen BEFORE the session is closed;
|
||||
// it's particularly important when reusing the session.
|
||||
|
||||
Connection connectionSpy = connectionSpies[0];
|
||||
|
||||
// Must close the resources, then the connection
|
||||
InOrder inOrder = inOrder( statementMock, connectionSpy );
|
||||
inOrder.verify( statementMock ).close();
|
||||
inOrder.verify( connectionSpy ).close();
|
||||
// We don't check the relative ordering of the rollback here,
|
||||
// because unfortunately we know it's wrong:
|
||||
// we don't get a "before transaction completion" event for rollbacks,
|
||||
// so in the case of rollbacks the closing always happen after transaction completion.
|
||||
}
|
||||
}
|
||||
|
||||
private void spyOnTransaction(XAResource xaResource) {
|
||||
|
|
|
@ -48,15 +48,16 @@ import static org.junit.Assert.fail;
|
|||
public class SQLServerDialectCollationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildSessionFactory() {
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() );
|
||||
StandardServiceRegistryImpl _serviceRegistry =
|
||||
buildServiceRegistry( bootRegistry, constructAndConfigureConfiguration( bootRegistry ) );
|
||||
|
||||
try {
|
||||
try {
|
||||
|
|
|
@ -43,10 +43,9 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe
|
|||
private boolean collationChanged;
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +55,7 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe
|
|||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry(
|
||||
bootRegistry,
|
||||
constructConfiguration()
|
||||
constructAndConfigureConfiguration( bootRegistry )
|
||||
);
|
||||
try {
|
||||
TransactionUtil.doWithJDBC(
|
||||
|
@ -92,7 +91,8 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe
|
|||
@Override
|
||||
protected void buildSessionFactory() {
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() );
|
||||
StandardServiceRegistryImpl serviceRegistry =
|
||||
buildServiceRegistry( bootRegistry, constructAndConfigureConfiguration( bootRegistry ) );
|
||||
|
||||
try {
|
||||
try {
|
||||
|
|
|
@ -24,10 +24,9 @@ public class TenantResolverConfigurationTest extends BaseCoreFunctionalTestCase
|
|||
private TestCurrentTenantIdentifierResolver currentTenantResolver = new TestCurrentTenantIdentifierResolver();
|
||||
|
||||
@Override
|
||||
protected Configuration constructAndConfigureConfiguration() {
|
||||
Configuration configuration = super.constructAndConfigureConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setCurrentTenantIdentifierResolver( currentTenantResolver );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
org.hibernate.internal.util.xml.XmlMappingOptionsStrategyRegistrationProvider
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
<entity-mappings
|
||||
xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
version="2.0">
|
||||
|
||||
<entity class="org.hibernate.test.annotations.xml.ejb3.PreParsedOrmXmlTest$NonAnnotatedEntity" name="NonAnnotated">
|
||||
<attributes>
|
||||
<id name="id">
|
||||
<generated-value strategy="IDENTITY"/>
|
||||
</id>
|
||||
<basic name="name">
|
||||
<column name="thename"/>
|
||||
</basic>
|
||||
</attributes>
|
||||
</entity>
|
||||
</entity-mappings>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="org.hibernate.test.annotations.xml.hbm.PreParsedHbmXmlTest$NonAnnotatedEntity" table="NonAnnotated">
|
||||
<id name="id">
|
||||
<generator class="identity"/>
|
||||
</id>
|
||||
<property name="name" column="thename"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -33,13 +33,12 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
Class<? extends MultiTableBulkIdStrategy> strategyClass = getMultiTableBulkIdStrategyClass();
|
||||
if ( strategyClass != null ) {
|
||||
configuration.setProperty( AvailableSettings.QUERY_MULTI_TABLE_MUTATION_STRATEGY, strategyClass.getName() );
|
||||
configuration.setProperty( AvailableSettings.HQL_BULK_ID_STRATEGY, strategyClass.getName() );
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
protected abstract Class<? extends MultiTableBulkIdStrategy> getMultiTableBulkIdStrategyClass();
|
||||
|
|
|
@ -32,12 +32,13 @@ public abstract class AbstractBulkIdTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
configuration.setProperty( AvailableSettings.QUERY_MULTI_TABLE_MUTATION_STRATEGY, getMultiTableBulkIdStrategyClass().getName() );
|
||||
return configuration;
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.HQL_BULK_ID_STRATEGY, getMultiTableBulkIdStrategyClass().getName() );
|
||||
}
|
||||
|
||||
|
||||
protected abstract Class<? extends MultiTableBulkIdStrategy> getMultiTableBulkIdStrategyClass();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,12 +24,15 @@ 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.jaxb.spi.XmlMappingOptions;
|
||||
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.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
@ -40,6 +43,8 @@ import org.dom4j.DocumentException;
|
|||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.XML_MAPPING_ENABLED;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -52,7 +57,8 @@ public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingP
|
|||
IndexView jandexIndex,
|
||||
final MappingBinder mappingBinder,
|
||||
final MetadataBuildingContext buildingContext) {
|
||||
final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
|
||||
MetadataBuildingOptions metadataBuildingOptions = metadata.getMetadataBuildingOptions();
|
||||
final ServiceRegistry serviceRegistry = metadataBuildingOptions.getServiceRegistry();
|
||||
final EnversService enversService = serviceRegistry.getService( EnversService.class );
|
||||
|
||||
if ( !enversService.isEnabled() ) {
|
||||
|
@ -60,6 +66,12 @@ public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingP
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if ( !metadataBuildingOptions.getXmlMappingOptions().isEnabled() ) {
|
||||
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<MappingDocument> additionalMappingDocuments = new ArrayList<>();
|
||||
|
||||
// atm we do not have distinct origin info for envers
|
||||
|
|
|
@ -9,14 +9,11 @@ package org.hibernate.envers.boot.internal;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
|
||||
import org.hibernate.envers.configuration.internal.EntitiesConfigurator;
|
||||
import org.hibernate.envers.configuration.internal.GlobalConfiguration;
|
||||
|
@ -39,8 +36,6 @@ import org.hibernate.service.spi.Stoppable;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.XML_MAPPING_ENABLED;
|
||||
|
||||
/**
|
||||
* Provides central access to Envers' configuration.
|
||||
*
|
||||
|
@ -89,10 +84,6 @@ public class EnversServiceImpl implements EnversService, Configurable, Stoppable
|
|||
);
|
||||
}
|
||||
this.integrationEnabled = ConfigurationHelper.getBoolean( INTEGRATION_ENABLED, configurationValues, true );
|
||||
boolean xmlMappingEnabled = ConfigurationHelper.getBoolean( XML_MAPPING_ENABLED, configurationValues, true );
|
||||
if ( this.integrationEnabled && !xmlMappingEnabled ) {
|
||||
throw new HibernateException( "Hibernate Envers currently requires XML mapping to be enabled. Please don't disable setting `" + XML_MAPPING_ENABLED + "`; alternatively disable Hibernate Envers." );
|
||||
}
|
||||
|
||||
log.infof( "Envers integration enabled? : %s", integrationEnabled );
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.ByteOrder;
|
||||
|
@ -39,7 +41,7 @@ import org.postgresql.util.PGobject;
|
|||
public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
|
||||
|
||||
final private Wkb.Dialect wkbDialect;
|
||||
private final Wkb.Dialect wkbDialect;
|
||||
|
||||
// Type descriptor instance using EWKB v1 (postgis versions < 2.2.2)
|
||||
public static final PGGeometryTypeDescriptor INSTANCE_WKB_1 = new PGGeometryTypeDescriptor( Wkb.Dialect.POSTGIS_EWKB_1 );
|
||||
|
@ -79,7 +81,7 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
return Types.OTHER;
|
||||
return 5432;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,8 +124,8 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
|
||||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getObject( name ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -113,11 +113,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
protected void buildSessionFactory(Consumer<Configuration> configurationAdapter) {
|
||||
// for now, build the configuration to get all the property settings
|
||||
configuration = constructAndConfigureConfiguration();
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
configuration = constructAndConfigureConfiguration( bootRegistry );
|
||||
if ( configurationAdapter != null ) {
|
||||
configurationAdapter.accept(configuration);
|
||||
}
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
afterConstructAndConfigureConfiguration( configuration );
|
||||
|
@ -146,14 +146,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
buildSessionFactory( configurationAdapter );
|
||||
}
|
||||
|
||||
protected Configuration buildConfiguration() {
|
||||
Configuration cfg = constructAndConfigureConfiguration();
|
||||
afterConstructAndConfigureConfiguration( cfg );
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected Configuration constructAndConfigureConfiguration() {
|
||||
Configuration cfg = constructConfiguration();
|
||||
protected Configuration constructAndConfigureConfiguration(BootstrapServiceRegistry bootstrapServiceRegistry) {
|
||||
Configuration cfg = constructConfiguration( bootstrapServiceRegistry );
|
||||
configure( cfg );
|
||||
return cfg;
|
||||
}
|
||||
|
@ -164,8 +158,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
afterConfigurationBuilt( cfg );
|
||||
}
|
||||
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = new Configuration();
|
||||
protected Configuration constructConfiguration(BootstrapServiceRegistry bootstrapServiceRegistry) {
|
||||
Configuration configuration = new Configuration( bootstrapServiceRegistry );
|
||||
configuration.setProperty( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
if ( createSchema() ) {
|
||||
|
|
Loading…
Reference in New Issue