-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unicode support
PostPosted: Fri May 02, 2008 3:15 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

Hibernate version:
3.2.6

Hibernate Annotations version:
3.3.1.GA

Hibernate EntityManager version:
3.3.2.GA

Is there any property I need to set in persistence.xml in order to support Unicode?

Please advise.

Thank you.

Regards,
Jap.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 5:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

the most important thing is that you created your database with the utf-8 character set. How you do that depends on your database type. Some databases, for example MySQL, support something like this as part of the JDBC connection string: ?useUnicode=true&characterEncoding=UTF-8 . This again is database specific.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 6:31 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
I try to put it to the database connect string as below:
Code:
<Resource name="jdbc/cis_mysql"
      auth="Container"
      driverClassName="org.gjt.mm.mysql.Driver"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"
      logAbandoned="true"
      removeAbandoned="true"
      removeAbandonedTimeout="60"
      type="javax.sql.DataSource"
      username="root"
      password="root"
      url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"/>


but tomcat throws the error, how to rectify?

Code:
May 2, 2008 6:26:27 PM org.apache.tomcat.util.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 54 column 71: The reference to entity "useUnicode" must end with the ';' delimiter.org.xml.sax.SAXParseException: The reference to entity "useUnicode" must end with the ';' delimiter.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1411)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:868)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanAttribute(XMLDocumentFragmentScannerImpl.java:1537)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1314)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2740)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
        at org.apache.catalina.startup.ContextConfig.processContextConfig(ContextConfig.java:782)
        at org.apache.catalina.startup.ContextConfig.contextConfig(ContextConfig.java:718)
        at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:987)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:279)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
        at org.apache.catalina.core.StandardContext.init(StandardContext.java:5071)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3984)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:448)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)


_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 8:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Since you using xml to configure the datasource you will have to escape the '&' with &amp; otherwise '&useUnicode' will be interpreted as incomplete xml entity.

Also have a look at this blog - http://www.warski.org/blog/?p=4. It might answer a few of your encoding questions.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 04, 2008 8:58 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

By the way, it seems like by putting the following in filter actually allows me to save & retrieve Unicode already.
Code:
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");


I removed the useUnicode & characterEncoding params from my datasource connection url and I also didn't put the the following in persistence.xml.
Code:
        <property name="hibernate.connection.useUnicode" value="true" />
        <property name="hibernate.connection.characterEncoding" value="UTF-8" />


Do I still need to put the above?

Please advise.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.