Reputation: 11665
I am trying to use the Class.forName('com.mypack.MyDomain').newInstance()
to create an instance of the grails domain from its qualified name.
But Its throwing a ClassNotFoundException.
I assume this is because the .forName('')
expects the class to be a java class instead of a groovy class?
How to make this work in grails, or is there another method to create the domain object from the class name in String format.
Thanks Priyank
Upvotes: 1
Views: 3696
Reputation: 171194
Another route to try would be to do:
GrailsDomainClass dc = grailsApplication.getDomainClass( 'com.mypack.MyDomain' )
def newDomainObject = dc.clazz.newInstance()
Upvotes: 8
Reputation: 4096
Try
GrailsClass clazz = grailsApplication.getArtefactByLogicalPropertyName(DomainClassArtefactHandler.TYPE, className)
clazz.clazz.newInstance()
Upvotes: 1