Java hibernate db UTF8无法正常工作

时间:2015-12-17 20:32:00

标签: java mysql hibernate utf-8

我在向数据库添加数据时遇到问题。

如果我添加文字HI, HOW ARE YOU? - 一切正常。

如果我尝试添加文本příliš žluťoučký kůň úpěl ďábelské ódy java servlet崩溃。

    HTTP ERROR 500

    Problem accessing /addPost. Reason:

        Server Error
    Caused by:

    java.lang.IllegalStateException: Transaction not active
        at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:70)
        at org.dao.GenericDaoJpa.commitTransaction(GenericDaoJpa.java:57)
        at org.dao.DefaultDaoRegister.saveTable_UserPost(DefaultDaoRegister.java:57)
        at org.manager.DefaultUserManager.addUserPost(DefaultUserManager.java:247)
        at org.web.servlet.AddPostServlet.doPost(AddPostServlet.java:31)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
        at org.web.filter.AuthenticationGuard.doFilter(AuthenticationGuard.java:41)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at 

org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Thread.java:745)
Powered by Jetty://

我不知道为什么。

我的persistence.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="org.my" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties> 
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>            
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.password" value=""/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="dialect" value="org.openmeetings.app.hibernate.utils.MySQL5MyISAMDialect" />       
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db?autoReconnect=true&amp;useUnicode=true&amp;createDatabaseIfNotExist=true&amp;characterEncoding=utf-8"/>
            <property name="hibernate.connection.CharSet" value="utf8" />
            <property name="hibernate.connection.characterEncoding" value="utf8" />
            <property name="hibernate.connection.useUnicode" value="true" />
            <property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
            <property name="hibernate.c3p0.min_size" value="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="300"/>                  
        </properties>
    </persistence-unit>
</persistence>

db的设置为:utf8_czech_ci

你能帮助我吗?

我不知道该怎么做。

我的应用程序在Netbeans的JETTY上运行。

0 个答案:

没有答案