I need to configure @TypeDefs to use custom @Type at the package level. When I configured it as follows, I get a ClassNotFoundException. But when I set @TypeDefs at the class level, it works fine.
I found a similar postoverflow post , but I do not know how to configure the <resource package="com.foo.bar.thepackage"/> with my application-context.xml file.
According to some posts (as below), noted this Spring related error
I believe this is due to a bug in Spring, where it doesn't scan the annotations in package-info, but only those on classes annotated with @Entity, @Embeddable, or @MappedSuperclass. See https://jira.springsource.org/browse/SPR-8589.
Can anyone help me solve this problem. Thanks.
Declaring @TypeDefs with package-info.java
@TypeDefs ({ @TypeDef( name="encryptedString", typeClass=EncryptedStringType.class, parameters={ @Parameter(name="encryptorRegisteredName", value="abcHibernateStringEncryptor") } ) }) package com.abc.core.model; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; import org.hibernate.annotations.Parameter; import org.jasypt.hibernate4.type.EncryptedStringType;
context.xml applications
<context:annotation-config/> <context:spring-configured/> <context:component-scan base-package="com.abc"/> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/project.properties"/> <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" /> <property name="packagesToScan" value="com.abc.core.model" /> <property name="jpaProperties"> <props> <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.dialect">org.hibernate.dialect.PostgresPlusDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.use_sql_comments">false</prop> <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop> <prop key="hibernate.connection.autocommit">false</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <jpa:repositories base-package="com.abc" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <bean id="abcStringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"> <property name="algorithm"> <value>PBEWithMD5AndDES</value> </property> <property name="password"> <value>XXX</value> </property> </bean> <bean id="theHibernateStringEncryptor" class="org.jasypt.hibernate4.encryptor.HibernatePBEStringEncryptor"> <property name="registeredName"> <value>abcHibernateStringEncryptor</value> </property> <property name="encryptor"> <ref bean="abcStringEncryptor" /> </property> </bean>
@Type custom mapping entity class
package com.stee.rcm.core.model; @Entity @Table(name = "trail") public class Trail implements Serializable { @Id @GeneratedValue @Column(name = "ID") private Integer id; @Type(type="encryptedString") @Column(name = "DESCRIPTION") private String description; }
Exception
Caused by: java.lang.ClassNotFoundException : encryptedString