-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: @Any does not work: @Any requires an explicit @JoinColumn(s)
PostPosted: Tue Jan 13, 2009 6:02 am 
Newbie

Joined: Tue Feb 05, 2008 11:35 am
Posts: 10
Hello!

I have problem with mapping @Any properties.
(My entity works as expected if I leave out the @Any property.)

Code:
@Entity
public class MyEntity implements Serializable {
  ...

  private Property mainProperty;

  @Any(metaColumn = @Column(name = "property_type"), fetch = FetchType.EAGER)
  @AnyMetaDef(idType = "integer", metaType = "string", metaValues = {
    @MetaValue(value = "S", targetEntity = StringProperty.class),
    @MetaValue(value = "I", targetEntity = IntegerProperty.class) }
  )
  @JoinColumn(name = "property_id")
  public Property getMainProperty() {
    return mainProperty;
  }

  public void setMainProperty(Property mainProperty) {
    this.mainProperty = mainProperty;
  }


It is the same mapping as in the Hibernate Annotations documentation at http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-hibspec-singleassoc-any.

I get the following exception during ddl generation:

Code:
Caused by: org.hibernate.AnnotationException: @Any requires an explicit @JoinColumn(s): com.example.MyEntity.mainProperty
   at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1231)
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
   at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224)
   at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
   ... 78 more


I debugged EJB3OverridenAnnotationReader, and I found that at line 280 the annotations of the property are filtered by

Code:
  for (Annotation annotation : annotations) {
    if ( !annotationToXml.containsKey( annotation.annotationType() ) ) {
      //unknown annotations are left over
      annotationList.add( annotation );
    }


This filter skips the @JoinColumn annotation that's why only the @Any and @AnyMetaDef will be added to annotationList. This results in @JoinColumn to be "lost" for further processing of @Any, and the application fails at AnnotationBinder@1231

Code:
else if ( joinColumns == null && property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
  throw new AnnotationException( "@Any requires an explicit @JoinColumn(s): "
    + StringHelper.qualify( propertyHolder.getPath(), property.getName() ) );
}


because property.isAnnotationPresent() is not aware of @JoinColumn at AnnotationBinder@1154.

Is this a bug, or should I configure something?

Thanks for your help in advance!
Regards:
Norbi

libs:
hibernate-core-3.3.1.GA
hibernate-annotations-3.4.0.GA
hibernate-entitymanager-3.4.0.GA


Top
 Profile  
 
 Post subject: Workaround
PostPosted: Sun Apr 12, 2009 4:44 am 
Newbie

Joined: Sun Apr 12, 2009 4:36 am
Posts: 1
Hi Norbi

I had the same problem. I believe there is a bug in the EJB3OverridenAnnotationReader in that it does not make provision for Any- associations. However, this class is only loaded if you have xml mapping files, including the orm.xml file. If you can, delete all such files from your deployment, and the EJB3OverridenAnnotationReader will never be called.

hope this helps

Ampie


Top
 Profile  
 
 Post subject: Bug report created
PostPosted: Mon Apr 13, 2009 3:06 pm 
Newbie

Joined: Fri Jan 23, 2009 4:02 pm
Posts: 6
I also ran into this bug, and created a ticket for it: http://opensource.atlassian.com/project ... se/ANN-819

Noah


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.