1

I have a domain and an enum like these:

class Order {
    static hasMany = [statuses: StatusEnum]
}

public enum StatusEnum {
    PAID("Paid")
    PICKED_UP("Picked Up")
}

I'm trying to use withCriteria to find an order which has been picked up:

Order.withCriteria {
    statuses {
        ...
    }
}

However, I'm getting a hibernate error:

org.hibernate.MappingException: collection was not an association

According to this SO question It seems that this is limitation of Hibernate (or at least it was at the time - 2011). There is even an unresolved Grails issue report: GRAILS-5989.

Does anyone have any suggestions on how to write a criteria for this relationship without going HQL (and preferably leaving the domain as is)?

Community
  • 1
  • 1
zoran119
  • 10,657
  • 12
  • 46
  • 88
  • Check out this: http://stackoverflow.com/questions/4253019/passing-enum-list-to-criteria – Michal_Szulc Jan 25 '16 at 12:47
  • To persist the `statuses` collection, I'm assuming gorm has to have a separate table for the association between the enum and the root class (I don't know of any other way). Considering this, you may want to have this 'association' be an explicit class with just 2 fields (`order` and `statusEnum`) if the collection is a `Set` (unique) and you are okay with a composite PK; otherwise 3 fields with an additional id. This doesn't answer your question directly but is an alternative. – tylerwal Jan 26 '16 at 01:55

0 Answers0