Reputation: 569
I've developed a project with Spring and JDBC, Now I'm trying to configure my Spring application with JPA and I was following this tutorial. I'm getting error at getObject()
under geJpaTransactionManager
method. I have included all JAR's mentioned. Am I missing any thing here?
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages = "net.jpa.spring")
public class AppConfig{
@Bean
public LocalEntityManagerFactoryBean getEntityManagerFactoryBean() {
LocalEntityManagerFactoryBean factoryBean = new LocalEntityManagerFactoryBean();
factoryBean.setPersistenceUnitName("LOCAL_PERSISTENCE");
return factoryBean;
}
@Bean
public JpaTransactionManager geJpaTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(getEntityManagerFactoryBean().getObject()); --> Getting error here
return transactionManager;
}
}
The error is
The method getObject() from the type AbstractEntityManagerFactoryBean refers to the missing type EntityManagerFactory
Upvotes: 2
Views: 1526
Reputation: 43
I think you might not have imported hibernate-jpa. The Maven dependency is as follows for hibernate-jpa. That is why the compiler is not able to detect the EntityManagerFactory.
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
Upvotes: 2