views:

815

answers:

1

We have an existing and working database created from hbm mapping files.

We want to create some new tables for an optional feature.

One option is that these new tables always exist but we would prefer for the tables and POJOs to only be created on request.

My issue is that these tables/POJOs have dependancies on existing tables/POJOs. I have created a mapping file but I can only get it to work if it creates create/drop commands for the existing tables as well as the new ones, along with their POJOs as well.

Can I avoid this existing table/POJO for Group appearing in the creation script.

In the example below Group is an existing table/POJO.

 <id name="id" type="java.lang.Long">
  <column name="ID" not-null="true" />
 </id>

 <many-to-one name="group"
  class="uk.co.foo.domain.dfwv.Group"
  foreign-key="GROUP_FK" lazy="false" not-found="ignore">
  <meta attribute="use-in-tostring">false</meta>
  <column name="GROUP_NAME"
    not-null="true" />
 </many-to-one>
</class>

The ant target to generate this is below and only works if the dependant objects are listed:

   <fileset dir="${dfwv.mappings.dir}">
    <include name="**/groups.hbm.xml" />
   </fileset>
  </configuration>
  <hbmtemplate exporterclass="uk.co.foo.hibernateutils.tools.Exporter" templateprefix="config/foopojo/" template="config/foopojo/Pojo.ftl">
   <property key="jdk5" value="true" />
   <property key="ejb3" value="false" />
  </hbmtemplate>
 </hibernatetool>
</target>

Without the dependant reference to Group then I get the error:

BUILD FAILED C:\projects\foo\db-build.xml:187: Schema text failed: An association from the table DISCON_TEST refers to an unmapped class: uk.co.foo.domain.dfwv.Group

Hibernate version:3.1.2

A: 

couldn't you just comment out the mappings until you really need them ? hibernate needs a complete meta-modell of the provided entities and can't create just "stubs" for some of them

Michael Lange
I could and that would work but the builds are created from a build server so I would have to commit that change and run the same build target. At the moment at least I have a target that the build server can run for the new functionality without having to make any code changes.
Bill Comer
i guess with those new - but deactivated - entities comes additional business logic, do you keep that "deactivated" too ? wouldn't it break too, because the logic (will sometime)combines old and new entities ?sounds like maintance hell ;-)
Michael Lange

related questions