title: org.hibernate.engine.jdbc.spi.SqlExceptionHelper 147 - Packet for query is too large
body: <p>I'm getting the below error when doing DB query using hibernate where it says the packet for query is too large. I don't quite understand from where it is coming.   </p>
  
  <blockquote>
    <p>21-07-2015 13:36:10,615  INFO [http-bio-9091-exec-7]
    com.aricent.aricloud.util.LoggerAspect 47 - Entered class
    com.aricent.aricloud.dao.AricloudDAOImpl Method   checkUserName<br/>
    21-07-2015 13:36:10,626  WARN [http-bio-9091-exec-7]
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper 145 - SQL Error: 0,
    SQLState: S1000<br/> 21-07-2015 13:36:10,630 ERROR
    [http-bio-9091-exec-7]
    <strong>org.hibernate.engine.jdbc.spi.SqlExceptionHelper 147 - Packet for query is too large (1083 > 1024). You can change this value on the
    server by setting the max_allowed_packet' variable.</strong></p>
  </blockquote>
  
  <p>I have set the variable <strong>max_allowed_packet=40M</strong> , but the packet seems to take 1024 as value. Where is this value coming from?</p>
  
  <p>Here is my method for select calling on which the issue is happening. The UserEntity table has only 13 rows in it and no other tables are having much data. If I restart mysql the application starts working, Please let me know how to fix the issue permanently ?</p>
  
  <pre><code>@Override
  @SuppressWarnings("unchecked")
  @Transactional
  public UserEntity checkUserName(String userName) {
      Session session = mySessionFactory.getCurrentSession();
      Query q = session.createQuery("SELECT e FROM UserEntity e WHERE userName = :userName");
      q.setParameter(USER_NAME, userName);
  
      List&lt;UserEntity&gt; list = q.list();
      if (!list.isEmpty()) {
          return list.get(0);
      } else {
          return null;
      }
  }
  </code></pre>