albartell wrote:
<one-to-one name="printjobuid" class="Printjob"/>
Just so I am understanding the above, that assumes class Printjob has a non-composite key, correct? And then it will map printjobuid to Printjob's uid? Makes sense.
No, this will work with a composite key as well - check the documentation on composite keys.
Quote:
Note that I use an IDE called MyEclipseIDE and each time I refresh my table from MySQL into the IDE it wipes out any custom hibernate configs out, so that is why I am trying to keep this in HQL.
Agreed, you can do what you need to do in HQL.
Quote:
However, in your example HQL, you aren't even using any properties from the Printjob table - so why do you need to join it?
I omitted a fairly large WHERE clause so it didn't confuse my original post. I check the Printjob.statusuid field to make sure it is a certain value, for instance. Sorry for the confusion.
Clarifying question - is statusuid also supposed to be a foreign key reference to another object? If so, can you include that?
Quote:
What do you _want_ to return in your query, and I can try to help you model it. IMHO the HQL language is very short-changed in the Hibernate documentation - it's quite powerful, but the concepts aren't well-described.
Let's keep it simple and modify the following HQL to JOIN Printjoboption.printjobuid to Printjob.uid. All I really need is to know how to JOIN to differently named columns in HQL.
SELECT DISTINCT pjo.printersettinguid
FROM com.loffler.copycenter.dao.Printjoboption pjo
LEFT JOIN com.loffler.copycenter.dao.Printjob pj
ON pjo.printjobuid=pj.uid
WHERE pj.statusuid=1
Thank you so much for your time pmularien, it is much appreciated.
Aaron Bartell
Well, remember - HQL doesn't care about
columns - that's the shift in thinking. You're already modeling the mapping between tables at the XML mapping level.
You can write it as follows:
Code:
select distinct pjo.printersettinguid
from com.loffler.copycenter.dao.Printjoboption pjo
join pjo.pj as pj
where pj.statusuid = 1
Assuming your Hibernate mappings are set up with the right relationships, that should just magically "work", joining the tables as required. Two further questions:
1. Is "statusuid = 1" referring to a specific object instance? If so, there are better ways to write that (see my question about where this is an FK reference, above)
2. Are you trying to return an object reference from this query? If so, you would be better to set up the relationship to
printersettinguid as a one-to-one (or as appropriate) relationship and return the whole PrinterSetting object.