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