0

In my project I want to store the Tamil characters in database. So I created the column for that with the datatype nvarchar(50).

Hibernate converts nvarchar to serializable. How to I set the value for this column?

Can anybody help to fix this issue?

jarlh
  • 42,561
  • 8
  • 45
  • 63
Selva
  • 1,620
  • 3
  • 33
  • 63
  • I guess you have to write a custom dialect by extending `SQLServerDialect ` that maps to the data type like nchar, nvarchar or ntext. something like `registerColumnType(Types.VARCHAR, 255, "nvarchar($l)")` – Amogh Jul 08 '15 at 13:59

2 Answers2

0

I guess you have to write a custom dialect by extending SQLServerDialect that maps to the data type.

public class CustomSQLServerDialect extends SQLServerDialect {

public CustomSQLServerDialect() {
    super();

    // Use Unicode Characters
    registerColumnType(Types.VARCHAR, "nvarchar($l)");        
  }
}
Amogh
  • 4,453
  • 11
  • 45
  • 106
  • @Amough,thanks,It's solved my problem partially.It allows to add the tamil fonts in db but when retrieving it dispaly ????? like this – Selva Jul 09 '15 at 11:44
  • Have you set `hibernate.connection.CharSet`,`hibernate.connection.characterEncoding` property to UTF8 and `hibernate.connection.useUnicode` to true. – Amogh Jul 09 '15 at 19:21
  • 1
    @Madhesh, With above three hibernate properties try setting DB connection string as `jdbc:mysql://localhost/MyDB?useUnicode=true&characterEncoding=utf-8 ` – Amogh Jul 09 '15 at 19:28
0

Madhesh, for having other languages characters in any of your fields in the Database, you don't need to worry about the types themselves, but you need to check the encoding that your field or table or even the Database itself is using (collation).

The most common one is utf8_general_ci:

Which is the best character encoding for Japanese language for DB, php, and html display?

I believe you can change these collations through the tool you use to access and modify your DB. Here are more detailed answers about character encoding and collations:

What does character set and collation mean exactly?

However, Tamil seems a special case, there is an open-tamil project for Tamil text processing in Github that may help you further, if UTF-8 encoding is not enough.

Community
  • 1
  • 1
Armfoot
  • 4,663
  • 5
  • 45
  • 60