get mapWith static domain field value from GrailsD

2019-06-03 07:57发布

How can I get mapWith property of a domain class?

I tried domainClass.mapWith as it's a static property of domain class.It didn't work. I also tried mappedBy but it's a different context.

Any idea on how can i get mapWith value from GrailsDomainClass

Below is my domain:-

public class Ticket {
    String id

    List<Long> productInstanceId

    static hasMany = [productInstanceId:Long]

    static mapWith = "none"

}

标签: grails gorm
2条回答
The star\"
2楼-- · 2019-06-03 08:38

If you are doing a direct check on a particular domain then you can fetch the static property with domain class. In your case it would be Ticket.mapWith or Ticket.class.mapWith.

If you are doing a dynamic check then you can find it with the help of DefaultGrailsDomainClass.

GrailsDomainClass aClass = new DefaultGrailsDomainClass(clazz)
aClass.mappingStrategy
查看更多
虎瘦雄心在
3楼-- · 2019-06-03 08:44

If you have the GrailsDomainClass you can access static properties via the Groovy (or Java) class using the getClazz() method or its clazz property form:

GrailsDomainClass dc = ...
String mapWith = dc.clazz.mapWith
查看更多
登录 后发表回答