title: "Packet for query is too large" in java web app with mysql
body: <p>I have web application running on tomcat 7  on ubuntu and connecting to a mysql database on same machine. to manage the connection I'm using a Hikari data source and I use Hibernate as the ORM.</p>
  
  <p>after running the server for few days I'm starting to get the following issue in the log files and all the requests starts to fail</p>
  
  <pre><code>Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1317 &gt; 1024). You can change this value on the server by setting the max_allowed_packet' variable.
  </code></pre>
  
  <p>I have set the max allowed packet variable in the mysql server as below in [mysqld] section.</p>
  
  <pre><code>key_buffer              = 16M
  max_allowed_packet      = 200M
  thread_stack            = 192K
  thread_cache_size       = 8
  </code></pre>
  
  <p>But I'm still getting this issue once few days and I need to restart tomcat and sometimes the mysql server too and once restarted it runs for another few days.</p>
  
  <p>In client entity manager factory i have following</p>
  
  <p></p>
  
  <pre><code>    &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan" value="com.***" /&gt;
  
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
              p:databasePlatform="org.hibernate.dialect.MySQL5InnoDBDialect"
              p:showSql="false" /&gt;
      &lt;/property&gt;
  
      &lt;property name="jpaDialect"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /&gt;
      &lt;/property&gt;
  
      &lt;property name="jpaPropertyMap"&gt;
          &lt;map&gt;
              &lt;entry key="javax.persistence.validation.factory" value-ref="validator" /&gt;
              &lt;entry key="hibernate.archive.autodetection" value="false" /&gt;
              &lt;entry key="hibernate.format_sql" value="false" /&gt;
              &lt;entry key="hibernate.generate_statistics" value="false" /&gt;
              &lt;entry key="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}" /&gt;
              &lt;entry key="hibernate.connection.charSet" value="UTF-8" /&gt;
              &lt;entry key="hibernate.bytecode.use_reflection_optimizer"
                  value="true" /&gt;
              &lt;entry key="hibernate.jdbc.use_scrollable_resultset" value="false" /&gt;
              &lt;entry key="hibernate.jdbc.use_streams_for_binary" value="true" /&gt;
              &lt;entry key="hibernate.jdbc.fetch_size" value="10" /&gt;
              &lt;entry key="hibernate.jdbc.batch_size" value="30" /&gt;
              &lt;entry key="hibernate.jdbc.batch_versioned_data" value="true" /&gt;
              &lt;entry key="hibernate.default_batch_fetch_size" value="16" /&gt;
              &lt;entry key="hibernate.order_inserts" value="true" /&gt;
              &lt;entry key="hibernate.order_updates" value="true" /&gt;
              &lt;entry key="hibernate.connection.max_allowed_packet" value="16905662" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I have followed few guides and configured the max_allowed_packet. but still getting the same issue. am I doing something wrong here?</p>