Hibernate version:
2.1.6
Mapping documents:
<hibernate-mapping package="example">
<class name="Report" table="reports" discriminator-value="r">
<id name="id">
<generator class="native"/>
</id>
<property name="reportDate" column="report_date" not-null="true"/>
<many-to-one name="species" not-null="true"/>
<component name="location" class="example.Location">
<property name="location"/>
</component>
<many-to-one name="certainty" not-null="true"/>
<many-to-one name="reporter" not-null="true"/>
<many-to-one name="timebehaviour" not-null="true"/>
<property name="remarks" />
</class>
</hibernate-mapping>
<hibernate-mapping package="example">
<class name="Location" table="locations" discriminator-value="l">
<id name="location">
<generator class="assigned"/>
</id>
<property name="name" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Query query = session.createQuery("from Report where .id=:id");
query.setInteger("id", id);
List list = query.list();
if (list.size() == 1) {
report = (Report) list.get(0);
}
Full stack trace of any exception that occurs:
None
Name and version of the database you are using:
PostgreSQL 7.4.5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I can now join these two objects together with the following where clause:
(Report.location = Location.location)
However, location is a property that can be looked up in table Location with the following condition:
(Report.location = Location.location) or (Report.location = substring(Location.location from 1 for 4)) or (Report.location = substring(Location.location from 1 for 2))
Hence no ordinary foreign key relation exists in the database and no <many-to-one> mapping can be made (like I have now in the mapping documents above).
Please let me know how I apply this condition to these two objects.
Thank you and best regards,
Jeroen
|