• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

GRAILS, GORM custom mapping subclass in existing database.

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've got MySQL database which is used for PHP CMS system and I would like to do Grails application based on that database. In MYSQL I have tables contact, individual and organisation
contact:
int id
String display_name
...

and
individual
int id
int contact_id ( FOREIGN KEY )
String first_name
String last_name

organisation
int id
int contact_od
Sring name

--
So I would like in Grails to have Contact as domain class and parent for Individual and Organisation
like


but I can't find a proper definition for mapping to get list of Individuals ( i didnt include my mappings in the code because they dont work ).

Can anybode help me with that ?
 
author
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you get this figured out yet?

I haven't done this before so I can't say for sure how to map it, but you could try creating a similar model in a test app and let Grails create the schema and see what it does. That should give you some clues as to how to map it.

One thing you will need to do is set the mapping to table per class instead table per hierarchy. Like this:

static mapping = {
tablePerHierarchy false
}

Hope that helps,
Dave
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

Finally I found time to play with this problem. I did not get what I wanted at the beginning, but it might be because of not-so-perfect database schema.
So My original tables are

If Individual extends Contact, then our id for individual is defined by 'contact_id'. There is no need of having normal id in this table, so I just dont map id.

So my classes definition are:


Anyway thanks ( at least you forced me to play with Grails )
 
Everybody's invited. Even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic