空指针异常Spring boot jpa

时间:2018-12-26 22:35:02

标签: database spring-boot jpa

我有下一段代码:

主班

@SpringBootApplication
  @EnableScheduling
  public class GeolocalizacionApplication  extends SpringBootServletInitializer {

    public static void main(String[] args) {
      SpringApplication.run(GeolocalizacionApplication.class, args);
    }

  }

@Transactional
@Repository
public class UsigRequestPersistanceDaoImpl implements UsigRequestPersistanceDao {

 @PersistenceContext
 private EntityManager em;

 public List<UsigRequestPersistance> getRequest() {

 Query query =  em.createQuery("select v.requestId from UsigRequestSeq v").getFirstResult();


 }

}

模型类

@Entity
@Table(name= "seq_usig_request", schema = "xxxx")
public class UsigRequestSeq {

  @Id
  @Column(name = "request_id", nullable = false)
  private Integer requestId;

   public Integer getRequestId() {
      return requestId;
   }

   public void setRequestId(Integer requestId) {
      this.requestId = requestId;
   }

}

配置

@Configuration
@EnableTransactionManagement
public class DatabaseConfiguration {

        @Bean
        public LocalSessionFactoryBean sessionFactory(){
            LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
            sessionFactoryBean.setDataSource(dataSource());
            sessionFactoryBean.setPackagesToScan("xxxx");
            sessionFactoryBean.setHibernateProperties(hibernateProperties());
            return sessionFactoryBean;
        }


        @Bean
        public DataSource dataSource(){
            DriverManagerDataSource dataSource = new DriverManagerDataSource();
            dataSource.setDriverClassName("com.teradata.jdbc.TeraDriver");

            dataSource.setUrl("jdbc:teradata://teradata.xxxx/TMODE=ANSI,CHARSET=UTF8");


            dataSource.setUsername("xxxx");
            dataSource.setPassword("xxxx");

            return dataSource;
        }

        @Bean(name = "properties")
        public Properties hibernateProperties(){
            Properties properties = new Properties();
            properties.put("hibernate.dialect", "org.hibernate.dialect.TeradataDialect");
            //properties.put("hibernate.show_sql", "true");
            return properties;
        }
        @Bean
        @Autowired
        public HibernateTransactionManager transactionManager(){
                HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager();
                hibernateTransactionManager.setSessionFactory(sessionFactory().getObject());    
            return hibernateTransactionManager;
        }



}

Application.properties

spring.jpa.database-platform=org.hibernate.dialect.TeradataDialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

那我确实有一个控制器,但是我认为没有必要将它放在这里。在我的控制器中,有一个调用getRequest()方法的方法。

这里有一些堆栈

java.lang.NullPointerException: null
    at com.xxxx.Geolocalizacion.dao.UsigRequestPersistanceDaoImpl.getRequest(UsigRequestPersistanceDaoImpl.java:82) ~[classes/:na]
    at com.xxxx.Geolocalizacion.controller.GeoController.ejecutar(GeoController.java:51) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_181]

我相信我在createQuery本机方法方面遇到问题,我对该程序进行了调试,并且在哪里坏了,但我找不到原因。我想念什么吗?

0 个答案:

没有答案