]
Hardy Ferentschik resolved METAGEN-35.
--------------------------------------
Resolution: Fixed
Generated meta model classes does not extend the super class'
meta model.
-------------------------------------------------------------------------
Key: METAGEN-35
URL:
http://opensource.atlassian.com/projects/hibernate/browse/METAGEN-35
Project: Hibernate Metamodel Generator
Issue Type: Bug
Components: processor
Affects Versions: 1.0.0.Final
Environment: Maven 2.2.1, Hibernate 3.5.4, maven-processor-plugin 13.6
Reporter: Joel Ringuette
Assignee: Hardy Ferentschik
Fix For: 1.1.0
I'm currently using maven to build a project. I'm using
org.bsc.maven.maven-processor-plugin plugin to generate the meta model. In my main source
folder, I have a class annotated with @MappedSuperclass.
{code}
@MappedSuperclass
public abstract class BaseEntity
{
// Entity id
@Id
@GeneratedValue
private Long id;
// some more code
}
{code}
In my test source folder, I have a class extending BaseEntity annotated with @Entity
{code}
@Entity()
public class Book extends BaseEntity
{
private String name;
@Column(unique = true)
private String isbn;
@ManyToOne(optional = false)
private Author author;
// some more code
}
{code}
When generating the meta model, the BaseEntity will generate BaseEntity_ and Book will
generate Book_. The problem is that Book_ does not extend BaseEntity_
Here is my config of the plugin
{code:xml}
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.6</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>${project.build.sourceDirectory}</outputDirectory>
</configuration>
</execution>
<execution>
<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>${project.build.testSourceDirectory}</outputDirectory>
<compilerArguments>-Adebug=true</compilerArguments>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.0.0.Final-Genia</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
{code}
After looking at the code, the culprit seem to be org.hibernate.jpamodelgen.ClassWriter.
In the method printClassDeclaration, we can see the following code:
{code}
if ( context.containsMetaEntity( superClassName )
|| context.containsMetaEmbeddable( superClassName ) ) {
pw.print( " extends " + superClassName + "_" );
}
{code}
It assume the the super class meta model is generated at the same time as the extending
class, which is not the case for test-compile and compile. I also assume that it does not
work if you extend a class coming from a jar where the meta model was already generated.
To locally fix the problem, I changed the above code for:
{code}
if (((TypeElement) superClassElement).getAnnotation(Entity.class) != null
|| ((TypeElement) superClassElement).getAnnotation(MappedSuperclass.class) !=
null)
{
pw.print(" extends " + superClassName + "_");
}
{code}
Since it's the first time I use annotation for code generation, I may not have fully
understood the problem so feel free to correct me if the above fix is not the correct
solution.
Regard,
Joel
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: