-
Jun 25th, 2008, 02:40 PM
#1
JavaConfig equivalents for JPA configuration
I'm trying to use JavaConfig for all our Spring configuration to avoid XML programming. So far I've been quite successful until I got to two problems, both related to JPA configuration.
The first issue is finding JavaConfig equivalent to <tx:annotationDriven/> tag. I looked at the source and there doesn't seem to be a simple bean declaration I can use in JavaConfig.
The second issue is EntityManagerFactory bean configuration. In XML I'm using
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />
</property>
<property name="persistenceUnitName" value="sonar" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.Oracle9iDialect" />
</bean>
</property>
</bean>
And that works fine. I've tried replacing that with the following JavaConfig (# means attribute "at" character which the forum software doesn't let me post):
#Bean
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setPersistenceUnitName("sonar");
bean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
bean.setJpaVendorAdapter(this.jpaVendorAdapter());
return bean;
}
#Bean
EntityManagerFactory entityManagerFactory() {
return getBean(EntityManagerFactory.class);
}
And I get NoSuchBeanDefinitionException: No bean named "sonar" is defined. "sonar" is the name of the JPA persistence unit.
Is there a complete example of JavaConfig JPA setup somewhere? I've searched forums and it seems that other people faced similar problems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules