How to get the name of the table GORM object is mapped to?

前端 未结 2 1035
不思量自难忘°
不思量自难忘° 2021-02-07 07:38

Say I have something like:

class Foo {
    static mapping = {
        table \'foo_table\'
    }
}

How can I get the name of foo_table

2条回答
  •  抹茶落季
    2021-02-07 08:20

    JamesA's answer will work, but only if table name if defined explicitly, like in the question.

    If you wish to get a table name whether or not it was specified in mapping, it can be done using SessionFactory:

    def tableName = sessionFactory.getClassMetadata(Foo).tableName
    

提交回复
热议问题