java.sql.SQLException:GET请求中getLong()的值无效

时间:2018-09-05 19:32:52

标签: java rest spring-boot web

下午好,

我遇到了一段时间的问题,我已经做了很多尝试以找到解决方案,但是我没有。

首先,我的问题来自java.sql.SQLException: Invalid value for getLong()。但是,就像我说的那样,我一直无法解决它,因为每一个询问者都说要尝试在数据库中像VARCHAR类型变量那样获取类型为Long的变量。但是,看看我所做的模型类的范围,所有变量的类型都是正确的。

我正在使用Spring Boot Restfull应用程序,因此,我对模型,存储库和资源类进行了编码。

我使用Postman进行测试,当我向特定资源类发送GET请求时,尽管我使用相同的逻辑来编码其他资源,但仍收到该异常。

我的尝试之一是将插入数据库的值从字母数字字符串(例如“ Pessoa 1 Reu”)更改为数字字符串(例如“ 1”),并且GET请求成功

尽管GET的请求在每个请求上都成功完成,但是关系类会发生此问题,该关系类将一个关系类和一个实体类相关联。

GET资源类方法使用了我做过的存储库类的实例,就像其他实例一样,它调用了findAll()方法。

如果有人可以帮助我,我会很感激……

---编辑---
我在本文的末尾添加了CREATE TABLE的代码。 在GET表中,使cpf_cnpj_pessoa请求的变量为pessoa_fj,在数据库中键入为VARCHAR,在应用程序中键入为String。当该变量存储字母数字字符串时,GET请求将失败...

关系类:

//imports was suppressed
@Entity
@Table(name = "reus_advogados")
@IdClass(Reu_AdvogadoIdClass.class)
public class Reu_Advogado {
    @Id
    @NotNull
    @Column(name="cpf_cnpj_pessoa_reu")
    protected String cpf_cnpj_pessoa_reu;
    @Id
    @NotNull
    @Column(name="num_processo_reu")
    protected Long num_processo_reu;
    @Id
    @NotNull
    @Column(name="num_adv_oab")
    protected String num_adv_oab;

    @JoinColumns(value = { 
            @JoinColumn(name= "num_processo_reu", insertable = false,updatable=false), 
            @JoinColumn(name= "cpf_cnpj_pessoa_reu",insertable = false,updatable=false) })
    @ManyToOne(cascade=CascadeType.ALL)
    private Reu reu;

    @JoinColumn(name="num_adv_oab",insertable=false, updatable=false)
    @ManyToOne(cascade=CascadeType.ALL)
    private Advogado advogado;

        // Getters, Setters, Hash and Equals was suppressed 
}

例外:

2018-09-05 15:24:26.446 ERROR 6800 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Invalid value for getLong() - 'Pessoa 1 Reu'
2018-09-05 15:24:26.451 ERROR 6800 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query] with root cause

    java.sql.SQLException: Invalid value for getLong() - 'Pessoa 1 Reu'
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2724) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2653) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2738) ~[mysql-connector-java-5.1.45.jar:5.1.45]
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:300) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.ComponentType.hydrate(ComponentType.java:662) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:333) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:169) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2790) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1729) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1655) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.getRow(Loader.java:1544) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.processResultSet(Loader.java:972) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:930) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2617) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2600) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2424) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:50) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:329) ~[spring-data-jpa-1.11.10.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:74) ~[spring-data-jpa-1.11.10.RELEASE.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:513) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:498) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:475) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.10.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at com.sun.proxy.$Proxy172.findAll(Unknown Source) ~[na:na]
    at com.example.DiarioDaJustica.api.resource.Reu_AdvogadoResource.listar(Reu_AdvogadoResource.java:40) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_171]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.27.jar:8.5.27]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]

创建表代码:

CREATE TABLE processos(
    num_processo BIGINT(16) NOT NULL,
    nome_classe VARCHAR(100),
    num_processo_origem BIGINT(16) DEFAULT 0,
    escrivania VARCHAR(200),
    numero_acordao VARCHAR(15),
    procedencia VARCHAR(200),
    grupo VARCHAR(5),
    relator VARCHAR(200)
);
CREATE TABLE pessoas_fj(
    cpf_cnpj_pessoa VARCHAR(200) NOT NULL,
    nome_pessoa VARCHAR(200)
);
CREATE TABLE advogados(
    num_adv_oab VARCHAR(20) NOT NULL,
    cpf_adv VARCHAR(200) NOT NULL,
    uf_estado_oab VARCHAR(2),
    sigla_pais_oab VARCHAR(4),
    nome_setor VARCHAR(20),
    is_procurador BIT(1) DEFAULT 0
);

