Hi,
I'm just beginning to experiment with Hibernate. While creating new
tables/classes works beautifully, I'm having difficulty integrating new
tables with existing ones.
The new tables must contain keys to existing legacy Oracle tables, but
the new tables will be created in a different schema. I need the
classes for the new tables to reference the existing tables as foreign
keys. I've written two separate mapping files for this. One intended
to map to the new tables and the other to map to the existing tables.
I'm running CodeGenerator with both, but SchemaExport only with the
former because I can't modify the existing tables. Naturally when I run
SchemaExport with the latter, I receive the expected Oracle errors
telling me I can't modify the existing tables. That's a good thing,
since I don't want to do that anyway.
The mapping for the new tables is:
<hibernate-mapping>
<class name="foo" schema="New" table="new_table">
<id>...</id>
<property name="bar_key" type="java.lang.Integer"
length="64" not-null="true" column="bar_key"/>
<many-to-one name="bar" class="bar" column="bar_key"/>
</class>
</hibernate-mapping>
The mapping for the existing tables is:
<hibernate-mapping>
<class name="bar" schema="Old" table="existing_table">
<id>...</id>
<property name="bar_key" type="java.lang.Integer"
length="64" not-null="true" column="bar_key">
</class>
</hibernate-mapping>
When I run SchemaExport with the new table's mapping file, the error I
receive is:
[java] Error creating schema An association refers to an unmapped class:
bar
[java] net.sf.hibernate.MappingException: An association refers to an
unmapped class: bar
It appears SchemaExport doesn't "know" about the legacy tables, because
it didn't make them. How do I get SchemaExport to create tables for one
mapping file but not for the other, while allowing foreign key
references from the new to the old?
TIA,
Todd
|