gorm-hibernate5
gorm-hibernate5 copied to clipboard
Can I dynamically register a domain?
with gorm-hibernate5-spring-boot:7.3.1 my code was:
def groovyCode = """
package com.example.gorm.entity
import grails.gorm.annotation.Entity
import org.grails.datastore.gorm.GormEntity
@Entity
class Person implements{
String firstName
String lastName
}
"""
def groovyClass2= loader.parseClass(groovyCode);
def person = groovyClass.getDeclaredConstructor().newInstance()
person.invokeMethod("find", { lastName == "John" })
Running the above code will throw an exception:
Either class [com.example.newgorm.entity.Person] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
I found that domain will be registered to STATIC_APIS at project startup. Can I dynamically register Person domain now?