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.

11 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

Unknown 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 .........

Unknown said...

Dude... You removed my headache..
I just came out from nightmare.. Thanks for this post...

Unknown said...

You.. removed my headache, Thanks for your post.

beth said...

Could you please tell me what versions you used to solve the problem? I've been dealing with this problem and I can't find the way to solve it yet
These are the maven dependencies I'm using:

org.hibernate
hibernate-core
3.3.1.GA


org.hibernate
hibernate-validator
4.2.0.Final


org.hibernate
hibernate-annotations
3.4.0.GA


Kind regards.