Say I have something like:
class Foo {
static mapping = {
table 'foo_table'
}
}
How can I get the name of foo_table
if I have a reference to an instance of this object?
Say I have something like:
class Foo {
static mapping = {
table 'foo_table'
}
}
How can I get the name of foo_table
if I have a reference to an instance of this object?
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
:Import
org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
.To get the table name from the domain class:
And to get the table name from an instance of the domain class: