What\'s the best/easiest way to get a list of the persistent properties associated with a given GORM domain object? I can get the list of all properties, but this list cont
As of grails 3.3.0
All code that uses the
GrailsDomainClass
orGrailsDomainClassProperty
classes should be re-written to use the mapping context api.To get started, inject the
grailsDomainClassMappingContext
bean. See the api documentation for more information on theMappingContext
,PersistentEntity
(GrailsDomainClass), andPersistentProperty
(GrailsDomainClassProperty)
For example:
class MyService {
def grailsDomainClassMappingContext //inject
def accessDomainProperties(Class clazz) {
PersistentEntity entityClass = grailsDomainClassMappingContext.getPersistentEntity(clazz.name)
List persistentPropertyList = entityClass.persistentProperties
persistentPropertyList.each { property ->
println property.name
}
}
}
Hope this helps someone.