4
如何将类型为enum的mysql字段映射到grails域类?Grails:将类型为enum的mysql字段映射到域类
我在grails v.2.0.3中使用了现有的(legacy)mySQL数据库。我得到了错误的列类型的错误:
failed; nested exception is org.hibernate.HibernateException: Wrong column type in
facilities.ost_fac_syslog for column log_type. Found: enum, expected: varchar(255)
的SQL字段被定义为:
mysql> describe ost_fac_syslog;
+------------+---------------------------------+------+-----+--------------------
| Field | Type | Null | Key | Default
+------------+---------------------------------+------+-----+----------------------+
| log_id | int(11) unsigned | NO | PRI | NULL auto_increment |
| log_type | enum('Debug','Warning','Error') | NO | MUL | NULL | |
我的领域类是:
class OstFacSyslog {
static mapping = {
table 'ost_fac_syslog'
version false
id column: 'log_id', name:'logId'
logType column: 'log_type', type: 'enum', name: 'logType'
}
Integer logId
LogType logType
enum LogType {
Debug('Debug'), Warning('Warning'), Error('Error')
private final String toString
LogType(String toString) {this.toString = toString}
String getName() {name()}
String toString() {toString}
}
}
谢谢,我感谢所有帮助。
没有看到这个文件上。一直试图找出超过3小时。谢谢! – ibaralf