Wednesday, 27 January 2010

HibernateTemplate/ Hibernate Session - difference between .get() and .load()?

In short: .get() retrieves it from db, while load() just gets it from
current session cache. Or that's how I understand this article.

Thursday, 21 January 2010

EasyMock gotchas

1. Using Easymock matchers when passing in known values to mock classes.

When we get errors like:

java.lang.IllegalStateException: 2 matchers expected, 1 recorded.
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(
at org.easymock.internal.ExpectedInvocation.<init>(

It means we are missing a matcher for our mocked classes.

Take this code, for example:

Map<String, Object> params = new HashMap<String, Object>();
List<Integer> groupIds = Arrays.asList(1,2,3);
params.put("groupIds", groupIds);

.queryForList((String)anyObject(), params))

Replace the last line with:

.queryForList((String)anyObject(), eq(params)))

"If you would like to use matchers in a call, you have to specify matchers for all arguments of the method call."

Otherwise, it should only be known values.

If you are mixing known values with matchers, you will have to use the eq() ("equals) static method


2. when mocking classes that are not an interface, like
SimpleJdbcTemplate, we need to use the createMock, replay, and verify
methods FROM org.easymock.classextension.EasyMock NOT FROM

otherwise, we get this error when running the test:

java.lang.IllegalArgumentException: not a proxy instance
at java.lang.reflect.Proxy.getInvocationHandler(
at org.easymock.EasyMock.getControl(
at org.easymock.EasyMock.reset(

Update 11 November 2010:
You no longer need to do the easymock.classextension package in (2) if you are using EasyMock 3. The package and classes still exist in EasyMock 3 only for backward compatibility. See the documentation.

Saturday, 16 January 2010

SRSLY? My email to my work address bounced because it had the word "SHIT"

"Delivery to the following recipient failed permanently:

<username removed of course>

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the
recipient domain. We recommend contacting the other email provider for
further information about the cause of this error. The error that the
other server returned was: 550 550 5.7.1 Inappropriate language
used:SHIT (state 18)."


I wonder if Telstra do the same to their work emails.

Monday, 11 January 2010

WTF? Error message that has 1st letter removed from each package name.

Got this error message when trying to run a test in IntelliJ IDEA 9.

NoClassDefFoundError: org/pache/ommons/bcp/asicDataSource

I don't really know what's going on, but somehow each of the package
groups has the 1st character missing. Bizarre.

I'll clean out the IDEA cache using "File --> Invalidate Caches" and
see if that fixes it.

Nope, didn't.

Further down the stacktrace it shows the right name:

Caused by: java.lang.ClassNotFoundException: