David Newton wrote:I might have mapped this differently if I knew I'd be going from type -> ability... by making an inverse relationship you can get an ability type and its associated abilities w/o having to do a join like that. I'm not sure if that's what's causing the behavior you're seeing--I've never really done what you're doing the way you're doing it. I make those kinds of relationships explicit. Something to think about, anyway.
Wow... Okay, first off, I definitely put in the wrong
test code. My apologies... Here is the stuff I was using when I initially posted this topic:
And here is the native SQL I
was using in the command line, which returns exactly what I want (or so I thought...):
After sitting and thinking about what you said, I realized I was looking at this the wrong way. I
really should be using
this query:
I now realize that the first query did return what I wanted, plus more, since it is taking the results from
BOTH tables. That explains why I was getting back
BOTH Ability
AND AbilityType objects in the result set. In the 2nd query, it's only taking the results from the
Ability table, which is really what I need. So I guess I now have 2 followup questions:
1) How can I replicate the 2nd query using HQL? I tried using this:
And got this stack trace:
I then tried this method:
It worked, but when I got the list, it was a list of Object arrays (that included all the data in said arrays). Obviously, I want Ability objects.
2) All of the above said, do you still think I am going across this wrong, starting way back with how I created the AbilityType and Ability tables, and the relationship between them? Or was that just because of how I originally wrote the HQL statement (which obviously was showing something I didn't want).
Thanks for your time. It is much appreciated!