diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableMappingType.java index f84b831a4d..e81d71abf1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableMappingType.java @@ -17,15 +17,19 @@ import java.util.function.Consumer; import java.util.function.Function; import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; +import org.hibernate.mapping.ToOne; import org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; +import org.hibernate.metamodel.mapping.internal.SingularAssociationAttributeMapping; import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.NavigablePath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.tree.from.TableGroup; @@ -34,7 +38,9 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.type.BasicType; +import org.hibernate.type.CollectionType; import org.hibernate.type.CompositeType; +import org.hibernate.type.EntityType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; @@ -114,7 +120,8 @@ public class EmbeddableMappingType implements ManagedMappingType { while ( propertyIterator.hasNext() ) { final Property bootPropertyDescriptor = propertyIterator.next(); - if ( subtypes[ attributeIndex ] instanceof BasicType ) { + final Type subtype = subtypes[attributeIndex]; + if ( subtype instanceof BasicType ) { attributeMappings.put( bootPropertyDescriptor.getName(), MappingModelCreationHelper.buildBasicAttributeMapping( @@ -122,7 +129,7 @@ public class EmbeddableMappingType implements ManagedMappingType { attributeIndex, bootPropertyDescriptor, this, - (BasicType) subtypes[ attributeIndex ], + (BasicType) subtype, containingTableExpression, mappedColumnExpressions.get( columnPosition++ ), representationStrategy.resolvePropertyAccess( bootPropertyDescriptor ), @@ -131,8 +138,8 @@ public class EmbeddableMappingType implements ManagedMappingType { ) ); } - else if ( subtypes[ attributeIndex ] instanceof CompositeType ) { - final CompositeType subCompositeType = (CompositeType) subtypes[ attributeIndex ]; + else if ( subtype instanceof CompositeType ) { + final CompositeType subCompositeType = (CompositeType) subtype; final int columnSpan = subCompositeType.getColumnSpan( creationProcess.getCreationContext().getSessionFactory() ); attributeMappings.put( @@ -153,6 +160,53 @@ public class EmbeddableMappingType implements ManagedMappingType { columnPosition += columnSpan; } + else { + final EntityPersister entityPersister = creationProcess + .getEntityPersister( bootDescriptor.getOwner().getEntityName() ); + if ( subtype instanceof CollectionType ) { + attributeMappings.put( + bootPropertyDescriptor.getName(), + MappingModelCreationHelper.buildPluralAttributeMapping( + bootPropertyDescriptor.getName(), + attributeIndex, + bootPropertyDescriptor, + entityPersister, + representationStrategy.resolvePropertyAccess( bootPropertyDescriptor ), + compositeType.getCascadeStyle( attributeIndex), + compositeType.getFetchMode( attributeIndex ), + creationProcess + ) + ); + } + else if ( subtype instanceof EntityType ) { + final Dialect dialect = creationProcess.getCreationContext() + .getSessionFactory() + .getJdbcServices() + .getDialect(); + + final SingularAssociationAttributeMapping singularAssociationAttributeMapping = MappingModelCreationHelper.buildSingularAssociationAttributeMapping( + bootPropertyDescriptor.getName(), + attributeIndex, + bootPropertyDescriptor, + entityPersister, + (EntityType) subtype, + getRepresentationStrategy().resolvePropertyAccess( bootPropertyDescriptor ), + compositeType.getCascadeStyle( attributeIndex ), + creationProcess + ); + MappingModelCreationHelper.interpretKeyDescriptor( + singularAssociationAttributeMapping, + bootPropertyDescriptor, + (ToOne) bootPropertyDescriptor.getValue(), + entityPersister, + dialect, + creationProcess + ); + attributeMappings.put( bootPropertyDescriptor.getName(), singularAssociationAttributeMapping ); + // todo (6.0) : not sure it is always correct + columnPosition++; + } + } attributeIndex++; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java index 0517cb1a39..3db657a10f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java @@ -16,6 +16,7 @@ import org.hibernate.engine.FetchStrategy; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer; import org.hibernate.sql.ast.tree.from.TableReferenceJoin; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; @@ -246,13 +247,14 @@ public class EmbeddedAttributeMapping lhs ); - lhs.addTableGroupJoin( new TableGroupJoin( navigablePath, SqlAstJoinType.INNER, compositeTableGroup, null ) ); - - return new TableGroupJoin( + TableGroupJoin tableGroupJoin = new TableGroupJoin( navigablePath, sqlAstJoinType, compositeTableGroup ); + lhs.addTableGroupJoin( tableGroupJoin ); + + return tableGroupJoin; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 54f0ee3c0a..9c8c4c2a09 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -13,6 +13,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.function.Consumer; +import org.hibernate.FetchMode; import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.NotYetImplementedFor6Exception; @@ -679,6 +680,7 @@ public class MappingModelCreationHelper { ManagedMappingType declaringType, PropertyAccess propertyAccess, CascadeStyle cascadeStyle, + FetchMode fetchMode, MappingModelCreationProcess creationProcess) { final Collection bootValueMapping = (Collection) bootProperty.getValue(); @@ -873,7 +875,7 @@ public class MappingModelCreationHelper { }; final FetchStyle style = FetchStrategyHelper.determineFetchStyleByMetadata( - ( (OuterJoinLoadable) declaringType ).getFetchMode( stateArrayPosition ), + fetchMode, collectionDescriptor.getCollectionType(), sessionFactory ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SingularAssociationAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SingularAssociationAttributeMapping.java index 87d7e65885..161e33ba11 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SingularAssociationAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SingularAssociationAttributeMapping.java @@ -140,8 +140,6 @@ public class SingularAssociationAttributeMapping extends AbstractSingularAttribu creationState.getSqlAstCreationState().getCreationContext() ); - lhsTableGroup.addTableGroupJoin( tableGroupJoin ); - sqlAstCreationState.getFromClauseAccess().registerTableGroup( fetchablePath, tableGroupJoin.getJoinedGroup() @@ -327,18 +325,22 @@ public class SingularAssociationAttributeMapping extends AbstractSingularAttribu .getFromClauseAccess() .findTableGroup( parentParentNavigablePath ) .getModelPart(); -// final SingularAssociationAttributeMapping part = (SingularAssociationAttributeMapping) modelPart -// .findSubPart( panentNaviblePath.getLocalName(), null ); - final EntityAssociationMapping part = (EntityAssociationMapping) modelPart.findSubPart( panentNaviblePath.getLocalName(), null ); - if ( panentNaviblePath.getLocalName().equals( referencedPropertyName ) - && part.getFetchableName().equals( referencedPropertyName ) ) { - return true; + final ModelPart subPart = modelPart.findSubPart( panentNaviblePath.getLocalName(), null ); + if ( subPart instanceof EntityAssociationMapping ) { + final EntityAssociationMapping part = (EntityAssociationMapping) subPart; + + if ( panentNaviblePath.getLocalName().equals( referencedPropertyName ) + && part.getFetchableName().equals( referencedPropertyName ) ) { + return true; + } + else if ( part.getKeyTargetMatchPart() != null + && part.getKeyTargetMatchPart().getPartName().equals( getAttributeName() ) ) { + return true; + } } - else if ( part.getKeyTargetMatchPart() != null -// && part.getKeyTargetMatchPart().equals( this ) ) { - && part.getKeyTargetMatchPart().getPartName().equals( getAttributeName() ) ) { - return true; + else { + return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index f853ee2750..e7c260743b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -5824,7 +5824,6 @@ public abstract class AbstractEntityPersister final Dialect dialect = creationProcess.getCreationContext() .getSessionFactory() .getJdbcServices() - .getJdbcEnvironment() .getDialect(); MappingModelCreationHelper.interpretKeyDescriptor( @@ -5836,6 +5835,8 @@ public abstract class AbstractEntityPersister creationProcess ); } ); + + singularAssociationsToFinilize.clear(); } protected static SqmMultiTableMutationStrategy interpretSqmMultiTableStrategy( @@ -6063,6 +6064,7 @@ public abstract class AbstractEntityPersister this, propertyAccess, tupleAttrDefinition.getCascadeStyle(), + getFetchMode( stateArrayPosition ), creationProcess ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstWalker.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstWalker.java index 46bededc4f..942f131622 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstWalker.java @@ -370,10 +370,8 @@ public abstract class AbstractSqlAstWalker protected void processTableGroupJoin(TableGroupJoin tableGroupJoin) { final TableGroup joinedGroup = tableGroupJoin.getJoinedGroup(); - //noinspection StatementWithEmptyBody if ( joinedGroup instanceof VirtualTableGroup ) { - // nothing to do - // todo (6.0) : join predicates? + processTableGroupJoins( tableGroupJoin.getJoinedGroup()); } else { appendSql( EMPTY_STRING ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java index bfcd7e49e4..f5f91241e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java @@ -10,6 +10,7 @@ import java.util.IdentityHashMap; import java.util.Map; import java.util.function.Consumer; +import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMapping; @@ -48,11 +49,12 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA this.embeddedModelPartDescriptor = resultDescriptor.getReferencedMappingContainer(); this.fetchParentAccess = fetchParentAccess; - final int numOfAttrs = embeddedModelPartDescriptor.getEmbeddableTypeDescriptor().getNumberOfAttributeMappings(); + final EmbeddableMappingType embeddableTypeDescriptor = embeddedModelPartDescriptor.getEmbeddableTypeDescriptor(); + final int numOfAttrs = embeddableTypeDescriptor.getNumberOfAttributeMappings(); this.resolvedValues = new Object[ numOfAttrs ]; this.assemblerMap = new IdentityHashMap<>( numOfAttrs ); - this.embeddedModelPartDescriptor.getEmbeddableTypeDescriptor().visitStateArrayContributors( + embeddableTypeDescriptor.visitStateArrayContributors( stateArrayContributor -> { final Fetch fetch = resultDescriptor.findFetch( stateArrayContributor.getFetchableName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Addr.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Addr.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Addr.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Addr.java index 3f19735cb5..cfb4ee4317 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Addr.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Addr.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Address.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Address.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Address.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Address.java index 11ee8eb0b3..668f0133e6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Address.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Address.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import javax.persistence.Embeddable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideSchemaTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideSchemaTest.java index 47ae8569fa..23a62394a2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideSchemaTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; import org.hibernate.dialect.H2Dialect; import org.hibernate.mapping.Table; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideTest.java new file mode 100644 index 0000000000..5c2a7e6ff6 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AssociationOverrideTest.java @@ -0,0 +1,150 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.annotations.override; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.persistence.PersistenceException; + +import org.hibernate.Transaction; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.AvailableSettings; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.test.util.SchemaUtil; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * @author Emmanuel Bernard + */ +@DomainModel( + annotatedClasses = { + Employee.class, + Location.class, + Move.class, + Trip.class, + PhoneNumber.class, + Addr.class, + SocialSite.class, + SocialTouchPoints.class + } +) +@ServiceRegistry(settings = { + @ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-jpa") +}) +@SessionFactory +public class AssociationOverrideTest { + + @Test + public void testOverriding(SessionFactoryScope scope) { + Location paris = new Location(); + paris.setName( "Paris" ); + Location atlanta = new Location(); + atlanta.setName( "Atlanta" ); + Trip trip = new Trip(); + trip.setFrom( paris ); + //trip.setTo( atlanta ); + scope.inSession( + session -> { + Transaction tx = session.beginTransaction(); + session.persist( paris ); + session.persist( atlanta ); + try { + session.persist( trip ); + session.flush(); + fail( "Should be non nullable" ); + } + catch (PersistenceException e) { + //success + } + finally { + tx.rollback(); + } + } + ); + } + + + @Test + public void testSchemaCreation(SessionFactoryScope scope) { + final MetadataImplementor metadata = scope.getMetadataImplementor(); + + assertTrue( SchemaUtil.isTablePresent( "Employee", metadata ) ); + assertTrue( + "Overridden @JoinColumn fails", + SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", metadata ) + ); + + assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", metadata ) ); + assertTrue( + "Overridden @JoinTable with default @JoinColumn fails", + SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", metadata ) + ); + assertTrue( + "Overridden @JoinTable.inverseJoinColumn fails", + SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", metadata ) + ); + } + + @Test + public void testDottedNotation(SessionFactoryScope scope) { + scope.inSession( + session -> { + Transaction tx = session.beginTransaction(); + try { + ContactInfo ci = new ContactInfo(); + Addr address = new Addr(); + address.setCity( "Boston" ); + address.setCountry( "USA" ); + address.setState( "MA" ); + address.setStreet( "27 School Street" ); + address.setZipcode( "02108" ); + ci.setAddr( address ); + List phoneNumbers = new ArrayList(); + PhoneNumber num = new PhoneNumber(); + num.setNumber( 5577188 ); + Employee e = new Employee(); + Collection employeeList = new ArrayList(); + employeeList.add( e ); + e.setContactInfo( ci ); + num.setEmployees( employeeList ); + phoneNumbers.add( num ); + ci.setPhoneNumbers( phoneNumbers ); + SocialTouchPoints socialPoints = new SocialTouchPoints(); + List sites = new ArrayList<>(); + SocialSite site = new SocialSite(); + site.setEmployee( employeeList ); + site.setWebsite( "www.jboss.org" ); + sites.add( site ); + socialPoints.setWebsite( sites ); + ci.setSocial( socialPoints ); + session.persist( e ); + tx.commit(); + + tx.begin(); + session.clear(); + session.get( Employee.class, e.getId() ); + tx.commit(); + } + catch (Exception e) { + if ( tx != null && tx.isActive() ) { + tx.rollback(); + } + throw e; + } + } + ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AttributeOverrideTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AttributeOverrideTest.java index 584c458901..04706f93db 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/AttributeOverrideTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.test.util.SchemaUtil; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/BlogEntry.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/BlogEntry.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/BlogEntry.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/BlogEntry.java index 8194b56bba..91193af528 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/BlogEntry.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/BlogEntry.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; import javax.persistence.AssociationOverride; import javax.persistence.AttributeOverride; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/ContactInfo.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/ContactInfo.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/ContactInfo.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/ContactInfo.java index 37e2c7eeb6..a91db63d29 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/ContactInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/ContactInfo.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Employee.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Employee.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Employee.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Employee.java index 38aacdd6f1..8aae984022 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Employee.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Employee.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import javax.persistence.AssociationOverride; import javax.persistence.AssociationOverrides; import javax.persistence.Embedded; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Entry.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Entry.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Entry.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Entry.java index d56a33bf85..357ef4af58 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Entry.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Entry.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; import java.io.Serializable; import java.util.HashSet; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/InheritedAttributeOverridingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/InheritedAttributeOverridingTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/InheritedAttributeOverridingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/InheritedAttributeOverridingTest.java index e124222b13..b947f6f4d5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/InheritedAttributeOverridingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/InheritedAttributeOverridingTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; import javax.persistence.Entity; import javax.persistence.Id; @@ -19,6 +19,7 @@ import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.testing.FailureExpected; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.testing.orm.junit.DomainModel; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Location.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Location.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Location.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Location.java index c9bc3234a0..cfc2e612cb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Location.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Location.java @@ -4,9 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ +package org.hibernate.orm.test.annotations.override; -//$Id$ -package org.hibernate.test.annotations.override; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Move.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Move.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Move.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Move.java index 1057c72fd1..594416653b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Move.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Move.java @@ -4,9 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ +package org.hibernate.orm.test.annotations.override; -//$Id$ -package org.hibernate.test.annotations.override; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PhoneNumber.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PhoneNumber.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/PhoneNumber.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PhoneNumber.java index c2ab4ba597..035d7bca01 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PhoneNumber.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PhoneNumber.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.util.Collection; import javax.persistence.CascadeType; import javax.persistence.Column; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyInfo.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyInfo.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyInfo.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyInfo.java index e9f291babe..70fe56ba27 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyInfo.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.math.BigDecimal; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyRecord.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyRecord.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyRecord.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyRecord.java index cf49b85a90..a532039e17 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/PropertyRecord.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/PropertyRecord.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.util.Map; import java.util.Set; import javax.persistence.AttributeOverride; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialSite.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialSite.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialSite.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialSite.java index 3d420808dd..069fc6f22c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialSite.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialSite.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.util.Collection; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialTouchPoints.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialTouchPoints.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialTouchPoints.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialTouchPoints.java index 7b0940e425..12ef5f24ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/SocialTouchPoints.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/SocialTouchPoints.java @@ -4,7 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.annotations.override; +package org.hibernate.orm.test.annotations.override; + import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Trip.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Trip.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/override/Trip.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Trip.java index e9021abac7..7a655a9684 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/Trip.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/Trip.java @@ -4,9 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ +package org.hibernate.orm.test.annotations.override; -//$Id$ -package org.hibernate.test.annotations.override; import javax.persistence.AssociationOverride; import javax.persistence.AssociationOverrides; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java deleted file mode 100644 index 2691e83023..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.annotations.override; - -import javax.persistence.PersistenceException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.boot.MetadataBuilder; -import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; - -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.test.util.SchemaUtil; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Emmanuel Bernard - */ -public class AssociationOverrideTest extends BaseNonConfigCoreFunctionalTestCase { - @Test - public void testOverriding() throws Exception { - Location paris = new Location(); - paris.setName( "Paris" ); - Location atlanta = new Location(); - atlanta.setName( "Atlanta" ); - Trip trip = new Trip(); - trip.setFrom( paris ); - //trip.setTo( atlanta ); - Session s = openSession(); - Transaction tx = s.beginTransaction(); - s.persist( paris ); - s.persist( atlanta ); - try { - s.persist( trip ); - s.flush(); - fail( "Should be non nullable" ); - } - catch (PersistenceException e) { - //success - } - finally { - tx.rollback(); - s.close(); - } - } - - @Test - public void testDottedNotation() throws Exception { - assertTrue( SchemaUtil.isTablePresent( "Employee", metadata() ) ); - assertTrue( "Overridden @JoinColumn fails", - SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", metadata() ) ); - - assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", metadata() ) ); - assertTrue( "Overridden @JoinTable with default @JoinColumn fails", - SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", metadata() ) ); - assertTrue( "Overridden @JoinTable.inverseJoinColumn fails", - SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", metadata() ) ); - - Session s = openSession(); - Transaction tx = s.beginTransaction(); - ContactInfo ci = new ContactInfo(); - Addr address = new Addr(); - address.setCity("Boston"); - address.setCountry("USA"); - address.setState("MA"); - address.setStreet("27 School Street"); - address.setZipcode("02108"); - ci.setAddr(address); - List phoneNumbers = new ArrayList(); - PhoneNumber num = new PhoneNumber(); - num.setNumber(5577188); - Employee e = new Employee(); - Collection employeeList = new ArrayList(); - employeeList.add(e); - e.setContactInfo(ci); - num.setEmployees(employeeList); - phoneNumbers.add(num); - ci.setPhoneNumbers(phoneNumbers); - SocialTouchPoints socialPoints = new SocialTouchPoints(); - List sites = new ArrayList(); - SocialSite site = new SocialSite(); - site.setEmployee(employeeList); - site.setWebsite("www.jboss.org"); - sites.add(site); - socialPoints.setWebsite(sites); - ci.setSocial(socialPoints); - s.persist(e); - tx.commit(); - - tx = s.beginTransaction(); - s.clear(); - e = (Employee) s.get(Employee.class,e.getId()); - tx.commit(); - s.close(); - } - - @Override - protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { - super.configureMetadataBuilder( metadataBuilder ); - metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ - Employee.class, - Location.class, - Move.class, - Trip.class, - PhoneNumber.class, - Addr.class, - SocialSite.class, - SocialTouchPoints.class - }; - } -} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java index 3e79e6ac02..725c373511 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java @@ -401,5 +401,10 @@ public class SessionFactoryExtension throw e; } } + + @Override + public MetadataImplementor getMetadataImplementor() { + return modelScope.getDomainModel(); + } } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryScope.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryScope.java index 249c4003bb..9681b10b7d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryScope.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryScope.java @@ -9,6 +9,7 @@ package org.hibernate.testing.orm.junit; import java.util.function.Consumer; import java.util.function.Function; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; @@ -27,4 +28,6 @@ public interface SessionFactoryScope { T fromTransaction(Function action); T fromTransaction(SessionImplementor session, Function action); + + MetadataImplementor getMetadataImplementor(); }