code

Hibernate Proxy InstantiationException

Changing entities to be lazy loaded led me to the following problem:

@OneToMany(fetch = FetchType.LAZY)
Caused by: org.hibernate.HibernateException: Javassist Enhancement failed: Thing
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:72)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:402)
	at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3483)
….
Caused by: java.lang.InstantiationException: Thing_$$_javassist_38
	at java.lang.Class.newInstance0(Class.java:340)
	at java.lang.Class.newInstance(Class.java:308)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)

Thanks to Kristian I jumped straight to the problem. From the Hibernate docs:

Cat has a no-argument constructor. All persistent classes must have a default constructor (which can be non-public) so that Hibernate can instantiate them using Constructor.newInstance(). It is recommended that you have a default constructor with at least package visibility for runtime proxy generation in Hibernate.

This should probably read “It is essential….”

Anyway now everything is real lazy so happy days.

  • Share/Bookmark

hibernate

Comments (0)

Permalink

Log4J settings for working with Hibernate


	
	
  		
	
	
  		
	
	
  		
	
	

	

  • Share/Bookmark

hibernate

Comments (0)

Permalink

Installing JRuby with Intellij (OS X)

GET it from http://jruby.org/

There is a download page, download and exract the tar file somehwere.

I put it in /System/Library/Frameworks/JRuby.framework/jruby-1.5.1

I then created a symbolic link to jruby_current

ln -s jruby-1.5.1/ jruby_current

And then simply add it to my ~/.bash_profile

$vi ~/.bash_profile
export PATH=/System/Library/Frameworks/JRuby.framework/jruby_current/bin:$PATH
#Reload the profile…
$. ~/.bash_profile
#Try out jruby…
$jruby -v
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]

Now you can add the JRuby SDK to your Java Module in Intellij:

Now you can have ruby and Java in the same project. Awesome.

  • Share/Bookmark

build
intellij
java
jruby
ruby
thoughtblog

Comments (0)

Permalink

Google reader “shared items” plugin for wordpress

I find google reader a useful way to aggregate information from many blogs. Particularly convenient is to be able to read these on my iPhone and then mark them as shared. That way I can build up a list of information I am interested in.

This is then conveniently exposed as an RSS feed by google. You can see my shared items at http://www.google.co.uk/reader/shared/jim.barritt for example.

I used to have a sidebar on this site which had a snippet directly from google reader, but it was determined to have its own style. I wanted a wordpress plugin that would do it for me and found “Recommended Reading Google Reader” by C. Murray Consulting

Its the nice “READING” section on my sidebar. Thanks guys! You just saved me from writing my own!

  • Share/Bookmark

meta
thoughtblog
website

Comments (0)

Permalink

Make Fireworks IntelliJ Plugin Ignore Integration Tests


http://www.wafermaneuver.com/nick/img/photo/fireworks2.jpg

The Fireworks Plugin for IntelliJ allows you to automatically run all your unit tests when you make a change to the code.

Its a well behaved plugin, it allows you to configure wether or not to do this so you can just turn it on or off.

Whilst using it I made a detour to Shave a couple of Yaks. So thought I’d document it here.

I found it was also running some integration tests which relied on the file system and so didn’t work because there doesn’t appear to be a way to specify the working directory (you can specify JVM args so I could use that instead. I submitted an issue.

In the mean time, actually I thought I would rather not run my integration tests. Fortunately Fireworks allows a regex pattern to decide which files are tests.

After some hunting, I found the following post on stack overflow which gave me the clues i needed to include Test but not IntegrationTest.

The solution takes advantage of “lookaround” features of regex. The syntax in question is:

(?!Integration)

The (?! regex ) syntax means negative look ahead. You can put any regex in there. In our case, just “Integration”. This says, something not followed by “Integration”.

The code on stack overflow had some unnescessary syntax at the beginning (^) and I changed the ordering around a bit to make it read more logically.

(.(?!Integration))*Test

The first “^” was unnescessary, and putting the “.” first made it read better i think. The parentheses are to provide some structure (regex groups) more than any functional reason.

So in words, the new expression reads “match any repeating character (.*) not followed by “Integration” (?!Integration)), then only match if “Test” is on the end.

Here is a test case for it (which along with some other regex stuff can be found on Github :

    @Test
    public void matchesUnitTestsButNotIntegrationTests() {
        String expression = “(.(?!Integration))*Test”;
        Pattern pattern = Pattern.compile(expression);
        assertThat(pattern.matcher(“SomeUnitTest”).matches(), is(true));
        assertThat(pattern.matcher(“SomeIntegrationTest”).matches(), is(false));
        assertThat(pattern.matcher(“SomeNonTestClass”).matches(), is(false));
    }

I found it hard to get this to work on the command line with grep. But I’ve got too much YAK HAIR on my floor now!

Now the Yaks are shaved I can go back to putting a system property in to allow my integration test to work.

  • Share/Bookmark

code
regex
testing

Comments (0)

Permalink