-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to configure a custom LocalContainerEntityManagerFactoryBean to work with native #30498
Comments
@snicoll Can you please check and update the ticket? |
@kartik-kaushik there's no need to mention me. I saw the issue but I haven't had the time to look at it yet. |
Hi Team, |
@kartik-kaushik I did follow the link above to try to get back the sample that leads to the exception you've shared above. Downloading the sample again, it looks like unchanged to me. If you want support, please take the time to share a minimal sample that reproduces the issue. I believe that you should be able to reproduce the issue above without the requirement of Oracle. Thank you. |
Hi @snicoll sharing the updated link. Kindly find the reproducible sample at: |
@kartik-kaushik I've downloaded the sample above and built the image using |
@snicoll the version that we used are native compatible i hope. Boot is 3.0.4 as we migrated all our other apps to the same version and so we want to use the same. Is the any limitations to this version specifically? Let me know if you need something more to reproduce it. |
It would have been nice to state that upfront... Creating the JPA entity manager this way means that AOT has zero chance to pre-process your persistence unit at build time. Paging the data team (@mp911de) to see if they had similar report and if they can offer guidance. @Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean customDBEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("CustomDBDataSource") DataSource ds) {
return builder.dataSource(ds)
.packages("com.codingknownsense.oraclespringboot").persistenceUnit("CUSTDB")
.build();
} |
We hadn't had such requests yet. FWIW, Spring Data supports programmatic bean registration for managed types as our AOT processor obtains and inspects the |
@kartik-kaushik apologizes for the delay in triaging this. We do have an infrastructure to externalize the persistence unit scanning in a separate component that is detected and processed by AOT. To make this working in native, you should restructure your code a bit so that the scanning is known upfront. I've updated your sample as follows and the issue above doesn't occur: @Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean customDBEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("CustomDBPersistenceManagedType") PersistenceManagedTypes persistenceManagedTypes,
@Qualifier("CustomDBDataSource") DataSource ds) {
return builder.dataSource(ds)
.managedTypes(persistenceManagedTypes).persistenceUnit("CUSTDB")
.build();
}
@Bean(name = "CustomDBPersistenceManagedType")
public PersistenceManagedTypes customDBPersistenceManagedTypes(ResourceLoader resourceLoader) {
return new PersistenceManagedTypesScanner(resourceLoader).scan("com.codingknownsense.oraclespringboot");
} The key is to expose a bean of type We'll use this issue to improve the documentation. |
After the fix apply in spring-orm 6.0.9 for spring boot native as mentioned in ticket numbered #30437 (comment)
we tried again the same project. but still getting below error :
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate persister: com.codingknownsense.oraclespringboot.entity.CustomerRegistration] with root cause
java.lang.IllegalArgumentException: Unable to locate persister: com.codingknownsense.oraclespringboot.entity.CustomerRegistration
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:740) ~[na:na]
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:721) ~[na:na]
at [email protected]/java.lang.reflect.Method.invoke(Method.java:568) ~[userprofile-db-sync:na]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:360) ~[na:na]
The text was updated successfully, but these errors were encountered: