gorm-hibernate5 icon indicating copy to clipboard operation
gorm-hibernate5 copied to clipboard

Can I dynamically register a domain?

Open ifree-zm opened this issue 3 months ago • 12 comments

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?

ifree-zm avatar May 14 '24 06:05 ifree-zm