Saturday, October 25, 2008

Hibernate "PreInsertEvent.getSource()" NoSuchMethodError.

I recently obtained the following error:

java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/engine/SessionImplementor;

This occurred when attempting to run a test on one of my Hibernate DAO entities.

The problem started when I updated some (but not all) of my hibernate .jar libraries, to enable the use of spring-test.jar to provide access to the helper org.springframework.test.AbstractTransactionalDataSourceSpringContextTests methods.

It turns out (http://opensource.atlassian.com/projects/hibernate/browse/HV-67) that the problem was:

Method getSource from an older version of the Hibernate Core is referenced.

It is stated within the compatibility matrix that Hibernate Validator 3.1.0.CR1 is compatible only with Hibernate Core 3.3.x version(s).Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/engine/SessionImplementor;

That is, I was using the latest Hibernate Core (3.3.x), but didn't have the most up to date Hibernate Validator. I downloaded a new hibernate-validator.jar and everything worked again.

8 comments:

Laran Evans said...

Thank you for posting this Glenn. This was the only post on the entire Internet that actually helped me move past the issue. For me, validator was being put onto the classpath from a project dependency before validator specific to my project. Thank you so much.

Anonymous said...

thanks, this took me away a terrible headache :)
Paolo

Daniele De Francesco said...

Thank you, Glenn this used to be a real PITA :-) ...
Cheers
Daniele

mike bavon said...

Thanks so much.

Phillip Darley said...

Thanks Glenn - saved me a lot of time

Anonymous said...

thks !
I spent half a day on this pb, before read your post.
Alex

Paul Sabou said...

Great post. Sometimes I'm amazed on how cryptic can the Hibernate messages become.

Anonymous said...

Even Though i have added the latest validator,it doesn't work.i am getting same error .please help me out .........