使用 JPA 的概念,如何使用另一个表中的数据更新表?

Posted

技术标签:

【中文标题】使用 JPA 的概念,如何使用另一个表中的数据更新表?【英文标题】:Using the concept of JPA, how to update table using data from another table? 【发布时间】:2021-09-19 22:05:52 【问题描述】:

FmoReorgGeo.java

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="fmo_reorg_geos")
public class FmoReorgGeo 
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID")
    private Integer ID;
    
    @Column(name="F_AOI", nullable = false)
    private String fAoi;
    
    @Column(name="F_AG", nullable = false)
    private String fAg;
    
    @Column(name="F_RA", nullable = false)
    private String fRa;
    
    @Column(name="T_AOI", nullable = false)
    private String tAoi;
    
    @Column(name="T_AG", nullable = false)
    private String tAg;
    
    @Column(name="T_RA", nullable = false)
    private String tRa;
    
    @Column(name="CLLI", nullable = false)
    private String clli;
    
    @Column(name="TURF", nullable = false)
    private String turf;

    @Column(name="REGION", nullable = false)
    private String region;
    
    @Column(name="F_AOI_RID")
    private String fAoiRid;
    
    @Column(name="F_AG_RID")
    private String fAgRid;
    
    @Column(name="F_RA_RID")
    private String fRaRid;
    
    @Column(name="T_AOI_RID")
    private String tAoiRid;
    
    @Column(name="T_AG_RID")
    private String tAgRid;
    
    @Column(name="T_RA_RID")
    private String tRaRid;
 
    @Column(name="REORG_DT")
    private Date reorgDt;

    public Integer getID() 
        return ID;
    

    public void setID(Integer iD) 
        ID = iD;
    

    public String getfAoi() 
        return fAoi;
    

    public void setfAoi(String fAoi) 
        this.fAoi = fAoi;
    

    public String getfAg() 
        return fAg;
    

    public void setfAg(String fAg) 
        this.fAg = fAg;
    

    public String getfRa() 
        return fRa;
    

    public void setfRa(String fRa) 
        this.fRa = fRa;
    

    public String gettAoi() 
        return tAoi;
    

    public void settAoi(String tAoi) 
        this.tAoi = tAoi;
    

    public String gettAg() 
        return tAg;
    

    public void settAg(String tAg) 
        this.tAg = tAg;
    

    public String gettRa() 
        return tRa;
    

    public void settRa(String tRa) 
        this.tRa = tRa;
    

    public String getClli() 
        return clli;
    

    public void setClli(String clli) 
        this.clli = clli;
    

    public String getTurf() 
        return turf;
    

    public void setTurf(String turf) 
        this.turf = turf;
    

    public String getRegion() 
        return region;
    

    public void setRegion(String region) 
        this.region = region;
    

    public String getfAoiRid() 
        return fAoiRid;
    

    public void setfAoiRid(String fAoiRid) 
        this.fAoiRid = fAoiRid;
    

    public String getfAgRid() 
        return fAgRid;
    

    public void setfAgRid(String fAgRid) 
        this.fAgRid = fAgRid;
    

    public String getfRaRid() 
        return fRaRid;
    

    public void setfRaRid(String fRaRid) 
        this.fRaRid = fRaRid;
    

    public String gettAoiRid() 
        return tAoiRid;
    

    public void settAoiRid(String tAoiRid) 
        this.tAoiRid = tAoiRid;
    

    public String gettAgRid() 
        return tAgRid;
    

    public void settAgRid(String tAgRid) 
        this.tAgRid = tAgRid;
    

    public String gettRaRid() 
        return tRaRid;
    

    public void settRaRid(String tRaRid) 
        this.tRaRid = tRaRid;
    

    public Date getReorgDt() 
        return reorgDt;
    

    public void setReorgDt(Date reorgDt) 
        this.reorgDt = reorgDt;
    

    @Override
    public String toString() 
        return "FmoReorgGeo [ID=" + ID + ", fAoi=" + fAoi + ", fAg=" + fAg + ", fRa=" + fRa + ", tAoi=" + tAoi
                + ", tAg=" + tAg + ", tRa=" + tRa + ", clli=" + clli + ", turf=" + turf + ", region=" + region
                + ", fAoiRid=" + fAoiRid + ", fAgRid=" + fAgRid + ", fRaRid=" + fRaRid + ", tAoiRid=" + tAoiRid
                + ", tAgRid=" + tAgRid + ", tRaRid=" + tRaRid + ", reorgDt=" + reorgDt + "]";
    
    
    


