My combination of is Spring Boot + Spring Data Jpa + Multiple Databases. I am getting following NullPointer exception when starting the application. Feels like SPring Data with
Spring boot have AutoConfiguration classes enabled by default for the data sources allready on classpath. You should explicitly exclude AutoConfiguration class to disable.
Example :
@EnableAutoConfiguration(exclude = {JndiConnectionFactoryAutoConfiguration.class,DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,JpaRepositoriesAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class})
@ComponentScan
public class MyBootApplication {
public static void main(String[] args) {
SpringApplication.run(MyBootApplication.class, args);
}
}
Many thanks to Vishal for the idea. In my case it was generic-less implementation of javax.persistence.AttributeConverter
that provoked this exception. Changing
class MapConverter implements AttributeConverter<Map, String> { ... }
to class MapConverter implements AttributeConverter<Map<String, Object>, String> { ... }
really helped.
I faced the mentioned issue with mapping in OnetoOne relationship..
My app had the following OneToOne relationship.
A ||---|| B
B ||---|| C
Since its OnetoOne, I kept entity B primary key same as entity A, using @MapsId as mentioned here
https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/
Similarly I kept entity C primary key same as entity B.
I fixed this by changing the relationship like this
A ||---|| B
A ||---|| C
For me this turned out to be due to a custom implementation of org.hibernate.usertype.UserType
that I was using for mapping JSON types to Java objects.
In my particular case, it was mapping to a java.util.Map and this change in Spring Data JPA was causing a regression on upgrading to that version.
The fix was to explicitly set generic types for the Map - e.g. Map<String, Object>
in my case.