我希望从 hibernate.cfg.xml 做两件事 mysql 数据库;
要有 utf8 字符,这样它就可以保存字符 č,ć,ž,đ,š 并按原样重新使用它们,而不是 ? 在挂毯应用中。
修复 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
连接关闭后不允许操作。由于基础异常/错误,连接被隐式关闭:** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MESSAGE:从服务器成功接收的最后一个数据包是 48709 毫秒前。最后一个成功发送到服务器的数据包是在 48709 毫秒前,比服务器配置的“wait_timeout”值长。您应该考虑在应用程序中使用之前使连接有效性过期和/或测试,增加客户端超时的服务器配置值,或使用 Connector/J 连接属性“autoReconnect=true”来避免此问题。
我的 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>