Based on my last post: Spring JPA long SQL String for NativeQuery
I've managed to find a "place" to write clean SQLs so that I can directly copy and paste it in the DB software for faster testing.
But another problem comes, if I wan to segregate my orm.xml file, say:
I tried renaming the files as seen above, but it says the methods in the files are not found during startup. Any idea how I can let the project understand the multiple orm.xml files?
Probably you already found the solution, but still post mine here in case others are still struggling with this.
When working with Spring JPA and Spring Boot, you may be familiar with the way we configure data sources. So while configuring the entity manager factory, set the mapping resources to the (set of) ORM files you have, as below. This will override the default "META-INF/orm.xml" that Spring Boot does for you.
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
// ..
// other configurations removed for brevity
// ..
factory.setMappingResources("META-INF/orm/student_orm.xml", "META-INF/orm/teacher_orm.xml");
return factory;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With