Back Forum Reply New

Cannot find entity with Chinese characters

Hi all:

I meet a problem when go through samples provided by ROO reference. It's the pizza shop sample.

1. I use finder to create a quot;findPizzasByNamequot; function.
2. one of Pizza's name is quot;#30000;#22253;#39118;#20809;quot; - it's in Chinese;
3. When I input quot;#30000;#22253;#39118;#20809;quot; and click quot;FINDquot;, the system said quot;no pizza foundquot;.

I make study for this issue. At the auto generated Pizza_Roo_Finder, I print a system log to see what is the input for query. The code are:
------------------------------------------
privileged aspect Pizza_Roo_Finder {      public static TypedQueryltizzagt; Pizza.findPizzasByName(String name) {       if (name == null || name.length() == 0) throw new IllegalArgumentException(quot;The name argument is requiredquot;);       EntityManager em = Pizza.entityManager();       TypedQueryltizzagt; q = em.createQuery(quot;SELECT Pizza FROM Pizza AS pizza WHERE pizza.name = :namequot;, Pizza.class);       q.setParameter(quot;namequot;, name);       System.out.println(quot;--- the name of Pizza#65306;quot; + name);       return q;   }   
}
-------------------------------------------

After check the system output, I found the Chinese characters are changed into quot;ç”°å›*风åquot;. I think it's the root cause. But I don't know why this happened, and how can I make it work?

Thanks very much for your help.

Hi litstone,

which version of Spring Roo are you using?
I just recently wrote a blog post named quot;broken special chars in Spring Roo?quot; which should address your problem.
2011/...pring-roo.html

Could you back on the points mentioned there - especially CharacterEncodingFilter - and tell us about your findings?

Thanks in advance
Alex

Hi Alex:

I use Roo 1.1.1 which integrated with STS 2.5.2
After reading your blog, I do check with the following results:

1. For the JSP encoding, the follows are source code of auto generated quot;findPizzasByName.jspxquot;. UTF-8 is the default encoding.
-------------------------------------
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot; standalone=quot;noquot;?gt;
lt;div xmlns:field=quot;urn:jsptagdir:/WEB-INF/tags/form/fieldsquot; xmlns:form=quot;urn:jsptagdir:/WEB-INF/tags/formquot; xmlns:jsp=quot;JSP/Pagequot; version=quot;2.0quot;gt;   lt;jsp:directive.page contentType=quot;text/html;charset=UTF-8quot;/gt;   lt;jsputput omit-xml-declaration=quot;yesquot;/gt;   lt;form:find finderName=quot;ByNamequot; id=quot;ff_com__roo_pizzashop_domain_Pizza  quot; path=quot;/pizzasquot; z=quotQQH+O5GWywOqtkENSeMZlRQAf0=quot;gt;       lt;field:input disableFormBinding=quot;truequot; field=quot;namequot; id=quot;f_com__roo_pizzashop_domain_Pizza_  namequot; min=quot;2quot; required=quot;truequot; z=quot;HqjSr5o+v3JSgXY9gA+J0IY4ChA=quot;/gt;   lt;/form:findgt;
lt;/divgt;
------------------------------------------------

2. For CharacterEncodingFilter secquence in web.xml file, I do the check and make adjustment according to your blog.

3. For database connection:
- I can input Chinese characters and save a quotizzaquot; to MySQL from Web Page
- I checked the data stored at MySQL. All Chinese data is saved properly.
- All Chinese characters can displayed properly on web page.

I do these updates as above. But the issue is still there. It looks I can create and display records properly on the Web through ROO. The only issue is how to find Chinese records.

I also hard code the query with Chinese characters in quot;findPizzasByNamequot; function in .aj file. In that situation, I can get the right result from MySQL.

I can send the whole project to you if you want. Thanks very much for your time and effort.

Hi litstone,

sorry, for not getting back to you for a while. I think the quickest way will be if you send me your project (completely packed as eclipse project?) including your db excerpt.

Do you use MySQL 5.1?

Please use the mail address from my blog. thanks in advance.

Alex
¥
Back Forum Reply New