1

Is there a way to change max_allowed_packet with the Hibernate XML configuration file?

This is my Spring injection for Hibernate

<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>
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
Wenn
  • 339
  • 2
  • 4
  • 14

2 Answers2

3

max_allowed_packet is a mysql configuration option. You should set it in your mysql configuration.

http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
0

If you wan to changed it for this clients connections only you can try passing it as parameter in the jdbc url.

jdbc:mysql://localhost:3306/surveysmart?max_allowed_packet=<value>

As @hvgotcodes suggests it is better to change in the mysql server configuration.

gkamal
  • 20,777
  • 4
  • 60
  • 57
  • According to the documentation, "The session value of this variable is read only." http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_max_allowed_packet – Palesz Apr 11 '12 at 11:02
  • Unfortunately doesn't work for me, the attempt to insert a large blob still fails with `PacketTooBigException: Packet for query is too large (9371229 > 4194304)` – Martin Vysny Oct 15 '19 at 13:13