FMOReorgGeoServiceImpl.java


import java.sql.Date;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import com.att.dmp.entity.FmoReorgGeo;
import com.att.dmp.repository.FMOReorgGeoRepository;
import com.att.dmp.service.FMOReorgGeoService;

@Service
@Qualifier("fMOReorgGeoServiceImpl")
public class FMOReorgGeoServiceImpl implements FMOReorgGeoService 

    private final Logger logger = LogManager.getLogger(FMOReorgGeoServiceImpl.class);

    @Autowired
    FMOReorgGeoRepository fMOReorgGeoRepository;

    @Override
    public List<FmoReorgGeo> updateResourceHierachyRID(String region, Date reorgDt) 
        List<Map<String, Object>> reorgRecords = Collections.emptyList();
        reorgRecords = fMOReorgGeoRepository.findreorgRecords(region, reorgDt);
        reorgRecords.forEach(map -> map.forEach((k, v) -> 
            logger.info(k + ":" + v);
        ));
        List<Map<String, Object>> updatedResourceHierachyRids = Collections.emptyList();
        for (Map<String, Object> reorgRecord : reorgRecords) 
            String f_aoi_rid = (String) reorgRecord.get("FAOIRID");
            String f_ag_rid = (String) reorgRecord.get("FAGRID");
            String f_ra_rid = (String) reorgRecord.get("FRARID");
            String t_aoi_rid = (String) reorgRecord.get("TAOIRID");
            String t_ag_rid = (String) reorgRecord.get("TAGRID");
            String t_ra_rid = (String) reorgRecord.get("TRARID");
            String clli = (String) reorgRecord.get("CLLI");
            String turf = (String) reorgRecord.get("TURF");
            updatedResourceHierachyRids = fMOReorgGeoRepository.updateRid(f_aoi_rid, f_ag_rid, f_ra_rid,t_aoi_rid, t_ag_rid,
                    t_ra_rid, clli, turf);

        
        
        List<FmoReorgGeo> updatedFMOReorgGeos = new ArrayList<FmoReorgGeo>();

        if (!updatedResourceHierachyRids.isEmpty()) 
            
              for (Map<String, Object> updatedResourceHierachyRid :
              updatedResourceHierachyRids)  FmoReorgGeo rh = new FmoReorgGeo();
              rh.setfAoiRid((String) updatedResourceHierachyRid.get("F_AOI_RID"));
              rh.setfAgRid((String) updatedResourceHierachyRid.get("F_AG_RID"));
              rh.setfRaRid((String) updatedResourceHierachyRid.get("F_RA_RID"));
              rh.settAoiRid((String) updatedResourceHierachyRid.get("T_AOI_RID"));
              rh.settAgRid((String) updatedResourceHierachyRid.get("T_AG_RID"));
              rh.settRaRid((String) updatedResourceHierachyRid.get("T_RA_RID"));
              rh.setClli((String) updatedResourceHierachyRid.get("CLLI"));
              rh.setTurf((String) updatedResourceHierachyRid.get("TURF"));
              updatedFMOReorgGeos.add(rh); 
        
        logger.info("Created updatedFMOReorgGeos are: ", updatedFMOReorgGeos);
        return updatedFMOReorgGeos;
    



FMOReorgGeoRepository.java

import java.sql.Date;
import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


import com.att.dmp.consts.AppConstant;
import com.att.dmp.entity.FmoReorgGeo;

@Repository
public interface FMOReorgGeoRepository extends JpaRepository<FmoReorgGeo, Integer> 
    
    @Query(value = AppConstant.SELECT_REORG_RECORDS_QUERY,nativeQuery = true)
    List<Map<String, Object>> findreorgRecords(@Param("region") String region,@Param("reorgDt") Date reorgDt);
    
    @Modifying
    @Query(value = AppConstant.UPDATE_RESOURCE_HIERACHY_RID,nativeQuery = true)
    List<Map<String, Object>> updateRid(@Param("F_AOI_RID") String f_aoi_rid,@Param("F_AG_RID") String f_ag_rid,@Param("F_RA_RID") String f_ra_rid,@Param("T_AOI_RID") String t_aoi_rid,@Param("T_AG_RID") String t_ag_rid,@Param("T_RA_RID") String t_ra_rid,@Param("CLLI") String clli,@Param("TURF") String turf);

错误日志

Hibernate: update FMO_REORG_GEOS set F_AOI_RID = ?, F_AG_RID = ?, F_RA_RID = ?, T_AOI_RID= ?,T_AG_RID = ?,T_RA_RID = ? where CLLI = ? and TURF = ?
"logType":"DEBUG","logLevel":"ERROR","logTimestamp":"2021-09-19T16:43:56.942-05:00","logger":"com.att.dmp.RestExceptionMapper","label":"Caught Exception in Jersey Service.....","runtime":"instance":"unknown","clusterName":"unknown","namespace":"unknown","image":"unknown","platformIdentifier":"AJSC7_JERSEY","application":"deploymentUnitName":"com.att.dmp.ReorgResourceCreatorMs","motsApplicationAcronym":"MOTS_ID"
"logType":"EXCEPTION","logLevel":"ERROR","logTimestamp":"2021-09-19T16:43:56.945-05:00","logger":"Exception","label":"Exception","runtime":"instance":"unknown","clusterName":"unknown","namespace":"unknown","image":"unknown","platformIdentifier":"AJSC7_JERSEY","application":"deploymentUnitName":"com.att.dmp.ReorgResourceCreatorMs","motsApplicationAcronym":"MOTS_ID","exception":"exceptionDetails":"Could not extract result set metadata; nested exception is org.hibernate.HibernateException: Could not extract result set metadata","stackTrace":"org.springframework.orm.jpa.JpaSystemException: Could not extract result set metadata; nested exception is org.hibernate.HibernateException: Could not extract result set metadata\r\n\tat org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:353)\r\n\tat org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)\r\n\tat org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)\r\n\tat org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)\r\n\tat org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)\r\n\tat org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)\r\n\tat com.sun.proxy.$Proxy246.updateRid(Unknown Source)\r\n\tat com.att.dmp.service.impl.FMOReorgGeoServiceImpl.updateResourceHierachyRID(FMOReorgGeoServiceImpl.java:45)\r\n\tat com.att.dmp.controller.RestControllerImpl.updateRID(RestControllerImpl.java:217)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)\r\n\tat org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)\r\n\tat org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)\r\n\tat org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:159)\r\n\tat org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)\r\n\tat org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)\r\n\tat org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)\r\n\tat org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:292)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:274)\r\n\tat org.glassfish.jersey.internal.Errors.process(Errors.java:244)\r\n\tat org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)\r\n\tat org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)\r\n\tat org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)\r\n\tat org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:392)\r\n\tat org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:365)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:318)\r\n\tat org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\r\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)\r\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\r\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)\r\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\nCaused by: org.hibernate.HibernateException: Could not extract result set metadata\r\n\tat org.hibernate.loader.custom.JdbcResultMetadata.<init>(JdbcResultMetadata.java:36)\r\n\tat org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:488)\r\n\tat org.hibernate.loader.Loader.processResultSet(Loader.java:2338)\r\n\tat org.hibernate.loader.Loader.getResultSet(Loader.java:2294)\r\n\tat org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050)\r\n\tat org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012)\r\n\tat org.hibernate.loader.Loader.doQuery(Loader.java:953)\r\n\tat org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)\r\n\tat org.hibernate.loader.Loader.doList(Loader.java:2815)\r\n\tat org.hibernate.loader.Loader.doList(Loader.java:2797)\r\n\tat org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2629)\r\n\tat org.hibernate.loader.Loader.list(Loader.java:2624)\r\n\tat org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)\r\n\tat org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2123)\r\n\tat org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1134)\r\n\tat org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:173)\r\n\tat org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1526)\r\n\tat org.hibernate.query.Query.getResultList(Query.java:165)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:409)\r\n\tat com.sun.proxy.$Proxy250.getResultList(Unknown Source)\r\n\tat org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:126)\r\n\tat org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88)\r\n\tat org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154)\r\n\tat org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142)\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:618)\r\n\tat org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)\r\n\tat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)\r\n\t... 72 more\r\nCaused by: java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement\n\r\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)\r\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:388)\r\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:381)\r\n\tat oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:564)\r\n\tat oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)\r\n\tat oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)\r\n\tat oracle.jdbc.driver.T4C8Odscrarr.doODNY(T4C8Odscrarr.java:98)\r\n\tat oracle.jdbc.driver.T4CPreparedStatement.doDescribe(T4CPreparedStatement.java:792)\r\n\tat oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:3928)\r\n\tat oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:56)\r\n\tat oracle.jdbc.driver.OracleResultSetImpl.getMetaData(OracleResultSetImpl.java:170)\r\n\tat org.apache.commons.dbcp2.DelegatingResultSet.getMetaData(DelegatingResultSet.java:347)\r\n\tat org.apache.commons.dbcp2.DelegatingResultSet.getMetaData(DelegatingResultSet.java:347)\r\n\tat org.hibernate.loader.custom.JdbcResultMetadata.<init>(JdbcResultMetadata.java:33)\r\n\t... 108 more\r\n"

