HHH-5024 - MetadataContext#registerAttribute does not recognize inherited fields
This commit is contained in:
parent
6258df4752
commit
75bd6b319b
|
@ -370,7 +370,17 @@ class MetadataContext {
|
|||
private <X> void registerAttribute(Class metamodelClass, Attribute<X, ?> attribute) {
|
||||
final String name = attribute.getName();
|
||||
try {
|
||||
Field field = metamodelClass.getDeclaredField( name );
|
||||
// there is a shortcoming in the existing Hibernate code in terms of the way MappedSuperclass
|
||||
// support was bolted on which comes to bear right here when the attribute is an embeddable type
|
||||
// defined on a MappedSuperclass. We do not have the correct information to determine the
|
||||
// appropriate attribute declarer in such cases and so the incoming metamodelClass most likely
|
||||
// does not represent the declarer in such cases.
|
||||
//
|
||||
// As a result, in the case of embeddable classes we simply use getField rather than get
|
||||
// getDeclaredField
|
||||
final Field field = attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED
|
||||
? metamodelClass.getField( name )
|
||||
: metamodelClass.getDeclaredField( name );
|
||||
try {
|
||||
if ( ! field.isAccessible() ) {
|
||||
// should be public anyway, but to be sure...
|
||||
|
|
|
@ -39,7 +39,6 @@ import static org.junit.Assert.assertNotNull;
|
|||
public class MappedSuperclassWithEmbeddedTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-5024" )
|
||||
@FailureExpected( jiraKey = "HHH-5024" )
|
||||
public void testStaticMetamodel() {
|
||||
new Ejb3Configuration().addAnnotatedClass( Company.class ).buildEntityManagerFactory();
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import static org.junit.Assert.assertNotNull;
|
|||
public class MappedSuperclassWithEmbeddedIdTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-5024" )
|
||||
@FailureExpected( jiraKey = "HHH-5024" )
|
||||
public void testStaticMetamodel() {
|
||||
new Ejb3Configuration().addAnnotatedClass( Product.class ).buildEntityManagerFactory();
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.Serializable;
|
|||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* @author Alexis Bataille
|
||||
|
@ -41,12 +42,9 @@ public abstract class AbstractAttribute implements Serializable {
|
|||
super();
|
||||
}
|
||||
|
||||
public abstract String getOwner();
|
||||
@Transient public abstract String getOwner();
|
||||
|
||||
@Column(name = "attribute_key")
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
@Transient public String getKey() { return key; }
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.hibernate.ejb.Ejb3Configuration;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
|
@ -40,7 +39,6 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|||
public class MappedSuperclassWithEntityWithIdClassTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-5024" )
|
||||
@FailureExpected( jiraKey = "HHH-5024" )
|
||||
public void testStaticMetamodel() {
|
||||
new Ejb3Configuration().addAnnotatedClass( ProductAttribute.class ).buildEntityManagerFactory();
|
||||
|
||||
|
@ -48,8 +46,7 @@ public class MappedSuperclassWithEntityWithIdClassTest extends BaseUnitTestCase
|
|||
assertNotNull( "'ProductAttribute_.owner' should not be null)", ProductAttribute_.owner );
|
||||
assertNotNull( "'ProductAttribute_.key' should not be null)", ProductAttribute_.key );
|
||||
|
||||
assertNotNull( "'AbstractAttribute_.owner' should not be null)", AbstractAttribute_.owner );
|
||||
assertNotNull( "'AbstractAttribute_.key' should not be null)", AbstractAttribute_.key );
|
||||
assertNotNull( "'AbstractAttribute_.value' should not be null)", AbstractAttribute_.value );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue