-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to map objects with T1.a = T2.b or (T1.a = T2.b + 1)?
PostPosted: Sun Oct 10, 2004 2:36 pm 
Newbie

Joined: Sun Oct 10, 2004 2:19 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.