Grails criteria duplicate association path error
Asked Answered
L

0

6

I am trying to use aliases along with the normal association names in a criteria which is giving me "duplicate association path error" my classes are as follows

class FlightReservation{
    Flight flight
    User usr
    String title
 }

class Flight {
    String flightNumber
    Category category

}

class Category {
    String name 
}

Criteria query

 FlightReservation.createCriteria().list(){
     createAlias("flight", "flt", CriteriaSpecification.LEFT_JOIN)

     flight{
       location{
        eq("name", "abc")
      }
    }


     order("flt.flightNumber", "asc")

}

Now as i think about it, it seems obvious and perhaps a Hibernate limitation so i want to know if there's an alternate approach to achieve this

I know i can use fetchMode to load the flight association but eliminating alias from the query would make things difficult for order clause( which is going to be dynamic and nesting closures would make things ugly)

One might say why can't I use "flt" (alias) in both the places? Actually this other criteria which uses the nested closure instead of alias comes from some other part of the code and I am supposed to reuse that code.

Let me know, if the question isn't clear enough, any insights on this error would be really helpful.

Latona answered 29/10, 2014 at 16:44 Comment(3)
I have the same error and it is not obvious to me why that happens. Can you refine that in your question?Amatory
Are you using aliases ? In my case i had created an alias for the "flight"( -> "flt" ) field and then at the same time i was trying to form a criteria with the field name ( i.e "flight" ) instead of the alias "flt". I suppose hibernate doesn't allow you to use the original field name if you have created an Alias.Latona
Facing something similar. Bug in Hibernate? #28029658, hibernate.atlassian.net/browse/HHH-879Orit

© 2022 - 2024 — McMap. All rights reserved.