account for inconsistencies in the annotation processoer

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17894 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2009-11-02 22:09:31 +00:00
parent 5ecfeb5cb8
commit d8f6d41a4b
1 changed files with 42 additions and 14 deletions

View File

@ -34,10 +34,12 @@ import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.IdentifiableType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Component;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.annotations.common.AssertionFailure;
@ -55,6 +57,8 @@ import org.hibernate.annotations.common.AssertionFailure;
* @author Emmanuel Bernard
*/
class MetadataContext {
private static final Logger log = LoggerFactory.getLogger( MetadataContext.class );
private final SessionFactoryImplementor sessionFactory;
private final AttributeFactory attributeFactory = new AttributeFactory( this );
@ -334,14 +338,12 @@ class MetadataContext {
final String name = attribute.getName();
try {
Field field = metamodelClass.getDeclaredField( name );
field.setAccessible( true ); // should be public anyway, but to be sure...
field.set( null, attribute );
try {
if ( ! field.isAccessible() ) {
// should be public anyway, but to be sure...
field.setAccessible( true );
}
catch ( NoSuchFieldException e ) {
// todo : exception type?
throw new AssertionFailure(
"Unable to locate static metamodel field : " + metamodelClass.getName() + '#' + name
);
field.set( null, attribute );
}
catch ( IllegalAccessException e ) {
// todo : exception type?
@ -350,6 +352,32 @@ class MetadataContext {
e
);
}
catch ( IllegalArgumentException e ) {
// most likely a mismatch in the type we are injecting and the defined field; this represents a
// mismatch in how the annotation processor interpretted the attribute and how our metamodel
// and/or annotation binder did.
//
// This does seem to be an issue currently for ListAttribute and CollectionAttribute for @OneToMany List
// w/o the @Index definition (which is a bag in Hibernate-terms. So for the time being we simply
// log an error
// throw new AssertionFailure(
// "Illegal argument on static metamodel field injection : " + metamodelClass.getName() + '#' + name
// + "; expected type : " + attribute.getClass().getName()
// + "; encountered type : " + field.getType().getName()
// );
log.error(
"Illegal argument on static metamodel field injection : " + metamodelClass.getName() + '#' + name
+ "; expected type : " + attribute.getClass().getName()
+ "; encountered type : " + field.getType().getName()
);
}
}
catch ( NoSuchFieldException e ) {
log.error( "Unable to locate static metamodel field : " + metamodelClass.getName() + '#' + name );
// throw new AssertionFailure(
// "Unable to locate static metamodel field : " + metamodelClass.getName() + '#' + name
// );
}
}
public MappedSuperclassTypeImpl<?> locateMappedSuperclassType(MappedSuperclass mappedSuperclass) {