Author: steve.ebersole(a)jboss.com
Date: 2009-11-02 17:08:48 -0500 (Mon, 02 Nov 2009)
New Revision: 17893
Modified:
core/tags/hibernate-3.5.0-Beta-2/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
Log:
ported change from trunk
Modified:
core/tags/hibernate-3.5.0-Beta-2/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
---
core/tags/hibernate-3.5.0-Beta-2/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-11-02
18:20:40 UTC (rev 17892)
+++
core/tags/hibernate-3.5.0-Beta-2/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-11-02
22:08:48 UTC (rev 17893)
@@ -34,10 +34,12 @@
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 @@
* @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,22 +338,46 @@
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 );
+ }
+ field.set( null, attribute );
+ }
+ catch ( IllegalAccessException e ) {
+ // todo : exception type?
+ throw new AssertionFailure(
+ "Unable to inject static metamodel attribute : " +
metamodelClass.getName() + '#' + name,
+ 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 ) {
- // todo : exception type?
- throw new AssertionFailure(
- "Unable to locate static metamodel field : " + metamodelClass.getName() +
'#' + name
- );
+ log.error( "Unable to locate static metamodel field : " +
metamodelClass.getName() + '#' + name );
+// throw new AssertionFailure(
+// "Unable to locate static metamodel field : " + metamodelClass.getName()
+ '#' + name
+// );
}
- catch ( IllegalAccessException e ) {
- // todo : exception type?
- throw new AssertionFailure(
- "Unable to inject static metamodel attribute : " +
metamodelClass.getName() + '#' + name,
- e
- );
- }
}
public MappedSuperclassTypeImpl<?> locateMappedSuperclassType(MappedSuperclass
mappedSuperclass) {
@@ -385,3 +413,4 @@
return persistentClass;
}
}
+
Show replies by date