I believe that I have a similar problem to this one, although I am using a mapping file and not using annotations. I have not found sufficient information in this thread to isolate my problem.
I am successfully using many-to-one unidirectional associations in Hibernate 3 to access my database objects as Java objects. I am trying to extend the hibernate mappings to add the reverse associations, with little success.
Specifically, I am trying to build a
bi-directional many-to-one association based on a foreign key between 2 subclasses of a common base class. When I try to traverse the one-to-many side, I get an exception dump which includes
"Unknown column 'imagesx0_.specimenId' in 'field list'" The table name used here is based on the name of the <set > mapping, not of the database table.
I believe the problem is that hibernate is choosing the wrong name for the related table. When I change the name of the set mapping, the error message changes. In the above, I had changed the name of the Set from "images" to "imagesX" and the error changed from "Unknown column 'images0_.specimenId'..." to "Unknown column 'imagesx0_.specimenId' ...".
The actual table name is "image"
Some details of the code and mapping file follow. The many-to-one direction of this mapping works properly, but not the reverse.
I would appreciate any ideas about what I've done wrong in this system. I can supply more details, if needed.
I have a mapping file with a base class (BaseObject) and 2 subclasses Image and Specimen, and tables baseObject, image and specimen. The image table has a specimenId field that is a foreign key to specimen. Both image and specimen have an "id" field that is a foreign key to baseObject.
The Java classes include
Code:
class BaseObject { String id ...}
class Specimen extends BaseObject {... Set imagesX;...}
class Image extends BaseObject {...Specimen specimen;...}
code fragment that causes error is:
Code:
getImagesX().iterator
The mapping files include
Code:
<subclass name="net.morphbank.rdfmetadata.Specimen"
extends="net.morphbank.rdfmetadata.BaseObject"
discriminator-value="Specimen">
<set name="imagesX" table="image" inverse="true" >
<key column="specimenId" />
<one-to-many class="net.morphbank.rdfmetadata.Image" />
</set>
<join table="SpecimenExtended">
... and...
Code:
<subclass name="net.morphbank.rdfmetadata.Image" extends="net.morphbank.rdfmetadata.BaseObject"
discriminator-value="Image">
<join table="image">
<key column="id" />
</property>
<many-to-one name="specimen" class="net.morphbank.rdfmetadata.Specimen" column="specimenId" />
...