2012-11-14 87 views
0

有兩件事情我想從hibernate.cfg.xml中做mysql數據庫;休眠mysql的問題

  1. 要有utf8的字符,以便它可以攢人品C,C,Z,DJ,S和repoduse他們作爲大公都不如?在Tapestry應用。

  2. 修復的com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException

No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MESSAGE: The last packet successfully received from the server was48709 milliseconds ago.The last packet sent successfully to the server was 48709 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

我hibermate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 
    <session-factory> 
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="connection.url">jdbc:mysql://localhost/200</property> 
    <property name="connection.username">root</property> 
    <property name="connection.password">123</property> 
    <property name="connection.autoReconnectForPools">true</property> 
    <property name="connection.autoReconnect">true</property> 
    <property name="hibernate.connection.useUnicode">true</property> 
    <property name="hibernate.connection.characterEncoding">UTF-8</property> 
    <property name="hibernate.connection.charSet">UTF-8</property> 
    <property name="connection.pool_size">5</property> 
    <property name="hbm2ddl.auto">update</property> 

    <!-- Print SQL to stdout. --> 
    <property name="show_sql">true</property> 
    <property name="format_sql">true</property> 
    <property name="use_sql_comments">true</property> 
    <property name="generate_statistics">true</property> 

    <property name="hibernate.transaction.flush_before_completion">false</property> 

    <!-- Mapping files --> 
    <mapping class="domaci.entities.Korisnik"/> 
    <mapping class="domaci.entities.Magazin"/> 
    <mapping class="domaci.entities.Rubrika"/> 
    <mapping class="domaci.entities.Strana"/> 

    </session-factory> 
</hibernate-configuration> 

回答

1

好,在你的CFG文件C,C,Z,DJ,的人物需要設置字符集設置爲UTF-8也:

default-character-set=utf8 

或這樣的事情,......,我不是很喜歡這個休眠的東西,但我知道,你需要做到這一點。 「的charset = UTF-8

0

也增加服務器超時旁邊的命令:

set @@global.wait_timeout=31536000 
set @@session.wait_timeout=31536000 
+0

沒有解決問題 – nkvnkv