From decb673bddd5b31ea24b8dbfef04ae728e21dfe4 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 27 Mar 2014 20:01:39 -0700 Subject: [PATCH] HHH-9089 : Test case that shows annotations on fields in nested embeddable collection elements are ignored --- .../nested/NestedEmbeddableMetadataTest.java | 6 ++ .../nested/fieldaccess/Customer.java | 68 +++++++++++++++++ ...dAccessedNestedEmbeddableMetadataTest.java | 73 +++++++++++++++++++ .../nested/fieldaccess/Investment.java | 65 +++++++++++++++++ .../nested/fieldaccess/MonetaryAmount.java | 64 ++++++++++++++++ 5 files changed, 276 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Customer.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Investment.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/MonetaryAmount.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java index e8a36f10ca..ce71d90c3b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/NestedEmbeddableMetadataTest.java @@ -34,10 +34,12 @@ import org.junit.Test; import org.hibernate.cfg.Configuration; import org.hibernate.engine.spi.Mapping; import org.hibernate.mapping.Collection; +import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.Value; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.type.CustomType; @@ -57,6 +59,10 @@ public class NestedEmbeddableMetadataTest extends BaseUnitTestCase { Property investmentsProperty = classMetadata.getProperty( "investments" ); Collection investmentsValue = (Collection) investmentsProperty.getValue(); Component investmentMetadata = (Component) investmentsValue.getElement(); + Value descriptionValue = investmentMetadata.getProperty( "description" ).getValue(); + assertEquals( 1, descriptionValue.getColumnSpan() ); + Column selectable = (Column) descriptionValue.getColumnIterator().next(); + assertEquals( 500, selectable.getLength() ); Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue(); SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue(); CustomType currencyType = (CustomType) currencyMetadata.getType(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Customer.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Customer.java new file mode 100644 index 0000000000..813e26f08a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Customer.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.test.annotations.embeddables.nested.fieldaccess; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.annotations.GenericGenerator; + +/** + * @author Thomas Vanstals + * @author Steve Ebersole + */ +@Entity +@Access( value = AccessType.FIELD ) +public class Customer { + @Id + @GeneratedValue( generator="increment" ) + @GenericGenerator( name = "increment", strategy = "increment" ) + private Long id; + + @ElementCollection(fetch = FetchType.EAGER) + private List investments = new ArrayList(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getInvestments() { + return investments; + } + + public void setInvestments(List investments) { + this.investments = investments; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java new file mode 100644 index 0000000000..fce5561596 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.test.annotations.embeddables.nested.fieldaccess; + +import java.sql.Types; + +import org.junit.Test; + +import org.hibernate.cfg.Configuration; +import org.hibernate.engine.spi.Mapping; +import org.hibernate.mapping.Collection; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Selectable; +import org.hibernate.mapping.SimpleValue; +import org.hibernate.mapping.Value; +import org.hibernate.test.annotations.derivedidentities.e4.a.Simple; +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.type.CustomType; + +import static org.hibernate.testing.junit4.ExtraAssertions.assertJdbcTypeCode; +import static org.junit.Assert.assertEquals; + +/** + * @author Steve Ebersole + */ +public class FieldAccessedNestedEmbeddableMetadataTest extends BaseUnitTestCase { + @Test + @FailureExpected( jiraKey = "HHH-9089" ) + public void testEnumTypeInterpretation() { + Configuration cfg = new Configuration().addAnnotatedClass( Customer.class ); + cfg.buildMappings(); + Mapping mapping = cfg.buildMapping(); + PersistentClass classMetadata = cfg.getClassMapping( Customer.class.getName() ); + Property investmentsProperty = classMetadata.getProperty( "investments" ); + Collection investmentsValue = (Collection) investmentsProperty.getValue(); + Component investmentMetadata = (Component) investmentsValue.getElement(); + Value descriptionValue = investmentMetadata.getProperty( "description" ).getValue(); + assertEquals( 1, descriptionValue.getColumnSpan() ); + Column selectable = (Column) descriptionValue.getColumnIterator().next(); + assertEquals( 500, selectable.getLength() ); + Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue(); + SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue(); + CustomType currencyType = (CustomType) currencyMetadata.getType(); + int[] currencySqlTypes = currencyType.sqlTypes( mapping ); + assertEquals( 1, currencySqlTypes.length ); + assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Investment.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Investment.java new file mode 100644 index 0000000000..4fa95b9cbb --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/Investment.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.test.annotations.embeddables.nested.fieldaccess; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Embeddable; + +/** + * @author Thomas Vanstals + * @author Steve Ebersole + */ +@Embeddable +public class Investment { + private MonetaryAmount amount; + + @Column(length = 500) + private String description; + private Date date; + + public MonetaryAmount getAmount() { + return amount; + } + + public void setAmount(MonetaryAmount amount) { + this.amount = amount; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/MonetaryAmount.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/MonetaryAmount.java new file mode 100644 index 0000000000..8d89446752 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/nested/fieldaccess/MonetaryAmount.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.test.annotations.embeddables.nested.fieldaccess; + +import java.math.BigDecimal; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; + +/** + * @author Thomas Vanstals + * @author Steve Ebersole + */ +@Embeddable +public class MonetaryAmount { + public static enum CurrencyCode { + USD, + EUR + } + + private BigDecimal amount; + + @Column(length = 3) + @Enumerated(EnumType.STRING) + private CurrencyCode currency; + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public CurrencyCode getCurrency() { + return currency; + } + + public void setCurrency(CurrencyCode currency) { + this.currency = currency; + } +}