当前位置: 首页 > 知识库问答 >
问题:

psqlException:错误:操作符不存在:bigint=bytea

荆鸿畅
2023-03-14

使用Spring和Hibernate,我使用@query注释创建了一个查询,如下所示:

@Repository
public interface SampleDAO extends CrudRepository<Sample, Long> {

    @Query("select count(s) from Sample s where dna_study_id = ?1")
    Integer getSamplesXAnalysis(Long id);

}

这是示例类:

@Entity
@Table(name="sample")
public class Sample implements Serializable {

    @Id
    @GeneratedValue
    @Column(name="sample_id")
    private Long sample_id;
    @Column(name="id")
    private String id;
    @Column(name="description")
    private String description;
    @ManyToOne
    @JoinColumn(name="dna_study_id")
    private DNA_Study study;

    public Sample() {  }

    public Sample(String id, String description, DNA_Study study) {
        this.id = id;
        this.description = description;
        this.study = study;
    }

    public Long getSample_id() {
        return sample_id;
    }

    public void setSample_id(Long sample_id) {
        this.sample_id = sample_id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DNA_Study getDna_study_id() {
        return study;
    }

    public void setDna_study_id(DNA_Study study) {
        this.study = study;
    }
}

当我从客户端调用:“url/getSamplesXAnalysis”时,它将执行:

@CrossOrigin
@RequestMapping("/getsamplesxanalysis")
public Integer getSamplesXAnalysis() {

    context = new ClassPathXmlApplicationContext("applicationContext.xml");
    SampleDAO dao = context.getBean(SampleDAO.class);
    return dao.getSamplesXAnalysis((long) 1);
}

并且没有给出错误或异常,我收到结果。但是,如果我试图在URL上使用参数,例如:“URL/getSamplesXAnalysis/2”,它将执行:

@CrossOrigin
    @RequestMapping("/getsamplesxanalysis/{id}")
    public Integer getSamplesXAnalysis(@PathParam("id") Long id) {

        context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SampleDAO dao = context.getBean(SampleDAO.class);
        return dao.getSamplesXAnalysis(id);
    }
Hibernate: 
    select
        count(sample0_.sample_id) as col_0_0_ 
    from
        sample sample0_ 
    where
        dna_study_id=?
2016-02-24 12:33:06.917  INFO 1956 --- [nio-8080-exec-3] o.s.c.s.ClassPathXmlApplicationContext   : Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@277d9: startup date [Wed Feb 24 12:33:06 CET 2016]; root of context hierarchy
2016-02-24 12:33:06.918  INFO 1956 --- [nio-8080-exec-3] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [applicationContext.xml]
2016-02-24 12:33:07.029  INFO 1956 --- [nio-8080-exec-3] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-02-24 12:33:07.032  INFO 1956 --- [nio-8080-exec-3] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: org.postgresql.Driver
2016-02-24 12:33:07.035  INFO 1956 --- [nio-8080-exec-3] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'jpaData'
2016-02-24 12:33:07.035  INFO 1956 --- [nio-8080-exec-3] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: jpaData
    ...]
2016-02-24 12:33:07.270  INFO 1956 --- [nio-8080-exec-3] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2016-02-24 12:33:07.273  INFO 1956 --- [nio-8080-exec-3] o.h.e.jdbc.internal.LobCreatorBuilder    : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2016-02-24 12:33:07.296  INFO 1956 --- [nio-8080-exec-3] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2016-02-24 12:33:07.346  INFO 1956 --- [nio-8080-exec-3] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2016-02-24 12:33:07.347  INFO 1956 --- [nio-8080-exec-3] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000102: Fetching database metadata
2016-02-24 12:33:07.374  INFO 1956 --- [nio-8080-exec-3] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000396: Updating schema
2016-02-24 12:33:07.414  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: public.datasource
2016-02-24 12:33:07.414  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [link, name, data_source_id]
2016-02-24 12:33:07.414  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: []
2016-02-24 12:33:07.415  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [datasource_pkey]
2016-02-24 12:33:07.446  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: public.dna_study
2016-02-24 12:33:07.446  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [date, dna_study_id, name, description]
2016-02-24 12:33:07.446  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: []
2016-02-24 12:33:07.446  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [dna_study_id]
2016-02-24 12:33:07.478  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: public.sample
2016-02-24 12:33:07.478  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [dna_study_id, sample_id, description, id]
2016-02-24 12:33:07.478  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: [fk_hhiykwraml4x7uwou4l1o56df]
2016-02-24 12:33:07.478  INFO 1956 --- [nio-8080-exec-3] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [sample_pkey]
2016-02-24 12:33:07.478  INFO 1956 --- [nio-8080-exec-3] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000232: Schema update complete
2016-02-24 12:33:07.482  WARN 1956 --- [nio-8080-exec-3] o.h.j.i.EntityManagerFactoryRegistry     : HHH000436: Entity manager factory name (jpaData) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
2016-02-24 12:33:07.537 ERROR 1956 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
    java.lang.NullPointerException: null
        at com.gembiosoft.gemdomus.rest.SampleController.getSamplesXAnalysis(SampleController.java:44) ~[classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_74]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_74]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.30.jar:8.0.30]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_74]