CREATE TABLE reus(
    cpf_cnpj_pessoa_reu VARCHAR(200) NOT NULL,
    num_processo_reu BIGINT(16) NOT NULL
);
CREATE TABLE reus_advogados(
    cpf_cnpj_pessoa_reu VARCHAR(200) NOT NULL,
    num_processo_reu BIGINT(16) NOT NULL,
    num_adv_oab VARCHAR(20) NOT NULL
);
ALTER TABLE processos ADD CONSTRAINT processos_pk PRIMARY KEY ( num_processo );
ALTER TABLE pessoas_fj ADD CONSTRAINT pessoas_fj_pk PRIMARY KEY ( cpf_cnpj_pessoa );
ALTER TABLE advogados ADD CONSTRAINT advogados_pk PRIMARY KEY ( num_adv_oab );
ALTER TABLE reus ADD CONSTRAINT reus_pk PRIMARY KEY ( cpf_cnpj_pessoa_reu, num_processo_reu );
ALTER TABLE reus_advogados ADD CONSTRAINT reus_advogados_pk PRIMARY KEY ( num_adv_oab, cpf_cnpj_pessoa_reu, num_processo_reu );

ALTER TABLE reus ADD CONSTRAINT reus_fk_pessoa_fj FOREIGN KEY ( cpf_cnpj_pessoa_reu ) REFERENCES pessoas_fj ( cpf_cnpj_pessoa );
ALTER TABLE reus ADD CONSTRAINT reus_fk_processo FOREIGN KEY ( num_processo_reu ) REFERENCES processos ( num_processo );

ALTER TABLE reus_advogados ADD CONSTRAINT reus_advogados_fk_reus FOREIGN KEY ( num_processo_reu, cpf_cnpj_pessoa_reu ) 
    REFERENCES reus ( num_processo_reu, cpf_cnpj_pessoa_reu );
ALTER TABLE reus_advogados ADD CONSTRAINT reus_advogados_fk_adv FOREIGN KEY ( num_adv_oab ) 
    REFERENCES advogados ( num_adv_oab );

2 个答案:

答案 0 :(得分:0)

@Column(name="num_processo_reu")
protected Long num_processo_reu;
  

我的尝试之一是将插入数据库的值从字母数字字符串(如“ Pessoa 1 Reu”)更改为数字字符串(如“ 1”),并且GET请求成功。

查看数据库模式。此列num_processo_reu被定义为VARCHAR,而不是数字。当该值是数字的字符串表示形式时,数据库将为您进行转换。当您尝试读取诸如Pessoa 1 Reu之类的非数字值时,您会遇到异常,因为数据库无法将该值转换为数字。

要么更改数据库模式(即CREATE TABLE),以使该列为数字且不能包含字符串值,要么将代码更改为

@Column(name="num_processo_reu")
protected String num_processo_reu;

并根据项目要求编写逻辑以处理非数字值。

答案 1 :(得分:0)

我解决了这个问题!
该问题源自以下代码:

@JoinColumns(value = { 
            @JoinColumn(name= "num_processo_reu", insertable = false,updatable=false), 
            @JoinColumn(name= "cpf_cnpj_pessoa_reu",insertable = false,updatable=false) })
    @ManyToOne(cascade=CascadeType.ALL)
    private Reu reu;

@JoinColumns批注中,声明Reu表键的顺序错误。当我改变时,问题解决了。解决方案如下:

 @JoinColumns(value = { 
            @JoinColumn(name= "cpf_cnpj_pessoa_reu",insertable = false,updatable=false),
            @JoinColumn(name= "num_processo_reu", insertable = false,updatable=false)})
    @ManyToOne(cascade=CascadeType.ALL)
    private Reu reu;

我认为在数据库中显式的顺序必须与您在数据库上调用desc reus时显示的顺序相同,该顺序cpf_cnpj_pessoa_reu首先出现。但是我不确定...

我决定将解决方案放在这里,因为其他人可能会遇到与我相同的问题。

谢谢!