Hibernate Criteria and multiple join?

I have got exactly the same problem, and was able to resolve it like this.

I have got exactly the same problem, and was able to resolve it like this: return criteria. CreateCriteria(A. Class) .

CreateCriteria("b", "join_between_a_b") . CreateCriteria("c", "join_between_b_c") . CreateCriteria("d", "join_between_c_d") .

Add(Restrictions. Eq("some_field_of_D", someValue)); Note: "b", "c" and "d" in code above refer to attribute names in A, B and C classes, correspondingly (class A has attribute be and so on). For this solution you don't even need to have lazy and fetch parameters to be set in your A.hbm.xml.

There are some good examples in the bernate Reference material that show to use setFetchMode to fetch associations with an outer join. An example is: List books = sess. CreateCriteria(Book.

Class) . SetFetchMode("chapters", FetchMode. EAGER) .

SetFetchMode("reviews", FetchMode. EAGER) .list(); There is also information there about different fetching stragies that may be of use to you.

Actually this didn't work for me, I had to do it like in the answer I have posted. It could be because I had an extra criteria on the D. – mindas Feb 23 '11 at 18:19.

Try setting the fetch mode in your criteria, like: criteria. SetFetchMode(..., FetchMode. EAGER) This creates a join query.

You may find more details here.

Yes, in fact there are several ways of doing this: When mapping the association, set its lazyness to false and its fetch mode to join. This will affect all criteria queries. Use setFetchMode as detailed by the other answers.

Use criteria. CreateAlias (or createCriteria). This also allows you to further restrict the rows you want joined.

Or, you use something like this (but it's not a Criteria query): String query = "Select s.?, fl.?, fvl.?, fv.?, ffv.? from table1 s JOIN blah blah Order BY ...":; String aliasesArr = {"s","fl","fvl","fv","ffv"}; Class classesArr = {Table1. Class,Table2. Class, blah blah}; SQLQuery sqlquery = session.

CreateSQLQuery(query); for(int i=0; I 0){ for(int i=0; I Get(i);//get the current row ((Table1)currResult0)//this is the first table/alias/pojo The result is a List where each entry is an array that corresponds to the types in classesArr (the array indices correspond to the order of the aliases/classes).

1 The question asked for a solution with the criteria API, not with SQLQuery. Also, your solution is vastly more complicated than necessary. – meriton Feb 13 '10 at 14:12 I digress, just trying to show an alternative... – boxymoron Feb 13 '10 at 17:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions