This is a Spring Hibernate implementation. I have defined a custom Type definition where I need to pass
one default value to my custom Type Definition class as below.
But the value is null please help me what am I missing here ?
@TypeDef(name = "customString", typeClass = com.mydomain.EncryptString.class)
public class employee{
private String empId;
private String empName;
@Type(type="customString")
private String passportNumber;
//setter and getters
}
public class EncryptString mplements UserType{
private String password; // inject via spring configurations
@Override
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
String encryptedPassport = rs.getString(names[0]);
System.out.println(names.length);
System.out.println("##"+password); // This null ????
return ""
}
//password getters and setters methods
}
Spring configurations
<bean id="customString"
class="com.mydomain.EncryptString">
<property name="password" value="password" />
</bean>
value of the password password in nullSafeGet()
method it prints Null. How to make it
inject ? I expect Spring will load all the given default values and it instantiate values
when the EncryptString class call via Hibernate annotation.
Updating my question with findings
I have saw a example where TypeDef pass spring bean id as a parameter as below.
@TypeDef(name = "encryptedString", typeClass =
org.jasypt.hibernate.type.EncryptedStringType.class, parameters = { @Parameter(name
= "encryptorRegisteredName", value = "hibernateStringEncryptor") })
Spring configuration is
<bean id="hibernateStringEncryptor"
class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor">
<property name="registeredName" value="hibernateStringEncryptor" />
<property name="password" value="password" />
<property name="saltGenerator">
<bean class="org.jasypt.salt.FixedStringSaltGenerator">
<property name="salt" value="salt"/>
</bean>
</property>
hibernateStringEncryptor configuration is injected via type def passing the bean id as a
parameter. I went through the code http://www.jasypt.org/download.html but could not figure
out the way the bean get injected.