<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Objectopia &#187; Chris Clark</title>
	<atom:link href="http://objectopia.com/author/chrisclark78/feed/" rel="self" type="application/rss+xml" />
	<link>http://objectopia.com</link>
	<description></description>
	<lastBuildDate>Fri, 23 Dec 2011 12:33:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='objectopia.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Objectopia &#187; Chris Clark</title>
		<link>http://objectopia.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://objectopia.com/osd.xml" title="Objectopia" />
	<atom:link rel='hub' href='http://objectopia.com/?pushpress=hub'/>
		<item>
		<title>Hibernate and sets &#8211; use at your peril</title>
		<link>http://objectopia.com/2011/12/06/hibernate-and-sets-use-at-your-peril/</link>
		<comments>http://objectopia.com/2011/12/06/hibernate-and-sets-use-at-your-peril/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 23:52:56 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=389</guid>
		<description><![CDATA[For the past 3 weeks I&#8217;ve spent hours tuning the performance in one of the applications we use. Unfortunately rather than spend some time and come up with a proper reporting solution I was tasked to fix the existing solution which is to report off our live transactional system. We use EJB3 on JBoss so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=389&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For the past 3 weeks I&#8217;ve spent hours tuning the performance in one of the applications we use. Unfortunately rather than spend some time and come up with a proper reporting solution I was tasked to fix the existing solution which is to report off our live transactional system. We use EJB3 on JBoss so hibernate it is, which I personally think is an excellent framework for getting your application up and running quickly. Hibernate have always stated that performance isn&#8217;t it&#8217;s goal so I can&#8217;t blame hibernate for anything I&#8217;ve found. I tackled the problem in the usual way, add some sql logging and see what&#8217;s really happening and look for the usual suspects, lazy loading, code structure etc. Where I saw collections being loaded up separately I added Join fetches and rerun the reports. This worked really well then I noticed that no matter how I wrote the JPQL it always seemed to be running seperate queries for some of the realtionships. That&#8217;s when the bulb flashed they were defined as Sets!!</p>
<p>An example of such a thing:</p>
<p><pre class="brush: java; light: true;">
@OneToMany(mappedBy=&quot;transaction&quot;)
private Set taxComponents = new HashSet(1);
</pre></p>
<p>I understand why sets are used but as I&#8217;m in control of what gets put in I can safely use:</p>
<p><pre class="brush: java; light: true;">
@OneToMany(mappedBy=&quot;transaction&quot;)
 private Collection taxComponents = new ArrayList(1);
 </pre></p>
<p>So using set&#8217;s is great but it comes at a cost and beware it&#8217;s not just fetches but deletes and inserts have a similar issue in that they get deleted one by one and then reinserted to ensure uniqueness, so if you do update the set it also has a performance hit.</p>
<p>The performance of the major report moved from 30 mins to 6 mins, still not lightning fast but a good improvement. I could of course move to native SQL but I didn&#8217;t want to have to rewrite a load of code to do that.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/389/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/389/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=389&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2011/12/06/hibernate-and-sets-use-at-your-peril/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
		<item>
		<title>EJB 3.0 Injecting The Correct Implementation</title>
		<link>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/</link>
		<comments>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 21:49:07 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[EJB 3.0 injection]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=222</guid>
		<description><![CDATA[When using stateless and stateful session beans I often find that I&#8217;m creating one interface per one implementation, which will be enhanced with the release of the 3.1 spec and implicit interfaces. Anyway on one of the occasions I had actually had multiple implementations of an interface that I wanted to inject, this made me [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=222&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When using stateless and stateful session beans I often find that I&#8217;m creating one interface per one implementation, which will be enhanced with the release of the 3.1 spec and implicit interfaces. Anyway on one of the occasions I had actually had multiple implementations of an interface that I wanted to inject, this made me stop and think how do I that!! It turns out it was pretty simple with a few annotations.</p>
<p>On your class that is implementing the interface you need to use the name attribute: -</p>
<p><pre class="brush: java;">

@Stateful(name=&quot;xxx.AssetTypeOverrideService&quot;)
public class AssetTypeOverrideService implements OverrideService{

@Stateful(name=&quot;xxxRuleTypeOverrideService&quot;)
public class RuleTypeOverrideService implements OverrideService {

</pre></p>
<p>Then on the bean you want inject these into you use:</p>
<p><pre class="brush: java;">

@EJB(beanName=&quot;xxx.AssetTypeOverrideService&quot;)
private OverrideService assetOverrideService;
	
@EJB(beanName=&quot;xxx.RuleTypeOverrideService&quot;)
private OverrideService ruleTypeOverrideService;

</pre></p>
<p>The name can be anything you want I just think it&#8217;s logical to keep it the same as the class and the beanName obviously is the same value of the bean you want to inject that has the correct implementation. </p>
<p>It seems easy now but it did make me stop and think.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=222&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/24/ejb-3-0-injecting-the-correct-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
		<item>
		<title>EJB 3.0 Interceptors</title>
		<link>http://objectopia.com/2009/07/21/ejb-3-0-interceptors/</link>
		<comments>http://objectopia.com/2009/07/21/ejb-3-0-interceptors/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 04:55:23 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Java etc...]]></category>
		<category><![CDATA[EJB3 Interceptor]]></category>
		<category><![CDATA[entitylisteners]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=152</guid>
		<description><![CDATA[I wanted to carry out some processing when an entity was committed to the db, I could of used the lifecycle annotation @PostPersist in the bean itself but that that would go against leaky abstraction (see post Non-anaemic models). Anywho it was pretty simple to get this working all that I had to use were [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=152&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to carry out some processing when an entity was committed to the db, I could of used the lifecycle annotation @PostPersist in the bean itself but that that would go against leaky abstraction (see post <a href="http://objectopia.com/2009/05/20/non-anaemic-models-and-service-oriented-architectures/">Non-anaemic models</a>). Anywho it was pretty simple to get this working all that I had to use were a couple of annotations.</p>
<p>The first @EntityListerners which accepts an array of classes that will become your event handlers:</p>
<p><pre class="brush: java;">
@EntityListeners(ErrorListener.class)
public class SystemError implements Serializable {
</pre></p>
<p>The next is to annotate the methods in your listener class that will handle the various events. The annotations that can be used are:</p>
<ol>
@PrePersist 	Executed before the entity manager persist operation is actually executed or cascaded. This call is synchronous with the persist operation.
</ol>
<ol>
@PreRemove	Executed before the entity manager remove operation is actually executed or cascaded. This call is synchronous with the remove operation.
</ol>
<ol>
@PostPersist	Executed after the entity manager persist operation is actually executed or cascaded. This call is invoked after the database INSERT is executed.
</ol>
<ol>
@PostRemove	Executed after the entity manager remove operation is actually executed or cascaded. This call is synchronous with the remove operation.
</ol>
<ol>
@PreUpdate	Executed before the database UPDATE operation.
</ol>
<ol>
@PostUpdate	Executed after the database UPDATE operation.
</ol>
<ol>
@PostLoad	Eexecuted after an entity has been loaded into the current persistence context or an entity has been refreshed.
</ol>
<p>Note that if you are using EJB dependency injection it won&#8217;t work in your listener as it&#8217;s not managed by your container buy you can use jndi: -</p>
<p><pre class="brush: java;">
Context ctx = new InitialContext();
XXXService service = (XXXService) ctx.lookup(&quot;EARNAME/XXXServiceBean/local&quot;);
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=152&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/21/ejb-3-0-interceptors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
		<item>
		<title>Joda with JPA</title>
		<link>http://objectopia.com/2009/07/10/joda-with-jpa/</link>
		<comments>http://objectopia.com/2009/07/10/joda-with-jpa/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 01:41:22 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Java etc...]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Joda]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://objectopia.com/?p=176</guid>
		<description><![CDATA[I have to work with a few legacy databases that are used by several different apps (apparently the database is a perfect integration point), and I want to use the Joda api in my persistence. In this example the date is actually stored as a string, genius! I&#8217;m going to use LocalDate as the string [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=176&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have to work with a few legacy databases that are used by several different apps (apparently the database is a perfect integration point), and I want to use the <a href="http://joda-time.sourceforge.net/faq.html">Joda</a> api in my persistence. In this example the date is actually stored as a string, genius! I&#8217;m going to use LocalDate as the string doesn&#8217;t store the time element. If you are lucky enough and the database is actually storing date time check this post out <a href="http://nerdgerl.wordpress.com/2009/06/18/how-to-map-joda-times-with-hibernate/">Joda With DateTime</a></p>
<p>To start with a create a simple helper class that converts String to LocalDate and LocatDate to String</p>
<p><pre class="brush: java;">
public static LocalDate createLocalDateForString(String dateString){
  DateTimeFormatter fmt = DateTimeFormat.forPattern(&quot;yyyyMMdd&quot;);
  return StringUtils.isEmpty(value) ? null :  fmt.parseDateTime(dateString).toLocalDate();	
}
    
    public static String createStringForLocalDate(LocalDate date){
    	return date.toString(&quot;yyyyMMdd&quot;); 
    }
</pre></p>
<p>Next is to create your own user type. This is done by implementing org.hibernate.usertype.UserType. The main methods I&#8217;m implement are </p>
<p><pre class="brush: java;">
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
			throws HibernateException, SQLException {
		LocalDate result = null;
		String dateAsString = rs.getString(names[0]);
		if(!rs.wasNull()){
			result = StringUtils.isNotEmpty(dateAsString) ? DateHelper.createLocalDateForString(dateAsString) : null;
		}
		return result;
	}

public void nullSafeSet(PreparedStatement statement, Object value, int index)
			throws HibernateException, SQLException {
		if(value == null){
			statement.setNull(index, SQL_TYPES[0]);
		}else{
			String dateAsString = DateHelper.createStringForLocalDate((LocalDate)value);
			statement.setString(index, dateAsString);
		}
}
</pre></p>
<p>All that is left is to add the annotation to each of your entity properties that you want to use as LocalDate.</p>
<p><pre class="brush: java;">
@org.hibernate.annotations.Type(type = &quot;xxx.LocalDateUserType&quot;)
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=176&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/10/joda-with-jpa/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Hibernate Search in SEAM 2.0 Application</title>
		<link>http://objectopia.com/2009/07/01/using-hibernate-search-in-seam-2-0-application/</link>
		<comments>http://objectopia.com/2009/07/01/using-hibernate-search-in-seam-2-0-application/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 04:24:37 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Java etc...]]></category>
		<category><![CDATA[Hibernate search]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[SEAM]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/?p=129</guid>
		<description><![CDATA[I implemented hibernate search recently in a SEAM project I was working on. I wanted to use the excellent suggestion tag from the excedel library and I wanted to use an index rather than hitting the database for each of the searches. I also wanted to use wildcard searches and for each keystroke this would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=129&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I implemented hibernate search recently in a SEAM project I was working on. I wanted to use the excellent suggestion tag from the <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/suggestionBox.jsf?tab=info&amp;cid=859442">excedel</a> library and I wanted to use an index rather than hitting the database for each of the searches. I also wanted to use wildcard searches and for each keystroke this would be far to expensive. To implement it I completed the following steps: -</p>
<p>In my persistence.xml I added the following to the properties of my persistence-unit:-</p>
<p><pre class="brush: java;">
&lt;property name=&quot;hibernate.search.default.indexBase&quot; value=&quot;PATH TO YOUR INDEX DIRECTORY&quot;/&gt;
&lt;property name=&quot;hibernate.ejb.post-insert&quot; value=&quot;org.hibernate.search.event.FullTextIndexEventListener&quot;/&gt;
&lt;property name=&quot;hibernate.ejb.post-update&quot; value=&quot;org.hibernate.search.event.FullTextIndexEventListener&quot;/&gt;
&lt;property name=&quot;hibernate.ejb.post-delete&quot; value=&quot;org.hibernate.search.event.FullTextIndexEventListener&quot;/&gt;
</pre></p>
<p>The path of your index base can be anywhere you want as long as the application has permission to write to it.</p>
<p>To used hibernate search you need to identify and highlight all of the classes that you want to search, you also need to identify each of the properties that you want indexed and the indexing strategy, you can find out what the various types are here <a href="https://www.hibernate.org/410.html">Hibernate Search</a></p>
<p><pre class="brush: java;">
@Indexed(index=&quot;index_direcory&quot;)
public class SomeClass

@Field(index=Index.TOKENIZED, analyzer = @Analyzer(impl = LowerCaseAnalyser.class))
@Column(name = &quot;inv_name&quot;, length = 200, nullable = true)
private String name;
</pre></p>
<p>Inject an instance of FullTextEntityManager into your code. I used a stateless session bean that was used throughout the application</p>
<p><pre class="brush: java;">
@In
private FullTextEntityManger entityManager;
</pre></p>
<p>I used a three different query types, RegEx, Prefix and WildCard.</p>
<p><pre class="brush: java;">
RegexQuery(new Term(fieldName,&quot;.*[^-'\\w]&quot; + searchString.toLowerCase() + &quot;(\\s|$)&quot;));
PrefixQuery(new Term(fieldName,searchString.toLowerCase()));
WildcardQuery(new Term(fieldName,'*'+searchString.toLowerCase()+'*'));
</pre></p>
<p>The regex one was used to search for firstname surname i.e. Jo Bloggs. The prefix query was used to search for Jo* i.e. Joanne, Jo Bloggs. The wildcard one, the most expensive one, was used to search for *Jo* i.e. Jones, BillyJoBloggs. The fieldname is the obviously the name of the field, so in:- </p>
<p><pre class="brush: java;">
@Field(index=Index.TOKENIZED, analyzer = @Analyzer(impl = LowerCaseAnalyser.class))
private String name;  
</pre></p>
<p>FiledName would = name</p>
<p>All that is left to do it actually query the index and this is done by:</p>
<p><pre class="brush: java;">
entityManager.createFullTextQuery(query,SomeClass.class).getResultList();
</pre></p>
<p>This has been in production for a some time now and it&#8217;s been stable and performed well. There has only been one instance to date of the index getting screwed up but I catered for that and enable the index to be rebuilt. I also had to provide this as any update to the indexed fields via direct sql wouldn&#8217;t be updated. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=129&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/07/01/using-hibernate-search-in-seam-2-0-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
		<item>
		<title>Calling Stored Procedures in JPA</title>
		<link>http://objectopia.com/2009/06/26/calling-stored-procedures-in-jpa/</link>
		<comments>http://objectopia.com/2009/06/26/calling-stored-procedures-in-jpa/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 05:26:52 +0000</pubDate>
		<dc:creator>Chris Clark</dc:creator>
				<category><![CDATA[Java etc...]]></category>

		<guid isPermaLink="false">http://objectopia.wordpress.com/?p=8</guid>
		<description><![CDATA[Recently I had to call a stored procedure using JPA and to my surprise I soon found out that it&#8217;s not directly supported. So how do you call a stored procedure? My stack is Db = Sybase AppServer = JBoss 4.2.3 Java = 1.6 Persistance = EJB3 implemented by Hibernate Hibernate = 3.4.0.GA So the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=8&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I had to call a stored procedure using JPA and to my surprise I soon found out that it&#8217;s not directly supported. So how do you call a stored procedure? My stack is</p>
<p>Db = Sybase<br />
AppServer = JBoss 4.2.3<br />
Java = 1.6<br />
Persistance = EJB3 implemented by Hibernate<br />
Hibernate = 3.4.0.GA</p>
<p>So the first thing I do is to create a named native query on my entity which looks something like this:<br />
<pre class="brush: java;">
@NamedNativeQuery(name=&quot;StoredProc_Call&quot;,
                  query=&quot;stored_proc_name(:param1, :param2, :param3)&quot;,
                  hints={
                      @QueryHint(name = &quot;org.hibernate.callable&quot;,value = &quot;true&quot;), 
                      @QueryHint(name = &quot;org.hibernate.readOnly&quot;,value = &quot;true&quot;)
                  },
                  resultSetMapping=&quot;scalar&quot;, resultClass=Result.class)

@SqlResultSetMapping(name=&quot;scalar&quot;,columns=@ColumnResult(name=&quot;result&quot;)
</pre></p>
<p>Because I&#8217;m using hibernate as my EJB3 implementation, the default for JBoss, I can use it to call the stored proc for me using the hints attribute which takes in an array of queryhint objects.</p>
<p>Because native scalar results aren&#8217;t supported by EJB3 you also have to set the resultClass and the resultSetMapping.</p>
<p><pre class="brush: java;">
@SqlResultSetMapping(name=&quot;scalar&quot;,columns=@ColumnResult(name=&quot;result&quot;)
</pre></p>
<p>All that is required now is to create the native query, set the required parameters and call it.</p>
<p><pre class="brush: java;">Query query = entityManager.createNamedQuery(&quot;StoredProc_Call&quot;);</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/objectopia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/objectopia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/objectopia.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=objectopia.com&amp;blog=8328377&amp;post=8&amp;subd=objectopia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://objectopia.com/2009/06/26/calling-stored-procedures-in-jpa/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cb4e8f1d97dd63efbba72b45e6130bb0?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">chrisclark78</media:title>
		</media:content>
	</item>
	</channel>
</rss>
