Announcement Announcement Module
Collapse
No announcement yet.
Cannot find entity with Chinese characters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 "findPizzasByName" function.
    2. one of Pizza's name is "田园风光" - it's in Chinese;
    3. When I input "田园风光" and click "FIND", the system said "no pizza found".

    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 TypedQuery<Pizza> Pizza.findPizzasByName(String name) {
    if (name == null || name.length() == 0) throw new IllegalArgumentException("The name argument is required");
    EntityManager em = Pizza.entityManager();
    TypedQuery<Pizza> q = em.createQuery("SELECT Pizza FROM Pizza AS pizza WHERE pizza.name = :name", Pizza.class);
    q.setParameter("name", name);
    System.out.println("--- the name of Pizza:" + name);
    return q;
    }

    }
    -------------------------------------------

    After check the system output, I found the Chinese characters are changed into "田*风". 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.
    Last edited by litstone; Feb 13th, 2011, 06:59 AM.

  • #2
    Hi litstone,

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

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

    Thanks in advance
    Alex

    Comment


    • #3
      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 "findPizzasByName.jspx". UTF-8 is the default encoding.
      -------------------------------------
      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <div xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <jsp:output omit-xml-declaration="yes"/>
      <form:find finderName="ByName" id="ff_com_springsource_roo_pizzashop_domain_Pizza " path="/pizzas" z="PQQH+O5GWywOqtkENSeMZlRQAf0=">
      <field:input disableFormBinding="true" field="name" id="f_com_springsource_roo_pizzashop_domain_Pizza_ name" min="2" required="true" z="HqjSr5o+v3JSgXY9gA+J0IY4ChA="/>
      </form:find>
      </div>
      ------------------------------------------------

      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 "Pizza" 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 "findPizzasByName" 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.
      Last edited by litstone; Feb 13th, 2011, 09:33 PM. Reason: provide more information

      Comment


      • #4
        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

        Comment


        • #5
          see
          http://forum.springsource.org/showth...-to-be-decoded
          Such is the case with finder by Japanese language, using GET method.

          Comment

          Working...
          X