Pergunta

Im trying to implement mapping in grails over hibernate for a table which has special characters in columne names. i.e "-"

Mapping in Domain Class

//properties
    Boolean  h00_02

//mapping
    static mapping = {
     h00_02 column : 'h00-02'
     }

Exception Stack Trace:

   2011-01-14 09:47:01,492 [http-8080-2] ERROR util.JDBCExceptionReporter  - Unknown column 'this_.h00' in 'field list'
2011-01-14 09:47:01,532 [http-8080-2] ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [GET] /Dailyreport/dates/list
Stacktrace follows:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'this_.h00' in 'field list'
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
 at com.mysql.jdbc.Util.getInstance(Util.java:381)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
 at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
 at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
 at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
 at dailyreport.DatesController$_closure2.doCall(DatesController.groovy:13)
 at dailyreport.DatesController$_closure2.doCall(DatesController.groovy)
 at java.lang.Thread.run(Thread.java:662)

Query: do you have any idea, how can i resolve aforementioned issue. Itried to escape it but it donot work too. I must use aforementioned column name because i m trying to develop UI on exsisting db.

Thanks in advance !

Foi útil?

Solução

Does this work?

static mapping = {
  h00_02 column : '`h00-02`'
}

(Or is that what you mean when you say "I tried to escape it"?)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top