我目前正在使用: - Scala v2.10 - Squeryl v 0.9.6 - MySQL Connector v5.1.28
我已经像这样定义了我的模型类:
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
}
但每当我尝试使用Squeryl方法在我的数据库上进行简单的选择时,我会收到此错误:
> [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:[]]
绝对绑定到注释:@Column("reply-to")
因为通过修改列的名称,错误消失并且查询已正常执行。不幸的是,更改列的名称对我来说不是一个选项,所以我请你帮忙寻找更好的解决方案。
答案 0 :(得分:2)
你肯定需要引用你的专栏,你可以做两件事:
默认情况下,在设置Mysql Adapter时可以引用:
new MySQLAdapter {
def quoteIdentifier(field: String) = "`"+field+"`"
}
或者您可以更改关系列字段
中的列名称object Schema1 extends Schema {
on(identities)(p => declare(
table1.reply_to is(named("myreplyto"))
)
}