GrailsDomainBinder.getMapping(Doamin) is returning null for non persisted domain in Grails-3.2.4

347 Views Asked by At

I have Two domains.

class ABC{

    String xyz

    static mapping = {
        discriminator column: 'ABC_TYPE_ID'
    }
}

and

class XYZ extends ABC{

    static mapWith = "none"

    static mapping = {
        discriminator value: 3
    }   
}

In Grails 2.5.5 below line works perfectly fine but after making the required changes it is not working in Grails-3.2.4 and is giving null.

Mapping mapping = new GrailsDomainBinder().getMapping(XYZ) //Works fine Grails 2.5.5

Mapping mapping = GrailsDomainBinder.getMapping(XYZ) // Giving null in Grails-3.2.4

Please help me in getting the Mapping object from the XYZ domain.

My findings:

I am using oracle db with commented #dbCreate:'' in application.yml.

After commenting static mapWith = "none" in XYZ domain i am getting the Mapping object and the corresponding table is not created in DB because of #dbCreate:''.

Are there any issue with this approach? if yes please provide me with alternative solutions.

1

There are 1 best solutions below

0
On

The static state part has been removed in recent versions of GORM. You need to use the MappingContext object to get what you want:

MappingContext mappingContext = .. // can be injected via Spring
Mapping mapping = (Mapping)mappingContext.getPersistentEntity(Foo).mapping.mappedForm

See http://gorm.grails.org/latest/hibernate/api/org/grails/datastore/mapping/model/MappingContext.html