HHH-9089 : Test case that shows annotations on fields in nested embeddable collection elements are ignored
This commit is contained in:
parent
4bb7966102
commit
decb673bdd
|
@ -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();
|
||||
|
|
|
@ -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<Investment> investments = new ArrayList<Investment>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Investment> getInvestments() {
|
||||
return investments;
|
||||
}
|
||||
|
||||
public void setInvestments(List<Investment> investments) {
|
||||
this.investments = investments;
|
||||
}
|
||||
}
|
|
@ -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] );
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue