HHH-6475 - Metamodel check fails when subclasses are used

This commit is contained in:
Hardy Ferentschik 2015-08-21 21:13:13 +02:00 committed by Steve Ebersole
parent e6c1f511a3
commit 25d8a66ac7
9 changed files with 212 additions and 0 deletions

View File

@ -2475,6 +2475,7 @@ public final class AnnotationBinder {
XProperty property = inferredData.getProperty();
setupComponentTuplizer( property, comp );
PropertyBinder binder = new PropertyBinder();
binder.setDeclaringClass(inferredData.getDeclaringClass());
binder.setName( inferredData.getPropertyName() );
binder.setValue( comp );
binder.setProperty( inferredData.getProperty() );

View File

@ -0,0 +1,31 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.Embedded;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
/**
* @author Hardy Ferentschik
*/
@MappedSuperclass
public class AbstractEntity {
@Id
private long id;
@Embedded
private EmbeddableEntity embedded;
public long getId() {
return id;
}
public EmbeddableEntity getEmbedded() {
return embedded;
}
}

View File

@ -0,0 +1,22 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Embeddable;
/**
* @author Hardy Ferentschik
*/
@Embeddable
@Access(AccessType.FIELD)
public class EmbeddableEntity {
private String foo;
}

View File

@ -0,0 +1,46 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EmbeddableType;
import javax.persistence.metamodel.ManagedType;
import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertNotNull;
/**
* @author Hardy Ferentschik
*/
public class EmbeddableInSuperClassTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
AbstractEntity.class, EmbeddableEntity.class, Entity.class
};
}
@Test
@TestForIssue(jiraKey = "HHH-6475")
public void ensureAttributeForEmbeddableIsGeneratedInMappedSuperClass() {
EmbeddableType<EmbeddableEntity> embeddableType = entityManagerFactory().getMetamodel()
.embeddable( EmbeddableEntity.class );
Attribute<?, ?> attribute = embeddableType.getAttribute( "foo" );
assertNotNull( attribute );
ManagedType<AbstractEntity> managedType = entityManagerFactory().getMetamodel().managedType( AbstractEntity.class );
assertNotNull( managedType );
attribute = managedType.getAttribute( "embedded" );
assertNotNull( attribute );
}
}

View File

@ -0,0 +1,14 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
/**
* @author Hardy Ferentschik
*/
@javax.persistence.Entity
public class Entity extends AbstractEntity {
}

View File

@ -0,0 +1,40 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.metamodel.EmbeddableType;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* An attempt at defining a test based on the HHH-8712 bug report
*/
public class FunkyExtendedEmbeddedIdTest extends BaseEntityManagerFunctionalTestCase {
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
WorkOrderComponentId.class, WorkOrderComponent.class, WorkOrderId.class
};
}
@Test
@TestForIssue(jiraKey = "HHH-8712")
public void ensureAttributeForEmbeddableIsGeneratedInMappedSuperClass() {
EmbeddableType<WorkOrderComponentId> woci = entityManagerFactory().getMetamodel()
.embeddable( WorkOrderComponentId.class );
assertThat( woci, notNullValue() );
assertThat( woci.getAttribute( "workOrder" ), notNullValue() );
assertThat( woci.getAttribute( "plantId" ), notNullValue() );
assertThat( woci.getAttribute( "lineNumber" ), notNullValue() );
}
}

View File

@ -0,0 +1,18 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.EmbeddedId;
/**
* @author Steve Ebersole
*/
@javax.persistence.Entity
public class WorkOrderComponent {
@EmbeddedId
private WorkOrderComponentId id;
}

View File

@ -0,0 +1,18 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import javax.persistence.Embeddable;
/**
* @author Steve Ebersole
*/
@Embeddable
public class WorkOrderComponentId extends WorkOrderId {
private Long lineNumber;
/* other stuffs */
}

View File

@ -0,0 +1,22 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.test.metamodel.attributeInSuper;
import java.io.Serializable;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
/**
* @author Steve Ebersole
*/
@Embeddable
@MappedSuperclass
public class WorkOrderId implements Serializable {
private String workOrder;
private Long plantId;
/* other stuffs */
}