I have a table that doesn't have any primary keys. but a unique row can be selected by creating one from three columns. I can't change the database model at this time, but i tried to use the reverse engineering tool to create a composite primary key.
hibernate.reveng.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table-filter match-name="my_table" exclude="false" />
<table name="my_table" class="MyTable" >
<primary-key>
<key-column name="a_a" property="aA" type="string" />
<key-column name="b_b" property="bB" type="big_decimal" />
<key-column name="c_c" property="cC" type="timestamp" />
</primary-key>
</table>
</hibernate-reverse-engineering>
I have an ant script setup to use this file: (line 39 is indicated below, because I also receive an error pointing to this line)
Code:
:
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
:
<target name="init">
<property file="hibernateBuild.properties"/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build.dir}"/>
<hibernatetool destdir="${build.dir}/generated"> <!-- this is LINE 39 in build.xml -->
<classpath>
<path location="${build.dir}/classes"/>
</classpath>
<jdbcconfiguration configurationfile="hibernate.cfg.xml" revengfile="hibernate.reveng.xml" >
<fileset dir=".">
<include name="*.hbm.xml"/>
</fileset>
</jdbcconfiguration>
<hbm2hbmxml destdir="${build.dir}/src" />
<hbm2java/>
</hibernatetool>
</target>
:
hibernatetool detects that there is no primary key and fails, shouldn't the reverse engineering file be picked up? Here is the
output of running my ant script, showing the warning: Rev.eng. strategy did not report any primary key columns for my_table (and the error message at build.xml:39)
Code:
[hibernatetool] WARNING: The JDBC driver didn't report any primary key columns in my_table. Asking rev.eng. strategy
[hibernatetool] Apr 15, 2011 5:51:05 PM org.hibernate.cfg.reveng.JDBCReader processPrimaryKey
[hibernatetool] WARNING: Rev.eng. strategy did not report any primary key columns for my_table
BUILD FAILED
C:\code\hibernate\build.xml:39: java.lang.NoSuchMethodError: org.hibernate.mapping.Component.<init>(Lorg/hibernat/mapping/PersistentClass;)V
at org.hibernate.cfg.JDBCBinder.handleCompositeKey(JDBCBinder.java:868)
at org.hibernate.cfg.JDBCBinder.bindPrimaryKeyToProperties(JDBCBinder.java:608)
at org.hibernate.cfg.JDBCBinder.createPersistentClasses(JDBCBinder.java:180)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:94)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:43)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:83)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:318)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
Thank you