kvess kvess - 2 years ago 80
MySQL Question

Creating mysql table with reference to field in other table using groovy domain class

I am trying to create mysql table using groovy domain class. I have one master table and other table with has reference to field in the master table.
Let me explain more clearly. I have a master table










QualificationID (this field refers to QualificationID in QualificationMaster)

Please help me in getting this done by using groovy domain class with sample snippet...I searched a lot but I find it so confusing..please help me as i am very new to groovy and helps me a lot. I am using GGTS IDE for this.

Answer Source

Check this out:

class QualificationMaster{
    String QualificationName 
    Integer QualificaitonDuration

class UserQualificationMap{
    String Username
    String Email
    QualificationMaster Qualification

You do not have to use QualificationMaster.QualificaitonID as primary key for QualificationMaster. QualificationMaster.id is created by default for each domain class (you can check it in your db).

Therefore you can make a reference to QualificationMaster from UserQualificationMap. It will be mapped as QualificationMaster's primary key in UserQualificationMap table.

Moreover try to use shorter and lowercased names for properties in your domain classes. For example change QualificationMaster.QualificationName to QualificationMaster.name and QualificationMaster.QualificaitonDuration to QualificationMaster.duration.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download