编辑2从长变长的参数方法:

public Integer getSamplesXAnalysis(@PathParam("id") long id) { ... }

返回IlelGalStateException:

java.lang.IllegalStateException: Optional long parameter 'id' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
    at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.handleNullValue(AbstractNamedValueMethodArgumentResolver.java:205) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:98) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_74]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_74]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_74]

共有1个答案

上官德寿
2023-03-14

这里作为一个答案:

NPE发生在SampleController中:

SampleController.getSamplesXAnalysis(SampleController.java:44) 

哪条线是44号?我会说这是

return dao.getSamplesXAnalysis(id.longValue()); 

所以有两个东西可以是null:dao或ID。我想是我的身份,不是刀。我相信你用一个id来调用控制器,但这个id并不能进入你的方法。

使用@PathVariable而不是@PathParam,一切都会好起来。

编辑

之所以为null是因为@PathParam在URL上定义查询参数时工作,例如:URL/getSamplesXanalysy/?id=2。因为我使用的是url/getSamplesXAnalysis/2,所以@PathVariable是必需的。

  • @PathVariable是从URI中获得一些占位符(Springs称之为URI模板)
  • @requestparam要获取参数

来源:@requestparam vs@pathvariable

 类似资料:
  • 这是我的存储库中的代码 我的控制器里有这个 我还注意到,如果我从(:subjects)中的s.subject_id的查询中删除这一部分,或者说我像(2,3,4)中的s.subject_id那样硬编码subjects值,代码将成功运行。但是,如果值来自请求,我就会得到错误。下面是请求的样子 本地主机:8080/评估/F3DF0BC2-7B4C-49B9-86C9-6E6B01628623/3/4/1

  • org.PostgreSQL.util.psqlException:错误:操作符不存在:integer=bytea 将null绑定到准备好的语句时出现Postgres bytea错误 Hibernate本机查询可选参数抛出'operator不存在:bigint=bytea' ...还有更多。 下面是其中一个控制器: 这是我从邮递员那里寄来的请求: 下面是我的本机查询存储库: 请帮助我的想法和可能的

  • 问题内容: 我正在尝试在PostgreSQL 8.4.2 DB上运行hibernate模式。每当我尝试运行一个简单的Java代码,例如: 我收到以下错误: 由于我将选项hibernate.show_sql选项设置为true,因此可以看到hibernate尝试运行以下SQL命令: 实际上,它至少应运行以下命令: 有谁知道我需要进行哪些更改才能使Hibernate为PostgreSQL生成正确的SQL

  • 我使用PostgreSQL 10、Spring Boot 2.2.7.Release和pgAdmin 4来实现Postgres GUI 我有以下实体类: 我已经使用GUI PGADMIN4为ID列“TB03_TABLE_A_SEQ”创建了表“TB03_TABLE_A”和序列 我哪里出问题了?请救命! 提前感谢!

  • 我在heroku上创建了java(Spring)应用程序,并将postgreql连接到它。当我在应用程序上发出请求时,日志显示 WARN 4-[io-14883-exec-3]o . h . engine . JDBC . SPI . sqlexception helper:SQL错误:0,SQLState:42p 01 app[web.1]:2016-12-11 12:13:09.942错误4-

  • 我正在开发一个广泛部署的java web服务。它连接到postgresql数据库。在这个数据库中,我有一个名为xx_activity的表。其中有一个名为“id”的列,它也是主键。下面是用于创建表的查询: 为了连接到这个表,我使用以下java代码: 但是,当我调用包含此代码的方法时,我得到一个错误: psqlException:错误:列“id”不存在 这怎么能修好呢?