How can we configure SORM to support utf-8?

106 Views Asked by At

With the following model:

case class Link(url: String, title: String, image: Option[String])

I tried saving some utf-8 encoded string to mysql db:

Db.save(Link("http://test2.com", "測試中文", None))

But a tragic thing happened, I see '????' instead of '測試中文' in mysql.

I doulbe-checked the settings in my mysql, both database and table are configured correctly with utf-8. I was using hibernate on this database, utf-8 characters show correctly too. So this must be a SORM problem then.

Can we configure utf-8 in SORM too?

1

There are 1 best solutions below

0
On BEST ANSWER

I figured it out.

In the connection url, we have to add in 'useUnicode=true&characterEncoding=UTF-8'.

So, the total configuration looks like this:

import sorm._
object Db extends Instance(
  entities = Set( Entity[Link]() ),
  url = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=UTF-8"
)