-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: MySQL/Hibernate Blob - max_allowed_packet
PostPosted: Wed Jan 03, 2007 9:00 am 
Newbie

Joined: Fri Aug 11, 2006 1:38 pm
Posts: 3
Hibernate version: hibernate-3.1.3

Ddatabas: MySQL 5.0.24

I am using a Blob data object in my implementation. However, there is a limit to the size of data transmission between the MySQL server and the client (Hibernate in this case). The default value is set to a very low value (100k I think).

The MySQL website gives the following advice to increase the limit:
Quote:
B.2.9. Packet too large

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave.

The largest possible packet that can be transmitted to or from a MySQL 5.0 server or client is 1GB.

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues a Packet too large error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:

shell> mysql --max_allowed_packet=32M

That sets the packet size to 32MB.

The server's default max_allowed_packet value is 1MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOB columns). For example, to set the variable to 16MB, start the server like this:

shell> mysqld --max_allowed_packet=16M

You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file:

[mysqld]
max_allowed_packet=16M

It is safe to increase the value of this variable because the extra memory is allocated only when needed. For example, mysqld allocates more memory only when you issue a long query or when mysqld must return a large result row. The small default value of the variable is a precaution to catch incorrect packets between the client and server and also to ensure that you do not run out of memory by using large packets accidentally.

You can also get strange problems with large packets if you are using large BLOB values but have not given mysqld access to enough memory to handle the query. If you suspect this is the case, try adding ulimit -d 256000 to the beginning of the mysqld_safe script and restarting mysqld.


It is straightforward to set the max_allowed_packet parameter in the MySQL server. However I am not sure how to set this in the Hibernate configuration file hibernate.cfg.xml (assuming the value is set there).

When using JBoss/EJB this value is set in *-ds.xml file as follows:


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!--                                                                       -->
<!--  JBoss Server Configuration                                           -->
<!--                                                                       -->
<!-- ===================================================================== -->
<!-- ==================================================================== -->
<!--  Datasource config for MySQL using 2.0.11 driver                     -->
<!-- ==================================================================== -->

<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
   <connection-url>jdbc:mysql://172.29.30.126:3306/partnerNet</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>xxxxxxx</password>
     <max_allowed_packet>16,905,662</max_allowed_packet>
     <idle-timeout-minutes>1</idle-timeout-minutes-->
  </local-tx-datasource>
</datasources>


I would appreciate if anyone could shed some light on how to set this value in Hibernate. As indicated in the MySQL website the value has to be set in both server (MySQL) and the client (Hibernate).

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 9:12 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
You can pass arbitrary properties to the DriverManager with the property
Code:
hibernate.connection.<propertyName>


The <propertyName> will be the property passed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.