How to create an association by joining a non-primary key column

class Contact { String name String number } class Message { String text String number Contact contactInfo //If any } 

I need to join Message.number = Contact.number. Any thoughts on creating an association in Grails / GORM with a non-primary key column?

+7
source share
2 answers

I am sure that this is not possible in GORM, and I do not know if this is possible in regular Hibernate. But you can fake it:

 class Message { String text String number static transients = ['contactInfo'] Contact getContactInfo() { Contact.findByNumber(number) } void setContactInfo(Contact contact) { number = contact.number } } 
+5
source

Burt, this is possible with hibernate using the property-ref attribute

+4
source

All Articles