*我正在尝试从 reorgViewX 获取数据,然后更新 FmoReorgGeo 表。我能够正确获取数据,但是在运行更新查询时出现错误。错误说: 无法提取结果集元数据;嵌套异常是 org.hibernate.HibernateException:无法提取结果集元数据。我正在使用 > 的概念,因为休眠不允许仅获取某些列,并且在获取时需要所有列。 *

【问题讨论】:

请不要在所有代码中复制粘贴,而仅在关键部分中复制粘贴:请编辑您的问题以将代码中的字段数量减少到表明问题的绝对最小值,如查看else 可以删除:见how to ask questions 和MCVE。 【参考方案1】:

这样的更新查询不会返回结果集。移除返回类型:

@Modifying
@Query(value = AppConstant.UPDATE_RESOURCE_HIERACHY_RID,nativeQuery = true)
void updateRid(@Param("F_AOI_RID") String f_aoi_rid,@Param("F_AG_RID") String f_ag_rid,@Param("F_RA_RID") String f_ra_rid,@Param("T_AOI_RID") String t_aoi_rid,@Param("T_AG_RID") String t_ag_rid,@Param("T_RA_RID") String t_ra_rid,@Param("CLLI") String clli,@Param("TURF") String turf);

【讨论】:

以上是关于使用 JPA 的概念,如何使用另一个表中的数据更新表?的主要内容,如果未能解决你的问题,请参考以下文章

SQL UPDATE - 如何使用另一个表更新一个表中的列?

Oracle SQL:使用另一个表中的数据更新表

如何通过将一个表中的 id 与另一个表匹配来选择和更新一个表中的记录?

如何使用MySQL一个表中的字段更新另一个表中字段

sql [sql]如何从另一个表中的相应数据更新一个表中的数据

使用另一个表中的数据更新行