One to One Mapping in Grails GORM

********************Main class where we need column of other class***********************************
class ObjectMapping {

//int sourceMapId
String oldSourceCd
String oldPrintedSourceCd
int minUpo =1 //DEFAULT 1,
String newPrintedSourceCd
Date mapStartDate
Date mapEndDate
String clientId 
Date createdDate // DEFAULT SYSDATE,
String createdBy
Date modifiedDate
String modifiedBy

//added after requirement
BigDecimal oldCampaignId
BigDecimal newCampaignId
String newSourceCd

Client client
//static belongsTo= [Client]
//static mappedBy = [client: "client_id"]

static mapping = {

table "cf_source_cd_mapping"
id column: "source_map_id", generator:'sequence', params:[sequence:'SOURCE_MAP_ID_SEQ']
sort id: "desc"
version false
oldPrintedSourceCd column: 'old_printed_source_cd'
newPrintedSourceCd column: 'new_printed_source_cd'
oldSourceCd column: 'old_source_cd'
minUpo column: 'min_upo'
client column:["CLIENT_ID"]


static constraints = {

oldSourceCd (nullable: false, blank: false)
oldPrintedSourceCd (nullable: false, blank: false)
newPrintedSourceCd (nullable: false, blank: false)
minUpo(min:1,nullable: false, blank: false)
mapStartDate (nullable: false, blank: false)
mapEndDate (nullable: false, blank: false)
createdBy (nullable: false, blank: false)
modifiedBy (nullable :true, blank: true)
modifiedDate (nullable :true, blank: true)


****child class where we have details which i need to fetch d based on a column present in main class and here column is id****************************************************


import javax.persistence.FetchType;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

class Client {

//static hasMany =[objectMappings:ObjectMapping]
//static mappedBy = [objectMapping: "client_id"]

String clientName

static mapping = {

table "cf_client"
id column: "client_id", type:"long"
clientName coloumn: 'client_name'
version false


static constraints = {
********************************************************access in gsp like this***********************************************************************************

<g:each in="${objectMappingInstanceList}" status="i" var="objectMappingInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

         <g:each in="${objectMappingInstance.client}" var="client"> 



Popular posts from this blog

Conversion from Clob To String in java and Vice versa

Portable Java 8/ JDK8 setup without admin rights

Multi Threading , Producer consumer problem in Java