Question

I am using Spring 3.1 + Hibernate 4.1 in my application. I want some fields(like password) to be stored in encrypted form using Jasypt. But in the integration i am facing exception below:

java.lang.AbstractMethodError: org.jasypt.hibernate.type.EncryptedStringType.nullSafeSet(Ljava/sql/PreparedStatement;Ljava/lang/Object;ILorg/hibernate/engine/spi/SessionImplementor;)V

For integration of spring+hibernate with Jasypt, i followed following steps:

  1. Added jasypt-1.8.jar in lib folder.

  2. Added following in dispatcher-servlet(Config File)

    < bean id="hibernateStringEncryptor" class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor" lazy-init="false"> hibernateStringEncryptor jasypt < / bean>

  3. Placed Following code on Entity:

    @TypeDef( name="encryptedString", typeClass=EncryptedStringType.class, parameters= { @Parameter(name="encryptorRegisteredName", value="hibernateStringEncryptor") } )

But it doesn't getting the expected result. Please help me to resolve this exception.

Regards,

Arun Kumar

Was it helpful?

Solution

According to the javadocs for EncryptedStringType:

A Hibernate 3 UserType implementation which allows transparent encryption of String values during persistence of entities.

And according to the Hibernate 4 Migration Guide:

References to org.hibernate.usertype.UserType methods should be changed as indicated:

nullSafeGet(ResultSet rs, String[] names, Object owner) should be changed to
nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) nullSafeSet(PreparedStatement st, Object value, int index) should be changed to nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)

so jasypt 1.8 wouldn't be compatible with Hibernate 4.x.

You'll have to upgrade to jasypt 1.9, which according to this offers Hibernate 4 support.

EDIT:

The Jasypt documentation provides a good overview.

This first sentence:

Jasypt provides the jasypt-hibernate3 and jasypt-hibernate4 artifacts for Hibernate integration. Since jasypt 1.9.0, these artifacts must be added to your classpath separately.

So you will need to add jasypt-hibernate4.jar to your classpath to resolve the compile error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top