Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.2
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:SQLServer 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I am trying to create a mapping document and HQL to improve the performance of an existing query that uses a couple existing objects where a very small subset of the full object graph is needed.
We have a location table that include a primary key, name, manager and some other fields. We also have a (many-to-many) join table for phone numbers. Locations can have multiple numbers but for the query in question, we are only interested in the 'primary' phone number row. The existing query gets a LocationBean that includes entirely too much data for the search screeen that displays on the location name, manager, primary area code and primary phone number.
I have created a 'LocationSummaryBean' that maps the (id, name and manager) fields from the location table into the object. In this object I also want a string field for the primary area code and string field for the primary phone number.
How do I define the mapping for these fields that exists in a different table? Or can't I?
We use XDoclet tags for our mapping.
Initially I tried setting defining a property for each field without the column specified but that just generated the column attribute with same value as the name attribute, which got an error finding the areaCode column. Then I removed the hibernate xdoclet property tag.
Then the next question is "how do I write the HQL (or mapping?) to get only the primary phone number row instead of getting a set of phone numbers?
The basic idea of the sql is like this:
Code:
select l.party_id, l.location_number, p.area_code, p.phone_number
from location l
left outer join phone_number p on l.party_id = p.party_id
where p.principle = 1