-->
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.  [ 4 posts ] 
Author Message
 Post subject: Extended @Entity with AnnotationConfiguration not working
PostPosted: Tue Jun 14, 2005 2:36 pm 
Newbie

Joined: Tue Jun 14, 2005 1:57 pm
Posts: 6
I'm testing the new ant task in hibernate-tools and I have annotated my classes with @Entity (org.hibernate.annotations.Entity, not javax.persistence.Entity). After running the HibernateToolTask as per docs I get the following error even though the class file is annotated (checked with bytecode viewer):

(package changed to *** in below)
org.hibernate.AnnotationException: Annotated class should have an @Entity, @Embeddable or @EmbeddedSuperclass annotation: com.***.DeviceFirmwareFamilyImpl
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:274)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:174)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:825)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:51)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2DDLGeneratorTask.execute(Hbm2DDLGeneratorTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)


This is the xml I'm using (both build and config):
Code:
<target name="devicedb2" description="(Re)builds the database schema" depends="init">
   <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpath="project.classpath"/>
   <hibernatetool destdir="${target.dir}/hibtool">
      <classpath refid="project.classpath"/>
      <annotationConfiguration configurationfile="hibernate.cfg.xml" propertyFile="${target.classes.dir}/hibernate.properties"/>
      <hbm2ddl/>
   </hibernatetool>
</target>

<hibernate-configuration>
   <session-factory>
      <mapping class="com.***.DeviceFirmwareFamilyImpl"/>
   </session-factory>
</hibernate-configuration>




I've tried both hibernate-tools3-alpha4 as well as rebuilding the latest from CVS (along with all dependencies), but still get this error. Looking at AnnotationConfiguration.java, it seems that the following code:

Code:
   public AnnotatedClassType addClassType(Class clazz) {
      AnnotatedClassType type;
      if ( clazz.isAnnotationPresent(Entity.class) ) {
         type = AnnotatedClassType.ENTITY;
      }
      else if (clazz.isAnnotationPresent(Embeddable.class) ) {
         type = AnnotatedClassType.EMBEDDABLE;
      }
      else if (clazz.isAnnotationPresent(EmbeddedSuperclass.class) ) {
         type = AnnotatedClassType.EMBEDDED_SUPERCLASS;
      }
      else {
         type = AnnotatedClassType.NONE;
      }
      classTypes.put(clazz, type);
      return type;
   }


assumes @Entity annotations will be of type javax.persistence.Entity since that's what it imports. How is the extended Entity annotation meant to be used from this configuration? For that matter, are there other extended annotations that would cause an error?

Would appreciate any insight,

Adrian


Top
 Profile  
 
 Post subject: That should be...
PostPosted: Tue Jun 14, 2005 3:00 pm 
Newbie

Joined: Tue Jun 14, 2005 1:57 pm
Posts: 6
The code I quoted above where the assumption is made about the annotation being javax.persistence.Entity is actually in ExtendedMappings.java, not AnnotationConfiguration.java.

Adrian


Top
 Profile  
 
 Post subject: Should this be better posted in another forum?
PostPosted: Wed Jun 15, 2005 9:00 am 
Newbie

Joined: Tue Jun 14, 2005 1:57 pm
Posts: 6
Would the hibernate users forum be a better forum to post the issue above?

Thanks,
Adrian


Top
 Profile  
 
 Post subject: Explanation
PostPosted: Thu Jun 16, 2005 10:52 am 
Newbie

Joined: Tue Jun 14, 2005 1:57 pm
Posts: 6
Usage of this was explained in Jira - here it is for people that might not search there...

@org.hibernate.annotations.Entity is an extension, not a replacement of @javax.persistence.Entity. Since annotations does not support inheritance, the right way to do is

@javax.persistence.Entity
@org.hibernate.annotations.Entity(...)
public class MyEntity { ... }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.