<?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; jpa</title>
	<atom:link href="http://robin.mytechtip.com/tag/jpa/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>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>
	</channel>
</rss>

