I am trying to generate Java entities from tables using hibernate3-maven-plugin and its hbm2java goal. Using reverse engineering (my custom implementation of ReverseEngineeringStrategy) I am having all entities extend a supertype class called AbstractDomainObject.

The supertype is a abstract class annotated with @MappedSuperclass. It has a Long id and a getter and setter for that id.

private Long id;

@Id
@GeneratedValue(strategy = IDENTITY)
//@Basic(optional = false)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {

    return id;
}

public void setId(final Long id) {

    this.id = id;
}

Using reveng.xml I am trying to exclude the id column (PK) from all entities, so the entities will reuse the id code from the superclass.

<table name="ACCOUNT" catalog="finsys">
    <column name="id" exclude="true" />
</table>

However, when I build the code, I get this error:

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2java (default) on project finsys-boot: There was an error creating the AntRun task.: An Ant BuildException has occured: org.hibernate.cfg.JDBCBinderException: sqltype is null for Table: finsys.ACCOUNT column: id -> [Help 1]

Apparently it does not allow me to exclude the primary key column from the process, even though the entities conform to a mapped supertype that contains the id.

Does anyone know how to solve this? It all succeeds when not excluding the id column.

Some more info.

The plugin:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>${hibernate3-maven-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <configuration>
                <hibernatetool>
                    <jdbcconfiguration
                        packagename="com.maescaprey.finsys.domain"
                        propertyfile="src/main/resources/hbm2java.hibernate.properties"
                        revengfile="src/main/resources/model.reveng.xml"
                        reversestrategy="com.maescaprey.finsys.utility.persistence.FinSysReverseEngineeringStrategy" 
                    />
                    <hbm2java jdk5="true" ejb3="true"
                        destdir="${project.build.directory}/generated-sources" />
                </hibernatetool>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-tools</artifactId>
                    <version>${hibernate-tools.version}</version>
                </dependency>
            </dependencies>
        </plugin>

Another plugin to put the generated source on the classpath (in IDE) :

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Finally the ReverseEngineeringStrategy method that makes the entities extend AbstractDomainObject:

@Override
public Map<String, MetaAttribute> tableToMetaAttributes(final TableIdentifier tableIdentifier) {

    Map<String, MetaAttribute> metaAttributes = super.tableToMetaAttributes(tableIdentifier);
    if (metaAttributes == null) {
        metaAttributes = new HashMap<String, MetaAttribute>();
    }

    final MetaAttribute extendsAttribute = new MetaAttribute("extends");
    extendsAttribute.addValue(AbstractDomainObject.class.getSimpleName());
    metaAttributes.put("extends", extendsAttribute);

    ... // some more MetaAttributes here

    return metaAttributes;
}
0

There are 0 best solutions below