<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Robin&#039;s Tech Tips &#187; mysql</title>
	<atom:link href="http://robin.mytechtip.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://robin.mytechtip.com</link>
	<description>Just another My Tech Tip weblog</description>
	<lastBuildDate>Wed, 06 Jul 2011 02:35:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use OpenJPA with MySQL: Some Tips</title>
		<link>http://robin.mytechtip.com/2009/10/14/use-openjpa-with-mysql-some-tips/</link>
		<comments>http://robin.mytechtip.com/2009/10/14/use-openjpa-with-mysql-some-tips/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 03:02:01 +0000</pubDate>
		<dc:creator>robin</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javadb]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[openjpa]]></category>

		<guid isPermaLink="false">http://robin.mytechtip.com/?p=51</guid>
		<description><![CDATA[


OpenJPA is an implementation of the JPA (Java Persistence API) standards. Initially, I used OpenJPA with Derby which is also known as JavaDB. It works well. However, when i tried to use MySQL as the backend database, I encountered a few issues. Here are a few small tips i would like to share when using [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-3371750151985752";
google_ad_slot = "0950801022";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<br />
OpenJPA is an implementation of the JPA (Java Persistence API) standards. Initially, I used OpenJPA with Derby which is also known as JavaDB. It works well. However, when i tried to use MySQL as the backend database, I encountered a few issues. Here are a few small tips i would like to share when using OpenJPA with MySQL:</p>
<p><strong>Change the default storage engine</strong></p>
<p>By default, OpenJPA uses innodb as the storage engine. While my application does not need to support transactions and other fancy db features, i&#8217;d like to use more plain and &#8220;traditional&#8221; myisam storage engine. To do so, I just need to set the property &#8220;openjpa.jdbc.DBDictionary&#8221; with the value &#8220;TableType=myisam&#8221;. This property object is the one passed to the method &#8220;Persistence.createEntityManagerFactory(String, Properties)&#8221;.</p>
<p><strong>Allow to store bigger objects (blobs)</strong><br />
By default, OpenJPA maps the java object to mysql data type &#8220;blob&#8221;. However, as you may be aware of, blob type in mysql only can store up to 65536(2<sup>16</sup>) bytes of data (check http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html), which is quite smaller than the blob in JavaDB or Derby (2G).</p>
<p>Mysql does provide other data types which supports larger storage. mediumblob supports up to 16M while longblob up to 4G. So if I want to store objects other than 64K, I need to change the mapping in OpenJPA. To change the mapping, just set the same property &#8220;openjpa.jdbc.DBDictionary&#8221;, but with value &#8220;blobTypeName=mediumblob&#8221;.</p>
<p>If I want both myisam as storage engine and mediumblob as mapped blob type, the property should be set as: &#8220;TableType=myisam,blobTypeName=mediumblob&#8221;.</p>
<p><strong>Avoid the error &#8220;Packet too large&#8221;</strong><br />
Now i can save objects up to 16M in size to the database. I run my program, only to find another exception popped up. It says something like &#8220;Packet too large&#8221;.</p>
<p>This requires the change of mysql server setting as indicated in <a id="h6su" title="mysql documentation" href="http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/dev.mysql.com');">mysql documentation</a>. The setting &#8220;<a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet" onclick="javascript:pageTracker._trackPageview('/outbound/article/dev.mysql.com');"><span style="font-family: Courier New">max_allowed_packet</span></a>&#8220;, default to 1M bytes, is too small in my case.</p>
]]></content:encoded>
			<wfw:commentRss>http://robin.mytechtip.com/2009/10/14/use-openjpa-with-mysql-some-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

