jpa - Spring LocalContainerEntityManagerFactoryBean scanForPackages and Hibernate package-level type definitions -
in spring 3.1 , higher localcontainerentitymanagerfactorybean supposed able configure jpa entitymanagerfactory without persistence.xml. configuration included in bean definition localcontainerentitymanagerfactorybean instead.
when use packagestoscan method tell factory bean scan entity classes doesn't seem picking hibernate type definitions defined @ package level.
package-info.java:
@org.hibernate.annotations.typedefs({ @org.hibernate.annotations.typedef(name = "typea", typeclass = com.foo.type.a.class), @org.hibernate.annotations.typedef(name = "typeb", typeclass = com.foo.type.b.class) }) package com.foo.type;
spring-jpa.xml:
<bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean" lazy-init="true"> <property name="datasource" ref="datasource" /> <property name="persistenceproviderclass" value="org.hibernate.ejb.hibernatepersistence"/> <property name="jpavendoradapter"> <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" /> </property> <property name="jpapropertymap"> <map> <entry key="hibernate.dialect" value="com.foo.foodialect" /> <entry key="hibernate.default_schema" value="dba"/> <entry key="hibernate.cache.use_query_cache" value="false"/> <entry key="hibernate.cache.use_second_level_cache" value="true"/> <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.singletonehcacheregionfactory"/> <entry key="net.sf.ehcache.configurationresourcename" value="meta-inf/ehcache.xml" /> <entry key="javax.persistence.validation.factory" value-ref="validator"/> </map> </property> <property name="packagestoscan"> <list> <value>com.foo.domain</value> <value>com.foo.type</value> </list> </property> </bean>
is there way make work?
i found adding @mappedsuperclass annotation package level typedefs causes hibernate find , process them. doesn't seem pretty solution, i'm still looking better way if 1 exists.
package-info.java:
@mappedsuperclass // <---hack cause hibernate notice these type defs @typedefs({ @typedef(name = "typea", typeclass = com.foo.type.a.class), @typedef(name = "typeb", typeclass = com.foo.type.b.class) }) package com.foo.type; import javax.persistence.mappedsuperclass;
Comments
Post a Comment