From d14d18e40b0cb3bf9fc5263d74bc6e343dc01dee Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Wed, 5 Sep 2012 14:59:35 +0200 Subject: [PATCH] HHH-7571 Minimal implementation of @ElementCollection details to pass AnnotationBasicCollectionBindingTests --- .../jaxb/spi/hbm/TableInformationSource.java | 4 + .../hibernate/metamodel/internal/Binder.java | 3 +- ...BasicPluralAttributeElementSourceImpl.java | 70 ++++++++++++ .../source/annotations/EntitySourceImpl.java | 6 ++ ...ToAnyPluralAttributeElementSourceImpl.java | 28 +++++ .../OneToManyAttributeElementSourceImpl.java | 62 +++++++++++ .../PluralAttributeKeySourceImpl.java | 7 +- .../PluralAttributeSourceImpl.java | 101 ++++++------------ .../attribute/MappedAttribute.java | 34 +++--- .../annotations/entity/ConfiguredClass.java | 11 +- .../entity/OneToManyBindingTest.java | 4 +- .../AbstractBasicCollectionBindingTests.java | 10 +- ...AnnotationBasicCollectionBindingTests.java | 2 - .../EntityWithBasicCollections.java | 14 ++- 14 files changed, 247 insertions(+), 109 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToAnyPluralAttributeElementSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/OneToManyAttributeElementSourceImpl.java diff --git a/hibernate-core/src/main/java/org/hibernate/jaxb/spi/hbm/TableInformationSource.java b/hibernate-core/src/main/java/org/hibernate/jaxb/spi/hbm/TableInformationSource.java index 96fc784c87..5fa8d06683 100644 --- a/hibernate-core/src/main/java/org/hibernate/jaxb/spi/hbm/TableInformationSource.java +++ b/hibernate-core/src/main/java/org/hibernate/jaxb/spi/hbm/TableInformationSource.java @@ -28,8 +28,12 @@ */ public interface TableInformationSource { public String getSchema(); + public String getCatalog(); + public String getTable(); + public String getSubselect(); + public String getSubselectAttribute(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index cf2d4faf66..be21930bd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -2173,8 +2173,7 @@ private void mapSourcesByName( final EntitySource entitySource ) { } private PluralAttributeElementBinding.Nature pluralAttributeElementNature(PluralAttributeSource attributeSource) { - return PluralAttributeElementBinding.Nature - .valueOf( attributeSource.getElementSource().getNature().name() ); + return PluralAttributeElementBinding.Nature.valueOf( attributeSource.getElementSource().getNature().name() ); } private PluralAttributeIndexBinding.Nature pluralAttributeIndexNature(PluralAttributeSource attributeSource) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..fe6ef520c9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java @@ -0,0 +1,70 @@ +package org.hibernate.metamodel.internal.source.annotations; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.attribute.Column; +import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; +import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource; +import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; +import org.hibernate.metamodel.spi.source.RelationalValueSource; + +/** + * @author Hardy Ferentschik + */ +public class BasicPluralAttributeElementSourceImpl implements BasicPluralAttributeElementSource { + private final AssociationAttribute associationAttribute; + + public BasicPluralAttributeElementSourceImpl(AssociationAttribute associationAttribute) { + this.associationAttribute = associationAttribute; + } + + @Override + public ExplicitHibernateTypeSource getExplicitHibernateTypeSource() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public Nature getNature() { + if ( MappedAttribute.Nature.ELEMENT_COLLECTION_BASIC.equals( associationAttribute.getNature() ) ) { + return Nature.BASIC; + } + else if ( MappedAttribute.Nature.ELEMENT_COLLECTION_EMBEDDABLE.equals( associationAttribute.getNature() ) ) { + return Nature.COMPONENT; + } + else { + throw new AssertionError( + "Wrong attribute nature for a element collection attribute: " + associationAttribute.getNature() + ); + } + } + + @Override + public List relationalValueSources() { + List valueSources = new ArrayList( ); + if ( !associationAttribute.getColumnValues().isEmpty() ) { + for ( Column columnValues : associationAttribute.getColumnValues() ) { + valueSources.add( new ColumnSourceImpl( associationAttribute, null, columnValues ) ); + } + } + return valueSources; + } + + @Override + public boolean areValuesIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean areValuesIncludedInUpdateByDefault() { + return true; + } + + @Override + public boolean areValuesNullableByDefault() { + return true; + } +} + + diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/EntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/EntitySourceImpl.java index 6ed629d67e..41ad6a94e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/EntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/EntitySourceImpl.java @@ -242,6 +242,12 @@ public List attributeSources() { :new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute ); attributeList.add( source ); break; + case ELEMENT_COLLECTION_BASIC: + case ELEMENT_COLLECTION_EMBEDDABLE: { + source = new PluralAttributeSourceImpl( ( PluralAssociationAttribute ) associationAttribute ); + attributeList.add( source ); + break; + } default: { throw new NotYetImplementedException(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToAnyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToAnyPluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..2eac143ae6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ManyToAnyPluralAttributeElementSourceImpl.java @@ -0,0 +1,28 @@ +package org.hibernate.metamodel.internal.source.annotations; + +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; +import org.hibernate.metamodel.spi.source.ManyToAnyPluralAttributeElementSource; + +/** + * @author Hardy Ferentschik + */ +public class ManyToAnyPluralAttributeElementSourceImpl implements ManyToAnyPluralAttributeElementSource { + private final PluralAssociationAttribute attribute; + + public ManyToAnyPluralAttributeElementSourceImpl(PluralAssociationAttribute attribute) { + this.attribute = attribute; + } + + @Override + public Iterable getCascadeStyles() { + return EnumConversionHelper.cascadeTypeToCascadeStyleSet( attribute.getCascadeTypes(), attribute.getContext() ); + } + + @Override + public Nature getNature() { + return Nature.MANY_TO_ANY; + } +} + diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/OneToManyAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/OneToManyAttributeElementSourceImpl.java new file mode 100644 index 0000000000..eb64b09d46 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/OneToManyAttributeElementSourceImpl.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.internal.source.annotations; + +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; +import org.hibernate.metamodel.spi.source.OneToManyPluralAttributeElementSource; + +/** + * @author Hardy Ferentschik + */ +public class OneToManyAttributeElementSourceImpl implements OneToManyPluralAttributeElementSource { + private final PluralAssociationAttribute attribute; + + public OneToManyAttributeElementSourceImpl(PluralAssociationAttribute attribute) { + this.attribute = attribute; + } + + @Override + public String getReferencedEntityName() { + return attribute.getReferencedEntityType(); + } + + @Override + public boolean isNotFoundAnException() { + return !attribute.isIgnoreNotFound(); + } + + @Override + public Iterable getCascadeStyles() { + return EnumConversionHelper.cascadeTypeToCascadeStyleSet( attribute.getCascadeTypes(), attribute.getContext() ); + } + + @Override + public Nature getNature() { + return Nature.ONE_TO_MANY; + } +} + + diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java index 3ada857085..cf06c21f10 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeKeySourceImpl.java @@ -115,16 +115,15 @@ public static class JoinColumnResolutionDelegateImpl implements JoinColumnResolu public JoinColumnResolutionDelegateImpl(PluralAssociationAttribute attribute) { this.attribute = attribute; - } @Override public List getJoinColumns(JoinColumnResolutionContext context) { - List joinClumnValues = attribute.getJoinColumnValues(); - if ( joinClumnValues.isEmpty() ) { + List joinColumnValues = attribute.getJoinColumnValues(); + if ( joinColumnValues.isEmpty() ) { return null; } - List result = new ArrayList( joinClumnValues.size() ); + List result = new ArrayList( joinColumnValues.size() ); for ( Column column : attribute.getJoinColumnValues() ) { result.add( context.resolveColumn( column.getReferencedColumnName(), null, null, null ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java index 99bbcce3e4..24ec95664e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java @@ -27,26 +27,22 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.CascadeType; import org.hibernate.FetchMode; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; -import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; -import org.hibernate.metamodel.spi.source.ManyToAnyPluralAttributeElementSource; import org.hibernate.metamodel.spi.source.MetaAttributeSource; -import org.hibernate.metamodel.spi.source.OneToManyPluralAttributeElementSource; import org.hibernate.metamodel.spi.source.Orderable; import org.hibernate.metamodel.spi.source.PluralAttributeElementSource; import org.hibernate.metamodel.spi.source.PluralAttributeKeySource; import org.hibernate.metamodel.spi.source.PluralAttributeSource; import org.hibernate.metamodel.spi.source.Sortable; +import org.hibernate.metamodel.spi.source.TableSource; import org.hibernate.metamodel.spi.source.TableSpecificationSource; /** @@ -78,21 +74,6 @@ public Map getParameters() { }; } - private Nature resolveAttributeNature() { - if ( Map.class.isAssignableFrom( attribute.getAttributeType() ) ) { - return PluralAttributeSource.Nature.MAP; - } - else if ( List.class.isAssignableFrom( attribute.getAttributeType() ) ) { - return PluralAttributeSource.Nature.LIST; - } - else if ( Set.class.isAssignableFrom( attribute.getAttributeType() ) ) { - return PluralAttributeSource.Nature.SET; - } - else { - return PluralAttributeSource.Nature.BAG; - } - } - @Override public Nature getNature() { return nature; @@ -103,7 +84,7 @@ public PluralAttributeElementSource getElementSource() { return elementSource; } - private PluralAttributeElementSource determineElementSource (){ + private PluralAttributeElementSource determineElementSource() { switch ( attribute.getNature() ) { case MANY_TO_MANY: return new ManyToManyPluralAttributeElementSourceImpl( attribute ); @@ -111,6 +92,10 @@ private PluralAttributeElementSource determineElementSource (){ return new ManyToAnyPluralAttributeElementSourceImpl( attribute ); case ONE_TO_MANY: return new OneToManyPluralAttributeElementSourceImpl( attribute ); + case ELEMENT_COLLECTION_BASIC: + case ELEMENT_COLLECTION_EMBEDDABLE: { + return new BasicPluralAttributeElementSourceImpl( attribute ); + } } throw new AssertionError( "unexpected attribute nature" ); } @@ -122,8 +107,24 @@ public PluralAttributeKeySource getKeySource() { @Override public TableSpecificationSource getCollectionTableSpecificationSource() { - // todo see org.hibernate.metamodel.internal.Binder#bindOneToManyCollectionKey - return null; + // todo - see org.hibernate.metamodel.internal.Binder#bindOneToManyCollectionKey + // todo - needs to cater for @CollectionTable and @JoinTable + return new TableSource() { + @Override + public String getExplicitSchemaName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getExplicitCatalogName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getExplicitTableName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + }; } @Override @@ -252,55 +253,19 @@ public FetchTiming getFetchTiming() { public FetchStyle getFetchStyle() { return attribute.getFetchStyle(); } - public Iterable interpretCascadeStyles(Set cascadeTypes) { - return EnumConversionHelper.cascadeTypeToCascadeStyleSet( cascadeTypes, attribute.getContext() ); - - } - - private class OneToManyPluralAttributeElementSourceImpl implements OneToManyPluralAttributeElementSource { - private final PluralAssociationAttribute attribute; - - private OneToManyPluralAttributeElementSourceImpl(PluralAssociationAttribute attribute) { - this.attribute = attribute; + private Nature resolveAttributeNature() { + if ( Map.class.isAssignableFrom( attribute.getAttributeType() ) ) { + return PluralAttributeSource.Nature.MAP; } - - @Override - public String getReferencedEntityName() { - return attribute.getReferencedEntityType(); + else if ( List.class.isAssignableFrom( attribute.getAttributeType() ) ) { + return PluralAttributeSource.Nature.LIST; } - - @Override - public boolean isNotFoundAnException() { - return !attribute.isIgnoreNotFound(); + else if ( Set.class.isAssignableFrom( attribute.getAttributeType() ) ) { + return PluralAttributeSource.Nature.SET; } - - @Override - public Iterable getCascadeStyles() { - return interpretCascadeStyles( attribute.getCascadeTypes() ); - } - - @Override - public Nature getNature() { - return Nature.ONE_TO_MANY; - } - } - - private class ManyToAnyPluralAttributeElementSourceImpl implements ManyToAnyPluralAttributeElementSource { - private final PluralAssociationAttribute attribute; - - private ManyToAnyPluralAttributeElementSourceImpl(PluralAssociationAttribute attribute) { - this.attribute = attribute; - } - - @Override - public Iterable getCascadeStyles() { - return interpretCascadeStyles( attribute.getCascadeTypes() ); - } - - @Override - public Nature getNature() { - return Nature.MANY_TO_ANY; + else { + return PluralAttributeSource.Nature.BAG; } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/MappedAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/MappedAttribute.java index c42f1ea91a..5ebc0ff40f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/MappedAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/MappedAttribute.java @@ -75,9 +75,9 @@ public abstract class MappedAttribute implements Comparable { * Defines the column values (relational values) for this property. A mapped property can refer to multiple * column values in case of components or join columns etc */ - private List columnValues = new ArrayList( ); + private List columnValues = new ArrayList(); - private List joinColumnValues = new ArrayList( ); + private List joinColumnValues = new ArrayList(); /** * Is this property an id property (or part thereof). @@ -86,7 +86,7 @@ public abstract class MappedAttribute implements Comparable { /** * Is this property a natural id property and what's the mutability it is. - */ + */ private SingularAttributeBinding.NaturalIdMutability naturalIdMutability; /** @@ -154,7 +154,7 @@ public List getColumnValues() { return columnValues; } - public List getJoinColumnValues(){ + public List getJoinColumnValues() { return joinColumnValues; } @@ -229,7 +229,8 @@ private SingularAttributeBinding.NaturalIdMutability checkNaturalId() { if ( naturalIdAnnotation == null ) { return SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; } - final boolean mutable = naturalIdAnnotation.value("mutable") == null ? false : naturalIdAnnotation.value( "mutable" ).asBoolean(); + final boolean mutable = naturalIdAnnotation.value( "mutable" ) == null ? false : + naturalIdAnnotation.value("mutable").asBoolean(); return mutable ? SingularAttributeBinding.NaturalIdMutability.MUTABLE : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE; } @@ -240,8 +241,11 @@ private void checkColumnAnnotations(Map> annot JPADotNames.COLUMN ); if ( columnAnnotation != null ) { - if ( getNature() == Nature.MANY_TO_ONE || getNature() == Nature.ONE_TO_ONE) { - throw getContext().makeMappingException( "@Column(s) not allowed on a "+ getNature() +" property: " +getContext().getOrigin().getName() +"."+ name ); + if ( getNature() == Nature.MANY_TO_ONE || getNature() == Nature.ONE_TO_ONE ) { + throw getContext().makeMappingException( + "@Column(s) not allowed on a " + getNature() + " property: " + getContext().getOrigin() + .getName() + "." + name + ); } columnValues.add( new Column( columnAnnotation ) ); } @@ -261,8 +265,11 @@ private void checkColumnAnnotations(Map> annot HibernateDotNames.COLUMNS ); if ( columnsAnnotation != null ) { - if ( getNature() == Nature.MANY_TO_ONE || getNature() == Nature.ONE_TO_ONE) { - throw getContext().makeMappingException( "@Column(s) not allowed on a "+ getNature() +" property: " +getContext().getOrigin().getName() +"."+ name ); + if ( getNature() == Nature.MANY_TO_ONE || getNature() == Nature.ONE_TO_ONE ) { + throw getContext().makeMappingException( + "@Column(s) not allowed on a " + getNature() + " property: " + getContext().getOrigin() + .getName() + "." + name + ); } List columnsList = Arrays.asList( JandexHelper.getValue( columnsAnnotation, "value", AnnotationInstance[].class ) @@ -295,10 +302,9 @@ private String checkCheckAnnotation() { } return checkCondition; } + /** * An enum defining the type of a mapped attribute. - * - * @author Hardy Ferentschik */ public static enum Nature { BASIC( JPADotNames.BASIC ), @@ -321,12 +327,6 @@ public static enum Nature { public DotName getAnnotationDotName() { return annotationDotName; } - - @Override - public String toString() { - return "Nature{" +annotationDotName.toString()+ - '}'; - } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java index d214c7d07e..b1750e1bc9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java @@ -54,7 +54,6 @@ import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; import org.hibernate.HibernateException; -import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride; @@ -461,10 +460,6 @@ else if ( attribute.isVersioned() ) { } break; } - case ELEMENT_COLLECTION_BASIC: - case ELEMENT_COLLECTION_EMBEDDABLE: { - throw new NotYetImplementedException( "Element collections must still be implemented." ); - } case EMBEDDED_ID: { final BasicAttribute attribute = BasicAttribute.createSimpleAttribute( attributeName, @@ -490,7 +485,6 @@ else if ( attribute.isVersioned() ) { resolveEmbeddable( attributeName, attributeType, annotations ); break; } - // OneToOne, OneToMany, ManyToOne, ManyToMany case ONE_TO_ONE: case MANY_TO_ONE: { final AssociationAttribute attribute = AssociationAttribute.createAssociationAttribute( @@ -504,6 +498,8 @@ else if ( attribute.isVersioned() ) { associationAttributeMap.put( attributeName, attribute ); break; } + case ELEMENT_COLLECTION_BASIC: + case ELEMENT_COLLECTION_EMBEDDABLE: case ONE_TO_MANY: case MANY_TO_MANY: { AssociationAttribute attribute = PluralAssociationAttribute.createPluralAssociationAttribute( @@ -609,12 +605,13 @@ private MappedAttribute.Nature determineAttributeNature(Map void checkResult( + private void assertBasicCollectionBinding( EntityBinding collectionOwnerBinding, PluralAttributeBinding collectionBinding, Class expectedCollectionTypeClass, diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AnnotationBasicCollectionBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AnnotationBasicCollectionBindingTests.java index 8ffdd4595e..30566b601c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AnnotationBasicCollectionBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AnnotationBasicCollectionBindingTests.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; /** * @author Hardy Ferentschik @@ -37,7 +36,6 @@ public void addSources(MetadataSources sources) { } @Test - @FailureExpectedWithNewMetamodel public void testBasicCollections() { super.testBasicCollections(); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/EntityWithBasicCollections.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/EntityWithBasicCollections.java index f0b4c96200..f384152429 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/EntityWithBasicCollections.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/EntityWithBasicCollections.java @@ -30,9 +30,15 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; +import javax.persistence.JoinColumn; + +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; /** * @author Gail Badner @@ -64,6 +70,7 @@ public void setId(Long id) { this.id = id; } + @Column(unique = true) public String getName() { return name; } @@ -72,7 +79,8 @@ public void setName(String name) { this.name = name; } - @ElementCollection + @ElementCollection(fetch = FetchType.EAGER) + @JoinColumn(name = "owner_id") public Collection getTheBag() { return theBag; } @@ -82,6 +90,8 @@ public void setTheBag(Collection theBag) { } @ElementCollection + @LazyCollection(value = LazyCollectionOption.EXTRA) + @JoinColumn(name = "pid") public Set getTheSet() { return theSet; } @@ -91,6 +101,8 @@ public void setTheSet(Set theSet) { } @ElementCollection + @JoinColumn(name = "pid", referencedColumnName = "name") + @Column(name="property_ref_set_stuff", nullable = false) public Set getThePropertyRefSet() { return thePropertyRefSet; }