Question

I'm currently using : - Scala v2.10 - Squeryl v 0.9.6 - MySQL Connector v5.1.28

I'have defined my model class like this:

class identities (
    val user_id: Long,
    val changed: String,
    val del : Long,
    val standard : Long,
    val name : String,
    val organization : String,
    val email : String,
    @Column("reply-to")
    val reply_to : String,
    val bcc: String,
    val signature: Option[String],
    val html_signature : Long,
    val pass : Option[String]) extends KeyedEntity[Long]
 {
    var identity_id : Long = 0
    def id = identity_id
 }

but whenever I try to do a simple select all query on my database using Squeryl methods I get this error :

> [RuntimeException: Exception while executing statement : You have an
> error in your SQL syntax; check the manual that corresponds to your
> MySQL server version for the right syntax to use near 'to as
> identities14_reply-to, identities14.signature as
> identities14_signature,' at line 9 errorCode: 1064, sqlState: 42000
> Select identities14.del as identities14_del, identities14.organization
> as identities14_organization, identities14.name as identities14_name,
> identities14.email as identities14_email, identities14.standard as
> identities14_standard, identities14.html_signature as
> identities14_html_signature, identities14.identity_id as
> identities14_identity_id, identities14.reply-to as
> identities14_reply-to, identities14.signature as
> identities14_signature, identities14.changed as identities14_changed,
> identities14.user_id as identities14_user_id, identities14.bcc as
> identities14_bcc, identities14.pass as identities14_pass From
> identities identities14 jdbcParams:[]]

that is absolutely bound to the annotation : @Column("reply-to") because by modifying the column's name the error disappear and the query is been executed normally. Unfortunately changing the column's name is not an option for me, so I ask you yo help finding a better solution.

Was it helpful?

Solution

you definitely need to quote your columns, you can do two things:

You can quote by default when instatiating the Mysql Adapter:

new MySQLAdapter {
     def quoteIdentifier(field: String) = "`"+field+"`"
}

Or you can change the column name in the relationship column-field

object Schema1 extends Schema {
  on(identities)(p => declare(
    table1.reply_to is(named("myreplyto"))
  )
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top