当我执行几个Rest api调用时,我遇到了MariaDB的问题:
17:05:53,188 ERROR [org.springframework.boot.web.servlet.support.ErrorPageFilter] (default task-1) Forwarding to error page from request [/processinglogs] due to exception [null]: java.lang.NullPointerException
at deployment.datalis_admin.war//org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:147)
at deployment.datalis_admin.war//org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:83)
at deployment.datalis_admin.war//org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
at deployment.datalis_admin.war//org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1415)
at deployment.datalis_admin.war//org.hibernate.internal.SessionImpl.list(SessionImpl.java:1501)
at deployment.datalis_admin.war//org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at deployment.datalis_admin.war//org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
at deployment.datalis_admin.war//org.hibernate.query.Query.getResultList(Query.java:135)
at deployment.datalis_admin.war//org.datalis.admin.backend.repo.ProcessingLogsRepositoryImpl.findAll(ProcessingLogsRepositoryImpl.java:111)
at deployment.datalis_admin.war//org.datalis.admin.backend.repo.ProcessingLogsRepositoryImpl$$FastClassBySpringCGLIB$$5da64ca3.invoke(<generated>)
at deployment.datalis_admin.war//org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
我在这一行得到NPE:
@Override
public List<ProcessingLogs> findAll(Specification<ProcessingLogs> spec) {
String hql = "select e from " + ProcessingLogs.class.getName() + " e";
TypedQuery<ProcessingLogs> query = entityManager.createQuery(hql, ProcessingLogs.class);
List<ProcessingLogs> processinglogs = query.getResultList();
return processinglogs;
}
我在Ubuntu服务器上使用最新的MariDB,而没有任何其他调整配置。您知道我需要增加一些限制来解决此问题吗?
答案 0 :(得分:0)
我使用此配置解决了问题:
@Configuration
@EnableTransactionManagement
public class ContextDatasource {
@Bean
public EntityManager entityManager(EntityManagerFactory emf) {
return emf.createEntityManager();
}
@Bean
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
}