-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Thu May 31, 2012 7:50 am 
Newbie

Joined: Mon Apr 16, 2012 4:49 am
Posts: 6
Hi,

I'm using IBM Websphere RAD 8.0.3 , websphere portal 6.1 and MS SQL 2008 Server.
I'm new to hibernate. I,m trying to insert Turkish characters with hibernate3.0 to MS sql server but i have garbage characters instead of what i want.
For exapmle; instead of yaş=> ya? and isntead of İş birliği => ?? birli?i

My database language is SQL_Latin1_General_CP1_CI_AS.
I sould not change my database language because i have to communicate my prject with an old project and changing language my lead to problems, too.

In my hibernate.cfg.xml i tried to set character encoding property as;
<property name="hibernate.connection.characterEncoding">utf8</property>

and a as a second way i add the following to my connection url
useUnicode=true;characterEncoding=ISO-8859-9; or useUnicode=true;characterEncoding=utf8;

a third way a create a class named SQLServerDialect, give the path to "hibernate.dialect" property. The code is below;

import java.sql.Types;

public class SQLServerDialect extends org.hibernate.dialect.SQLServerDialect {

public SQLServerDialect() {
super();
registerColumnType(Types.CHAR, "nchar(1)" );

// Use Unicode Characters
registerColumnType(Types.VARCHAR, 255, "nvarchar($l)");
registerColumnType(Types.CLOB, "nvarchar(max)");

// Microsoft SQL Server 2000 support bigint and bit
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");

}

}


also tried to set the following properties in my persistence.xml;
<property name="hibernate.connection.charSet" value="ISO8859_1"/>
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.connection.defaultNChar" value="true"/>
<property name="hibernate.sendStringParametersAsUnicode" value="true"/>


but nothing change.


Can anyone help me?

Thanks in advance..


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Thu May 31, 2012 7:56 am 
Newbie

Joined: Mon Apr 16, 2012 4:49 am
Posts: 6
I am working on Microsoft XP Professional and my computer language is English(A.B.D)


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Mon Jun 18, 2012 9:59 am 
Newbie

Joined: Thu Mar 29, 2012 7:19 am
Posts: 7
did you tried setting column type to nvarchar? it worked for me.


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Mon Jun 18, 2012 11:52 am 
Newbie

Joined: Thu Jan 27, 2011 10:53 am
Posts: 12
Hello,
I had such problems with sqlserver not supporting utf 8 (use UCS7 instead)
You may have a look in that direction
Regards


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Thu Jun 21, 2012 10:05 am 
Newbie

Joined: Mon Apr 16, 2012 4:49 am
Posts: 6
Thank you for answers..

pdshelke, my column type is nvarchar already but it does not work for me.

fsouleil, i tried UCS7 encoding but nothing changed.

Is there any solutions?


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Fri Jun 22, 2012 3:35 am 
Newbie

Joined: Thu Mar 29, 2012 7:19 am
Posts: 7
Following are changes we made to work with japanese characters:

Changes in JSP Files:

a. Adding encoding type in JSP file as

<%@ page language="java" session="true" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Changes in tld (tag Library Descriptor) Files:

a. Adding encoding type in “c-1_0.tld”, “fmt-1_0.tld”, “spring.tld” and “pager-taglib.tld” file as

<?xml version="1.0" encoding="UTF-8" ?>

Changes in web.xml File:

a. Finally to get request from jsp page as in UTF-8 encoding type format, set Character Encoding Filter in “web.xml” file as below

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

Configuration Change in Server.xml File:

a. Set URIEncoding as "UTF-8” in “server.xml” file


Top
 Profile  
 
 Post subject: Re: Hibernate character encoding problem with MS SQL server 2008
PostPosted: Mon Jul 09, 2012 4:55 am 
Newbie

Joined: Mon Apr 16, 2012 4:49 am
Posts: 6
Thank you for your answer. I tried the following steps you given below.
It seems you are using spring framework. I'm using IBM RAD. So as filter class i wrote a little code and other steps are ok. But nothing change for me, the problem persist.
Code for filter class is below;

public class EncodingFilter {
protected FilterConfig filterConfig;
protected String encoding;

public void doFilter(ServletRequest request,
ServletResponse response, FilterChain chain) throws
IOException, ServletException {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws
ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}

}


pdshelke wrote:
Following are changes we made to work with japanese characters:

Changes in JSP Files:

a. Adding encoding type in JSP file as

<%@ page language="java" session="true" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Changes in tld (tag Library Descriptor) Files:

a. Adding encoding type in “c-1_0.tld”, “fmt-1_0.tld”, “spring.tld” and “pager-taglib.tld” file as

<?xml version="1.0" encoding="UTF-8" ?>

Changes in web.xml File:

a. Finally to get request from jsp page as in UTF-8 encoding type format, set Character Encoding Filter in “web.xml” file as below

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

Configuration Change in Server.xml File:

a. Set URIEncoding as "UTF-8” in “server.xml” file


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.