<?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; database</title>
	<atom:link href="http://robin.mytechtip.com/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://robin.mytechtip.com</link>
	<description>Just another My Tech Tip weblog</description>
	<lastBuildDate>Wed, 09 Jun 2010 05:46:07 +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>Remember to Clear Entity Manager if Entities No Longer Used</title>
		<link>http://robin.mytechtip.com/2010/03/24/remember-to-clear-entity-manager-if-entities-no-longer-used/</link>
		<comments>http://robin.mytechtip.com/2010/03/24/remember-to-clear-entity-manager-if-entities-no-longer-used/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 05:04:55 +0000</pubDate>
		<dc:creator>robin</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[EntityManager]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[load]]></category>

		<guid isPermaLink="false">http://robin.mytechtip.com/?p=67</guid>
		<description><![CDATA[Recently  a lesson was learned about the proper use of Java JPA to persist a large number of records into database in a batch process.



Some times it is necessary to load the records line by line from a large file and insert into the database table. There can be several ways to do this:

Use the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently  a lesson was learned about the proper use of Java JPA to persist a large number of records into database in a batch process.</p>
<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>
</p>
<p>Some times it is necessary to load the records line by line from a large file and insert into the database table. There can be several ways to do this:</p>
<ul>
<li>Use the database provided tool to load the data into table. It can be a special sql command or a special stored procedure. This method is quite database specific and not portable.</li>
<li>Write the program to load the data into the database table (Using JDBC if the program is written in Java).  This method can be applied to different databases if the insert SQL statement conforms to a level of standard.</li>
<li>Use JPA to persist the object one by one. This allows for changing database more easily (under the condition that the JPA provider supports the database.</li>
</ul>
<p>We used the third options to load the records into the database as we want to support multiple databases without  low level tweaking. However, the first implementation seemed very slow compared with the second option. And it became slower and slower when process of persisting records  progressed.</p>
<p>After a few checking, we realized that we didn&#8217;t call the method &#8220;clear&#8221; of the class EntityManager each time we persisted the object.  The EntityManager kept managing these objects so the resource was not released immediately, making it become slower and slower.</p>
<p>Once we add the &#8220;clear&#8221; method call, the performance became acceptable. So lesson learned about the use of JPA.</p>
]]></content:encoded>
			<wfw:commentRss>http://robin.mytechtip.com/2010/03/24/remember-to-clear-entity-manager-if-entities-no-longer-used/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>
		<item>
		<title>derby db connecting problem (using ij)</title>
		<link>http://robin.mytechtip.com/2008/12/05/derby-db-connecting-ij/</link>
		<comments>http://robin.mytechtip.com/2008/12/05/derby-db-connecting-ij/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 02:52:43 +0000</pubDate>
		<dc:creator>robin</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[javadb]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://robin.mytechtip.com/2008/12/05/3/</guid>
		<description><![CDATA[derby db connecting problem (using ij)
This problem happened to me when i tried the apache derby database (now it&#8217;s also called java db, part of jdk 6).
Trying the following command in ij (the bundled simple console) just gave me an error like this &#8220;ERROR: Unable to establish connection&#8221;:
ij&#62; connect &#8220;jdbc:derby://localhost/firstdb;create=true&#8221;;
It&#8217;s annoying, because i didn&#8217;t know [...]]]></description>
			<content:encoded><![CDATA[<p>derby db connecting problem (using ij)</p>
<p>This problem happened to me when i tried the <a id="fu93" title="apache derby database" href="http://db.apache.org/derby/" onclick="javascript:pageTracker._trackPageview('/outbound/article/db.apache.org');">apache derby database</a> (now it&#8217;s also called <a id="l3fl" title="java db" href="http://developers.sun.com/javadb/" onclick="javascript:pageTracker._trackPageview('/outbound/article/developers.sun.com');">java db</a>, part of jdk 6).<br />
Trying the following command in ij (the bundled simple console) just gave me an error like this &#8220;ERROR: Unable to establish connection&#8221;:</p>
<blockquote id="bsue"><p>ij&gt; connect &#8220;jdbc:derby://localhost/firstdb;create=true&#8221;;</p></blockquote>
<p>It&#8217;s annoying, because i didn&#8217;t know what&#8217;s wrong from the error message.<br />
Finally, i found out the reason, which is quite trivial. That is: i should not use the double quote (&#8221;) to quote the database url. Instead, i need to use single quote (&#8217;).</p>
<p>Maybe it&#8217;s documented somewhere in the derby documents, which , unfortunately, i missed.</p>
<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>
</p>
]]></content:encoded>
			<wfw:commentRss>http://robin.mytechtip.com/2008/12/05/derby-db-connecting-ij/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
