Thursday, February 25, 2010

Infinispan Went GA

Infinispan just went GA. Hibernate 3.5 is at a CR. It's getting to be time to try clustering our app using Infinispan and their cache provider for Hibernate.

We have a few machines in the QA lab just waiting for this. I hope our gb switch is fast enough to run an Infinispan cluster. Our app hauls a lot of content, and I noticed that they used Inifiband interconnects (way faster than any ethernet, widely used in high-performance computing) in their benchmarks.

If anyone has already tried Infinispan with Hibernate let me know how it went for you.

Upgrading To Spring and SpringSecurity 3.0

Tonight I upgraded our enterprise Java app to both Spring 3.0 and Spring Security 3.0.


Spring 3.0


Upgrading to Spring 3.0 was easy. It works with spring-*-2.5 XML schemas, so I didn't have to change any of my beans files. The only hitch is that we use Jersey and the jersey-spring module.

We build with maven, and this module's pom has versioned dependencies on Spring 2.5.x, so a bunch of <exclusions> were needed.

Spring Security 3.0

Spring Security was much harder to upgrade from 2.0.4 to 3.0.2. The module structures have changed, so it was a bit of trial and error to find the minimal set of spring-security modules that met our app requirements.

The trouble wasn't over once I had a clean build. Lots of the classes have changed packages, so a number of the beans in our spring security XML file needed to be fixed.

Our old Spring Security config had some quirks. It used the security namespace configuration to create the primary beans (it created them all with an underscore ID, like _formLoginFilter) then created two different filter chains using normal bean definitions.

This doesn't work in SS3. No choice but to manually set up all the bean definitions for all the components of SS. This might be good (lots of flexibility, I learned a ton about SS) but it took hours to get it just right.

The app is running smoothly now, using all the latest Spring goodness. Hope this helps someone!

Wednesday, September 23, 2009

Why is Lucene MoreLikeThis Final?

Lucene has a class MoreLikeThis which can used to build a search query finding documents similar to a passed example document.

This is very useful; in my RSS reader I allows users to find articles similar to an article they find interesting.

I'd like to do something a bit advanced: given an instance of class A, find similar instances of class B. The two classes are stored in separate Lucene indices; the vast majority of the time they are to be queried separately.

For some reason they have chosen to implement MoreLikeThis as final. I can't see any reason for this. I'd like to be able to extend it to add a new public Query like... method but no dice. The primary methods I need (createQuery()) to call are private so there doesn't seem to be a way around it:

I'll need to make my own version of the whole class. Ick. Looking at it positively, this will encourage me to learn the internals of the class instead of using it as a black box.

Saturday, September 19, 2009

Upgrading to EhCache 1.6.2 with Hibernate to enable JMX Monitoring

I couldn't (easily) find this answer, so here goes: Yes, it is completely OK to use 1.6.2 with Hibernate (3.3.2 in my case).

For whatever reason, the maven package hibernate-ehcache uses an old version of ehcache, version 1.2.3. This version doesn't support JMX (which is why I wanted to upgrade) but supposedly there are significant performance improvements in newer ehcache versions as well.

My app is maven/spring/hibernate, so first in your spring config make sure to use the Singleton version of the ehcache provider, otherwise you won't be able to turn on JMX:

<entry key="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" />


Then in maven, exclude the old version and bring in the new one:

        <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.3.2.GA</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.6.2</version>
</dependency>


Finally you will need to register JMX mbeans for your cache when your app starts:

        CacheManager manager = CacheManager.getInstance();
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true);


Now you can see how many items are in each cache region using JConsole. Enjoy!

Friday, September 18, 2009

Hibernate Search FTW

In praise of Hibernate Search:

-Search is both easy to learn and easy to use
-A great book "Hibernate Search in Action" is available to tame the learning curve
-It is very well designed, exposing just the right amount of the underlying Lucene extendability. I am using Filters, programmatic construction of complex queries, FieldBridges to search custom types, and a custom Scorer for result ranking

Just wanted to put this out there: If you're thinking of using Hibernate Search, jump in. To the Hibernate Search team: thank you!

Friday, July 17, 2009

JBossCache 3 vs Oracle Coherence

I'm looking at both products right now. If anyone has real world comparative experience, please chime in.

My initial impression is that Coherence has a more sophisticated replication scheme that eliminates the need for all data to be replicated to all nodes; this probably helps them to get closer to true linear scalability.

My other impression is that Coherence is insanely expensive. Their cheapest edition is $4600 per processor; whoa!

Hibernate and JBossCache

While attempting to move from EHCache to JBossCache I was having a hard time finding information or documentation. Then I found this: http://galder.zamarreno.com/wp-content/uploads/2008/09/hibernate-jbosscache-guide.pdf

It took me almost two hours to stumble across this, hopefully this saves someone some time.

Monday, May 25, 2009

Maven Plugins for Eclipse

I've tried both q4e and m2eclipse pretty thoroughly at this point and I hereby declare m2eclipse the winner. My application is a multi-module project and q4e got terribly confused, m2eclipse handles this better. It's not perfect but way better than switching out to the shell to build, and a real time saver if you frequently work across multiple modules. Go get it now: http://m2eclipse.sonatype.org/

Tuesday, May 19, 2009

Hibernate Redux

Hey big suprise, another long ignored hibernate bug (ok ok this one is only six months old), this time it is creating duplicate Foreign Keys (increasing the size of my DB, certainly not *helping* performance). At least there is a workaround. http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532

Monday, May 18, 2009

Has Hibernate Been Abandoned?

When I run into a serious defect like this one, and it hasn't been worked in almost a year, I have to wonder if anyone over at JBoss/RedHat works on Hibernate any more. Maybe they just decided to abandon it? Are there other similar big bugs that they seem to be studiously ignoring?
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3332