Comments (11)
It seems to me, as if I have found the problem and could fix it. It was probably due to using Jakarta Persistence-API version 3.2.0-M1.
After changing Jakarta Persistence-API version from 3.2.0-M1 to 3.1.0 in my Maven pom.xml (according to Spring Boot migration guide, v3.1.0 is the default version supported by Spring Boot 3.2.x), the previously thrown exception concerning Spring Data JPA/Hibernate/Jakarta incompatibility no longer occurs :)
Although the jakarta.persistence-api dependency was commented out in my pom.xml, the jakarta-persistence.version set as a property in my pom.xml, apparently overwrites the value of the same property in spring-boot-starter-parent pom, which implicitly adds the appropriate jakarta.persistence-api dependency to the build.
Extracts from my current Maven pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
</parent>
<properties>
<jakarta-persistence.version>3.1.0</jakarta-persistence.version>
<!-- version 3.2.0-M1 does not work
<jakarta-persistence.version>3.2.0-M1</jakarta-persistence.version>
-->
</properties>
<!-- Already included by spring-boot-starter-data-jpa::hibernate-core -->
<!--
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta-persistence.version}</version>
</dependency>
-->
from spring-boot.
As far as I can see, this is not a conflict with Spring's EntityManagerInfo
mixin but rather with the Hibernate SessionFactory
interface itself declaring a getSchemaManager()
method that is incompatible with the new JPA 3.2 method of the same name. You could try to avoid HibernateJpaVendorAdapter
or override the getEntityManagerFactoryInterface()
method but that's only going to get you one step further; I would expect this to subsequently break in Hibernate itself.
Note that we are aiming for initial JPA 3.2 compatibility in Spring Framework 6.2, but so far, that's just covering proxy support for new methods in JPA 3.2. No specific incompatibilities are known in Spring's JPA support itself. Hibernate is a different matter.
from spring-boot.
We haven't seen this problem and no one else has reported it. Unfortunately, you haven't provided enough information for us to identify why things are behaving differently for you. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
from spring-boot.
I have the same issue, using spring boot 3.2.2, java 17 and the following coding:
package de.mycompany.vector.backend.config;
import jakarta.persistence.EntityManagerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.CollectionUtils;
import javax.sql.DataSource;
import java.util.Map;
import java.util.Properties;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "de.mycompany.vector.backend.dao",
entityManagerFactoryRef = "defaultEntityManagerFactory",
transactionManagerRef = "defaultTransactionManager"
)
public class DefaultDataSourceConfig {
private final Environment env;
private final JpaProperties jpaProperties;
public DefaultDataSourceConfig(@Autowired Environment env, @Autowired JpaProperties jpaProperties) {
this.env = env;
this.jpaProperties = jpaProperties;
}
@Bean(name = {"defaultDataSource"})
@Primary
public DataSource defaultDataSource() {
if (env == null) {
return null;
}
DriverManagerDataSource dataSource = new DriverManagerDataSource();
String url = env.getProperty("spring.datasource.url");
String driver = env.getProperty("spring.datasource.driver-class");
String username = env.getProperty("spring.datasource.username");
String password = env.getProperty("spring.datasource.password");
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
Resource initSchema = new ClassPathResource("schema.sql");
if (initSchema.exists()) {
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema);
DatabasePopulatorUtils.execute(databasePopulator, dataSource);
}
return dataSource;
}
/**
* provide a simple jdbc template to export data without all the expensive JPA/ORM functions
*/
@Bean(name = {"nbpJdbcTemplate"})
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(defaultDataSource());
}
@Bean(name = "defaultEntityManagerFactory")
@Primary
@Autowired
public LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory(
EntityManagerFactoryBuilder entityManagerFactoryBuilder,
@Qualifier("defaultDataSource") DataSource ds) {
return entityManagerFactoryBuilder
.dataSource(ds)
.packages("de.mycompany.vector.backend.model")
.properties(jpaProperties != null ? jpaProperties.getProperties() : null)
.persistenceUnit("default")
.build();
}
@Bean(name = "defaultTransactionManager")
@Primary
@Autowired
public PlatformTransactionManager defaultTransactionManager(EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
Any hints are very much appreciated!
Best regards
Maik
from spring-boot.
Command line output while start up is as follows:
jdk17.0.2\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:61495,suspend=y,server=n -XX:TieredStopAtLevel=1 -Dspring.profiles.active=dev -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" -javaagent:C:\Users\Me\AppData\Local\JetBrains\IntelliJIdea2023.3\captureAgent\debugger-agent.jar=file:/C:/Users/Me/AppData/Local/Temp/1/capture.props -Dfile.encoding=UTF-8 -classpath C:\Users\Me\AppData\Local\Temp\1\classpath477957752.jar de.mycompany.vector.backend.Application
Connected to the target VM, address: '127.0.0.1:61495', transport: 'socket'
MySpringBootBackendApp [Spring Boot Backend]
2024-02-27 17:33:51,302 INFO [background-preinit] o.h.v.i.u.Version: HV000001: Hibernate Validator 8.0.1.Final
2024-02-27 17:33:51,380 INFO [main] o.s.b.StartupInfoLogger: Starting Application using Java 17.0.2 with PID 30932 (C:\Develop\projects\myapp\src\backend\target\classes started by Me in C:\Develop\projects\myapp\src\backend)
2024-02-27 17:33:51,381 DEBUG [main] o.s.b.StartupInfoLogger: Running with Spring Boot v3.2.2, Spring v6.1.3
2024-02-27 17:33:51,382 INFO [main] o.s.b.SpringApplication: The following 1 profile is active: "dev"
2024-02-27 17:33:55,279 INFO [main] o.s.d.r.c.RepositoryConfigurationDelegate: Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-02-27 17:33:55,536 INFO [main] o.s.d.r.c.RepositoryConfigurationDelegate: Finished Spring Data repository scanning in 244 ms. Found 19 JPA repository interfaces.
2024-02-27 17:33:59,911 INFO [main] o.s.b.w.e.t.TomcatWebServer: Tomcat initialized with port 8081 (http)
2024-02-27 17:33:59,930 INFO [main] o.a.j.l.DirectJDKLog: Initializing ProtocolHandler ["http-nio-8081"]
2024-02-27 17:33:59,934 INFO [main] o.a.j.l.DirectJDKLog: Starting service [Tomcat]
2024-02-27 17:33:59,935 INFO [main] o.a.j.l.DirectJDKLog: Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-02-27 17:34:00,109 INFO [main] o.a.j.l.DirectJDKLog: Initializing Spring embedded WebApplicationContext
2024-02-27 17:34:00,112 INFO [main] o.s.b.w.s.c.ServletWebServerApplicationContext: Root WebApplicationContext: initialization completed in 8480 ms
2024-02-27 17:34:03,136 INFO [main] o.f.c.i.l.s.Slf4jLog: Database: jdbc:oracle:thin:@myDBHost:1234:XXX (Oracle 19.0)
2024-02-27 17:34:04,731 INFO [main] o.f.c.i.l.s.Slf4jLog: Successfully validated 133 migrations (execution time 00:01.188s)
2024-02-27 17:34:05,155 INFO [main] o.f.c.i.l.s.Slf4jLog: Current version of schema "NBP_TEST": 2.121
2024-02-27 17:34:05,187 INFO [main] o.f.c.i.l.s.Slf4jLog: Schema "NBP_TEST" is up to date. No migration necessary.
2024-02-27 17:34:06,689 INFO [main] o.e.s.o.t.o.p.UpfrontAllocatingPageSource: Allocating 20.0MB in chunks
2024-02-27 17:34:06,739 INFO [main] o.e.c.EhcacheManager: Cache 'keyAccountDataCache' created in EhcacheManager.
2024-02-27 17:34:06,746 INFO [main] o.e.s.o.t.o.p.UpfrontAllocatingPageSource: Allocating 10.0MB in chunks
2024-02-27 17:34:06,752 INFO [main] o.e.c.EhcacheManager: Cache 'meterInfoCache' created in EhcacheManager.
2024-02-27 17:34:06,798 INFO [main] o.e.j.Eh107CacheManager: Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=file./C./Develop/projects/myapp/src/backend/target/classes/ehcache.xml,Cache=keyAccountDataCache
2024-02-27 17:34:06,802 INFO [main] o.e.j.Eh107CacheManager: Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=file./C./Develop/projects/myapp/src/backend/target/classes/ehcache.xml,Cache=meterInfoCache
2024-02-27 17:34:07,011 INFO [main] o.h.j.i.u.LogHelper: HHH000204: Processing PersistenceUnitInfo [name: default]
2024-02-27 17:34:07,149 INFO [main] o.h.Version: HHH000412: Hibernate ORM core version 6.4.1.Final
2024-02-27 17:34:07,238 INFO [main] o.h.c.i.RegionFactoryInitiator: HHH000026: Second-level cache disabled
2024-02-27 17:34:08,824 INFO [main] o.s.o.j.p.SpringPersistenceUnitInfo: No LoadTimeWeaver setup: ignoring JPA class transformer
2024-02-27 17:34:12,277 INFO [main] o.h.e.t.j.p.i.JtaPlatformInitiator: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-02-27 17:34:12,350 INFO [main] o.s.o.j.AbstractEntityManagerFactoryBean: Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-02-27 17:34:12,356 WARN [main] o.s.c.s.AbstractApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEntityManagerFactory' defined in class path resource [de/mycompany/vector/backend/config/DefaultDataSourceConfig.class]: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]
2024-02-27 17:34:12,369 INFO [main] o.e.c.EhcacheManager: Cache 'keyAccountDataCache' removed from EhcacheManager.
2024-02-27 17:34:12,372 INFO [main] o.e.c.EhcacheManager: Cache 'meterInfoCache' removed from EhcacheManager.
2024-02-27 17:34:12,382 INFO [main] o.a.j.l.DirectJDKLog: Stopping service [Tomcat]
2024-02-27 17:34:12,415 INFO [main] o.s.b.a.l.ConditionEvaluationReportLogger:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-02-27 17:34:12,450 ERROR [main] o.s.b.SpringApplication: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEntityManagerFactory' defined in class path resource [de/mycompany/vector/backend/config/DefaultDataSourceConfig.class]: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1231)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:949)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
at de.mycompany.vector.backend.Application.main(Application.java:21)
Caused by: java.lang.IllegalStateException: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.createEntityManagerFactoryProxy(AbstractEntityManagerFactoryBean.java:469)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769)
... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: methods with same signature getSchemaManager() but incompatible return types: [interface org.hibernate.relational.SchemaManager, interface jakarta.persistence.SchemaManager]
at java.base/java.lang.reflect.ProxyGenerator.checkReturnTypes(ProxyGenerator.java:311)
at java.base/java.lang.reflect.ProxyGenerator.generateClassFile(ProxyGenerator.java:488)
at java.base/java.lang.reflect.ProxyGenerator.generateProxyClass(ProxyGenerator.java:178)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.defineProxyClass(Proxy.java:558)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.build(Proxy.java:670)
at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$1(Proxy.java:440)
at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:438)
at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.createEntityManagerFactoryProxy(AbstractEntityManagerFactoryBean.java:464)
... 20 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:61495', transport: 'socket'
Process finished with exit code 1
Maik
from spring-boot.
what version of spring data jpa are you using?
from spring-boot.
Hi @stag33, I'm using version 3.2.2, as explicitly set for spring-boot-starter-parent.
All dependencies in your own pom.xml with <groupId>org.springframework.boot</groupId> are implicitly using the version set for spring-boot-starter-parent, except you explicitly provide a different version for them (what I do not recommend).
from spring-boot.
Thanks, @md4cc. Spring Framework (and therefore Spring Boot) doesn't not yet support JPA 3.2 so you should use the version of JPA that is provided by default.
@stag33 which version of JPA are you using in your application? The minimal sample that we have requested above would allow us to answer this.
from spring-boot.
Thanks @wilkinsona for confirming that JPA 3.2 is not supported, yet by Spring Boot 3.2.x and therefore the default JPA 3.1.0 should be used.
from spring-boot.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
from spring-boot.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
from spring-boot.
Related Issues (20)
- Runtime hint registration for property binding should not fail when parameter information is unavailable HOT 1
- RestClient Integration Test with MockRestServiceServer.bindTo fails HOT 2
- MethodArgumentNotValidException not raised anymore for jakarta validation HOT 4
- Single property support for JSON based values of GCP Secret Manager integration HOT 3
- Slow server shutdown starting with spring boot 3.2.x (tomcat) HOT 2
- 3.2.4 version can't be find in Maven repo https://mvnrepository.com/
- Document SBOM Support
- Docker Compose support doesn't work with Docker Compose 2.25.0 HOT 12
- Document CDS support HOT 4
- Implement strategy to redirect older documentation links to the new site
- Shorten fragment links HOT 1
- Review and splt up large documentation pages
- Replace links to code with links to javadoc HOT 1
- Develop 'apiref' macro for use in Antora
- Provide configuration properties documentation
- Move tools javadoc to a different module
- Migrate to always use xrefs in documentation HOT 1
- Use code-include for Gradle Groovy/Kotlin in documention
- Move older documentation to new location
- Create docs-build branch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.