|
Hello everyone,
I'm new in Grails/Hibernate and i'm trying to do a domain modeling with the following sctucture class Object0 {
Map <Object1,List<Object2> = []
}This is because i need that the Object 0 have a Map of Objects1 that every Object1 have diferents Object2 depending of Object0. I'm trying to create a hasMany relationship with Objects but grails doens't accept object as Key of a map on Relationship Map <Object1,list<Object2>> relationship static hasMany = [relationship, Object1] But Hibernate error say's only String can be a key of a Map. What can i do? Thank's |
|
On 11/06/2012 15:02, Charlies wrote:
> But Hibernate error say's only String can be a key of a Map. > > What can i do? Think about modelling your domain slightly differently, using a domain class to represent the association: class ObjectRelationship { Object1 o1 Object2 o2 } Then instead of myObject0.relatedObjects.get(someO1) you do ObjectRelationship.findAllByO1(someO1)*.o2. Or you can write a utility method in Object0 itself to do this: class Object0 { List<Object2> findObject2sFor(Object1 obj) { ObjectRelationship.withCriteria { eq('o1', obj) projections { // return the Object2 rather than the ObjectRelationship property('o2') } } } } then you can say myObject0.findObject2sFor(someO1) Ian -- Ian Roberts | Department of Computer Science [hidden email] | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I thought in the possibility to create a different domain model but my application requires this specific scructure.
an Object relationship can be create easily with a couple of static hasMany relationship but i'm trying to use hibernate in all aplicacion without need to implement manually getters and setters and DDBB sctucture. Can i create a map or list in hibernate using object as a key? Thanks. 2012/6/11 Ian Roberts [via Grails] <[hidden email]> On 11/06/2012 15:02, Charlies wrote: -- -------------------------------------------------------------------------------------------------------------------------------- La información contenida en este mensaje y los archivos adjuntos son confidenciales. Si usted recibe este mensaje por error debe destruirlo sin copiarlo ni comunicarlo e informar inmediatamente por correo electrónico al emisor del mensaje. Cualquier comunicación, copia, distribución u otro uso de esta información no autorizado expresamente por el emisor del mensaje está prohibido legalmente. The information contained in this message and its attachments are confidential. If you have received this message by mistake, you must delete it without making any copy and communication. Furthermore, you have to immediately inform by e-mail about this incident to the sender. Any disclosure, reproduction, distribution or other of this information without the express permission of the sender it is legally prohibited. |
| Powered by Nabble | Edit this page |
