gpt4 book ai didi

mysql - Hibernate mysql 问题

转载 作者:行者123 更新时间:2023-11-29 14:11:49 34 4
gpt4 key购买 nike

我希望从 hibernate.cfg.xml 做 mysql 数据库的两件事;

  1. 拥有 utf8 字符,以便可以保存字符 č,ć,ž,đ,š 并按原样重新使用它们,而不是?在挂毯应用中。

  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>

最佳答案

那么,在您的 cfg 文件中,对于 č,ć,ž,đ,š 字符,您还需要将字符集设置为 utf-8:

default-character-set=utf8

或者类似的东西,...,我不太喜欢这种 hibernate 的东西,但我知道你需要这样做。 “charset=utf-8

关于mysql - Hibernate mysql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379524/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com