Overflowers
我正在尝试用Spring Data JPA (2.1.4,似乎是最新的)获得ObjectDB (2.7.6_01,最新版本)。
Spring Data JPA的文档说需要一个2.1版的JPA提供程序。AFAIKT ObjectDB的JPA提供程序是2.0...不确定这是不是问题所在。
但我的问题是这个例外:
Caused by: java.lang.IllegalArgumentException: com.objectdb.jpa.EMF is not an interface这导致了:
EntityManagerFactory interface [class com.objectdb.jpa.EMF] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]我很高兴我的代码正确地选择了ObjectDB实体管理器工厂,但是Spring围绕这个类的CGLIB包装器(EMF)不能正常工作。
有人有什么想法吗?
Gradle依赖关系:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compile files('libs/objectdb-jee.jar')
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}然后,这两个@Beans中的任何一个(一个或另一个,而不是两个)会导致上面相同的EMF异常:
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
final ObjectdbJpaVendorAdapter vendorAdapter = new ObjectdbJpaVendorAdapter();
return vendorAdapter;
}或
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final ObjectdbJpaVendorAdapter vendorAdapter = new ObjectdbJpaVendorAdapter();
vendorAdapter.setShowSql(true);
vendorAdapter.setGenerateDdl(false);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("com.example.demo.persistence");
factory.setDataSource(dataSource());
factory.afterPropertiesSet();
return factory;
}我有一个无操作的DataSource @Bean来让Spring的某些方面保持愉快,但我不认为它在这个问题上起到了积极的作用。
根本不设置spring.jpa.*。
干杯
发布于 2020-01-10 03:48:51
您必须提供的Beans要简单得多:
@Bean
@ConfigurationProperties("app.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name="entityManagerFactory")
public EntityManagerFactory getEntityManagerFactoryBean() {
// this is the important part - here we use a local objectdb file
// but you can provide connection string to a remote objectdb server
// in the same way you create objectdb EntityManagerFactory not in Spring
return Persistence.createEntityManagerFactory("spring-data-jpa-test.odb");
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(emf);
return txManager;
}有了以上内容(以及pom.xml中的适当依赖项),就不需要进行任何额外的配置(即,不需要在application.properties中进行任何配置)。
可以在here中找到一个简单的工作示例。
https://stackoverflow.com/questions/54379167
复制相似问题