有没有办法用Hibernate XML配置文件更改max_allowed_packet?
这是我对Hibernate的Spring注入
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql://localhost:3306/surveysmart</value></property>
<property name="username"><value>root</value></property>
<property name="password"><value>xxx</value></property>
</bean>
<!-- Session Factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="packagesToScan" value="com.sdl.contacts.vo" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
答案 0 :(得分:3)
max_allowed_packet
是一个mysql配置选项。您应该在mysql配置中设置它。
http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
答案 1 :(得分:1)
如果您想为此客户端连接更改它,您可以尝试将其作为jdbc url中的参数传递。
jdbc:mysql://localhost:3306/surveysmart?max_allowed_packet=<value>
正如@hvgotcodes建议更改mysql服务器配置更好。