HHH-8184 association attributes from mapped super class are not included

This commit is contained in:
Strong Liu 2013-04-15 21:56:35 +08:00
parent f29a670378
commit a448e268e0
6 changed files with 34 additions and 23 deletions

View File

@ -38,7 +38,9 @@
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.collections.JoinedIterable;
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; 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.BasicAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
import org.hibernate.metamodel.internal.source.annotations.attribute.Column; import org.hibernate.metamodel.internal.source.annotations.attribute.Column;
import org.hibernate.metamodel.internal.source.annotations.attribute.FormulaValue; import org.hibernate.metamodel.internal.source.annotations.attribute.FormulaValue;
@ -168,6 +170,19 @@ public Collection<BasicAttribute> getSimpleAttributes() {
return attributes; return attributes;
} }
@Override
public Iterable<AssociationAttribute> getAssociationAttributes() {
List<Iterable<AssociationAttribute>> list = new ArrayList<Iterable<AssociationAttribute>>( );
list.add( super.getAssociationAttributes() );
// now the attributes of the mapped superclasses
for ( MappedSuperclass mappedSuperclass : mappedSuperclasses ) {
list.add( mappedSuperclass.getAssociationAttributes() );
}
return new JoinedIterable<AssociationAttribute>( list );
}
public Collection<MappedAttribute> getIdAttributes() { public Collection<MappedAttribute> getIdAttributes() {
List<MappedAttribute> attributes = new ArrayList<MappedAttribute>(); List<MappedAttribute> attributes = new ArrayList<MappedAttribute>();

View File

@ -29,13 +29,11 @@
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@FailureExpectedWithNewMetamodel
public class GenericsTest extends BaseCoreFunctionalTestCase { public class GenericsTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testManyToOneGenerics() throws Exception { public void testManyToOneGenerics() throws Exception {

View File

@ -12,7 +12,8 @@
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.metamodel.spi.relational.Database;
import org.hibernate.metamodel.spi.relational.Schema;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -22,7 +23,6 @@
/** /**
* @author Manuel Bernhardt <bernhardt.manuel@gmail.com> * @author Manuel Bernhardt <bernhardt.manuel@gmail.com>
*/ */
@FailureExpectedWithNewMetamodel
public class UniqueConstraintTest extends BaseCoreFunctionalTestCase { public class UniqueConstraintTest extends BaseCoreFunctionalTestCase {
@Override @Override
@ -70,25 +70,26 @@ public void testUniquenessConstraintWithSuperclassProperty() throws Exception {
@Test @Test
@TestForIssue( jiraKey = "HHH-8026" ) @TestForIssue( jiraKey = "HHH-8026" )
public void testUnNamedConstraints() { public void testUnNamedConstraints() {
Iterator<org.hibernate.mapping.Table> iterator = configuration().getTableMappings(); Database database = metadata().getDatabase();
org.hibernate.mapping.Table tableA = null; org.hibernate.metamodel.spi.relational.Table tableA = null;
org.hibernate.mapping.Table tableB = null; org.hibernate.metamodel.spi.relational.Table tableB = null;
while( iterator.hasNext() ) { for(final Schema schema : database.getSchemas()){
org.hibernate.mapping.Table table = iterator.next(); for(final org.hibernate.metamodel.spi.relational.Table table : schema.getTables()){
if ( table.getName().equals( "UniqueNoNameA" ) ) { if ( table.getPhysicalName().getText().equals( "UniqueNoNameA" ) ) {
tableA = table; tableA = table;
} }
else if ( table.getName().equals( "UniqueNoNameB" ) ) { else if ( table.getPhysicalName().getText().equals( "UniqueNoNameB" ) ) {
tableB = table; tableB = table;
}
} }
} }
if ( tableA == null || tableB == null ) { if ( tableA == null || tableB == null ) {
fail( "Could not find the expected tables." ); fail( "Could not find the expected tables." );
} }
assertFalse( tableA.getUniqueKeyIterator().next().getName().equals( assertFalse( tableA.getUniqueKeys().iterator().next().getName().equals(
tableB.getUniqueKeyIterator().next().getName() ) ); tableB.getUniqueKeys().iterator().next().getName() ) );
} }
@Entity @Entity

View File

@ -41,7 +41,7 @@
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
@FailureExpectedWithNewMetamodel @FailureExpectedWithNewMetamodel(message = "@OneToOne with mappedBy specified is not supported yet")
public class CastTest extends AbstractMetamodelSpecificTest { public class CastTest extends AbstractMetamodelSpecificTest {
private static final int QUANTITY = 2; private static final int QUANTITY = 2;

View File

@ -57,7 +57,7 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@FailureExpectedWithNewMetamodel @FailureExpectedWithNewMetamodel(message = "@OneToOne with mappedBy specified is not supported yet")
public class ExpressionsTest extends AbstractMetamodelSpecificTest { public class ExpressionsTest extends AbstractMetamodelSpecificTest {
private CriteriaBuilder builder; private CriteriaBuilder builder;

View File

@ -28,8 +28,6 @@
import org.junit.Test; import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -38,7 +36,6 @@
*/ */
public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase { public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase {
@Test @Test
@FailureExpectedWithNewMetamodel
public void testIsLoadedOnPrivateSuperclassProperty() { public void testIsLoadedOnPrivateSuperclassProperty() {
EntityManager em = entityManagerFactory().createEntityManager(); EntityManager em = entityManagerFactory().createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();