Re: hibernate OneToMany composite key
On Sat, 12 Mar 2011, Lew wrote:
comp.lang.java.programmer wrote:
The same question was posted here
http://stackoverflow.com/questions/1995080/hibernate-criteria-returns-children-multiple-times-with-fetchtype-eager
Thanks, that's helpful. You clearly have strong Google-fu.
I found this, too:
<http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-optional-outerjoin>
<http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/performance.html#performance-fetching>
I'm beginning to understand why Hibernate systems turn out the way they do as
I read through its documentation.
The thing that really winds me up about Hibernate is that its developers
implement some completely boneheaded behaviour, then when someone points
out it's boneheaded, they furiously defend it as obviously being the only
right way to do it. They always manage to do it in a phenomenally
patronising tone, too.
The current case:
http://community.jboss.org/wiki/HibernateFAQ-AdvancedProblems#Hibernate_does_not_return_distinct_results_for_a_query_with_outer_join_fetching_enabled_for_a_collection_even_if_I_use_the_distinct_keyword
If you do a query for some class C, then if a found instance of C has a
one-to-many relationship with N instances of some class D, and if that
relationship is eagerly fetched, *the results of the query will contain N
references to C*. Even if D is not involved in the query. This is flat-out
idiotic, and there is no possible excuse for it.
And yet, how does the FAQ entry defending the indefensible begin?
First, you need to understand SQL and how OUTER JOINs work in SQL. If you
do not fully understand and comprehend outer joins in SQL, do not
continue reading this FAQ item but consult a SQL manual or tutorial.
Otherwise you will not understand the following explanation and you will
complain about this behavior on the Hibernate forum.
So if you have a problem with this idiotic, broken, behaviour, the problem
is that *you* are *too stupid* to understand outer joins! Not that the
authors of Hibernate are too stupid to understand deduplication. Oh, and
you're a whiny little whiner too!
FFS.
tom
--
Gin makes a man mean; let's booze up and riot!