尝试从WebLogic 12.2.1.3返回REF_CURSOR时出现Spring Boot错误

时间:2018-07-02 12:09:09

标签: java hibernate spring-boot stored-procedures weblogic

当我尝试在WebLogic 12.2.1.3。上测试应用程序时,会有一些奇怪的事情。

问题是:

当我尝试从Spring Boot应用程序调用存储过程时,发生此错误:

“ exception”:“ javax.persistence.PersistenceException”,     “ message”:“ org.hibernate.exception.GenericJDBCException:错误注册REF_CURSOR参数[pCur]”。

我正在通过邮递员测试我的应用。

我试图使用app.properties文件中的 spring.datasource.jndi-name = jdbc / asebabi 连接到WebLogic上的数据源。

仅当我输入所有spring连接参数(例如spring.datasource.url,spring.datasource.username,spring.datasource.pass ...)时,此方法才适用于12.2.1.3。 如果我不想使用* spring.datasource.jndi名称,则在同一文件中。

同样奇怪的是,我不需要在pom.xml中使用ojdbc依赖关系来使应用程序正常工作。

但是我想使用jndi。

JNDI是可以识别的,因为使用它的所有其他方法都可以正常工作。REF_CURSOR是唯一的问题。

我的Oracle数据库版本为10g。

但是在WebLogic 12.1.3上一切正常。

下面是我的代码:

package springboot.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Racun {

        private int org_jed;
        private String kontoId; 
        @Id
        private String partija;
        private int proizvod ;
        private int vlasnik ;
        private int errCode ;
        private String errMsg ;

        public Racun() {};

        public Racun(int org_jed, String kontoId, String partija, int proizvod, int vlasnik, int errCode,
                String errMsg) {
            super();
            this.org_jed = org_jed;
            this.kontoId = kontoId;
            this.partija = partija;
            this.proizvod = proizvod;
            this.vlasnik = vlasnik;
            this.errCode = errCode;
            this.errMsg = errMsg;
        }

        public int getOrg_jed() {
            return org_jed;
        }

        public void setOrg_jed(int org_jed) {
            this.org_jed = org_jed;
        }

        public String getKontoId() {
            return kontoId;
        }

        public void setKontoId(String kontoId) {
            this.kontoId = kontoId;
        }

        public String getPartija() {
            return partija;
        }

        public void setPartija(String partija) {
            this.partija = partija;
        }

        public int getProizvod() {
            return proizvod;
        }

        public void setProizvod(int proizvod) {
            this.proizvod = proizvod;
        }

        public int getVlasnik() {
            return vlasnik;
        }

        public void setVlasnik(int vlasnik) {
            this.vlasnik = vlasnik;
        }

        public int getErrCode() {
            return errCode;
        }

        public void setErrCode(int errCode) {
            this.errCode = errCode;
        }

        public String getErrMsg() {
            return errMsg;
        }

        public void setErrMsg(String errMsg) {
            this.errMsg = errMsg;
        }

        @Override
        public String toString() {
            return "Racun [org_jed=" + org_jed + ", kontoId=" + kontoId + ", partija=" + partija + ", proizvod="
                    + proizvod + ", vlasnik=" + vlasnik + ", errCode=" + errCode + ", errMsg=" + errMsg + "]";
        }

}

    package springboot.repository;
    import org.springframework.data.repository.CrudRepository;
    import springboot.domain.Racun;
    public interface RacunRepository extends CrudRepository<Racun, Long> {

    }


        package springboot.controller;
        import java.util.List;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.context.annotation.ComponentScan;
        import org.springframework.web.bind.annotation.RequestBody;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestMethod;
        import org.springframework.web.bind.annotation.RestController;
        import springboot.service.RacunService;
        import springboot.domain.Racun;
        import springboot.repository.RacunRepository;
        import springboot.request.RacunRequest;

        @ComponentScan({"springboot"})
        @RestController
        @RequestMapping("/procedure")
        public class RacunController {

            @Autowired
            RacunService racunService;


    @RequestMapping(method = RequestMethod.POST, value = "/vratiSveRacune")
                public List<Racun> vratiSveRacune(@RequestBody RacunRequest racunRequest)   {

                    List<Racun> izlaz = racunService.fetch_accounts(racunRequest.getIndSistema(), 
                                                                    racunRequest.getMaticniBroj(), 
                                                                    racunRequest.getSifraValute());


                    return izlaz;
                }

                @RequestMapping(method = RequestMethod.GET, value = "/pozdrav")
                public String vratiPozdrav()   {

                    return "Cao GAcone,maestro!";
                }
        }


    package springboot.service;

    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;
    import javax.persistence.EntityManager;
    import javax.persistence.ParameterMode;
    import javax.persistence.PersistenceContext;
    import javax.persistence.StoredProcedureQuery;

    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.stereotype.Service;

    import springboot.domain.Racun;


    @ComponentScan("springboot")
    @Service
    public class RacunService {

         @PersistenceContext
          private EntityManager em;

         /*
         @Autowired
         private RacunRepository racunRepository;
         */

        public List<Racun> fetch_accounts(String indSistema, String mBr, int sifraValute) {

            StoredProcedureQuery query = em.createStoredProcedureQuery("vukovic_pkg.vratiSveRacune");

            query.registerStoredProcedureParameter("pIndSistema", String.class, ParameterMode.IN);
            query.registerStoredProcedureParameter("pMaticni_broj", String.class, ParameterMode.IN);
            query.registerStoredProcedureParameter("pSifra_Valute", Integer.class,  ParameterMode.IN);
            query.registerStoredProcedureParameter("pCur",Void.class, ParameterMode.REF_CURSOR);

            query.setParameter("pIndSistema", indSistema);
            query.setParameter("pMaticni_broj", mBr);
            query.setParameter("pSifra_Valute", sifraValute);



             query.execute();
                @SuppressWarnings("unchecked")
                List<Object[]> list = query.getResultList();
                List<Racun> listaRacuna = new ArrayList<Racun>();
                for (Object[] item : list) {

                    Racun r = new Racun();
                   r.setOrg_jed(((BigDecimal) item[0]).intValue());
                   r.setKontoId(String.valueOf(item[1]));
                   r.setPartija(String.valueOf(item[2]));
                   r.setProizvod(((BigDecimal) item[3]).intValue());
                   r.setVlasnik(((BigDecimal) item[4]).intValue());
                   r.setErrCode(((BigDecimal) item[5]).intValue());
                   r.setErrMsg(String.valueOf(item[6]));

                   listaRacuna.add(r);
                }


            return listaRacuna;



        }       


    }

    package springboot.request;

    public class RacunRequest {

        private String indSistema;
        private String maticniBroj;
        private int sifraValute;

        public RacunRequest() {
            super();
        }

        public RacunRequest(String indSistema, String maticniBroj, int sifraValute) {
            super();
            this.indSistema = indSistema;
            this.maticniBroj = maticniBroj;
            this.sifraValute = sifraValute;
        }

        public String getIndSistema() {
            return indSistema;
        }

        public void setIndSistema(String indSistema) {
            this.indSistema = indSistema;
        }

        public String getMaticniBroj() {
            return maticniBroj;
        }

        public void setMaticniBroj(String maticniBroj) {
            this.maticniBroj = maticniBroj;
        }

        public int getSifraValute() {
            return sifraValute;
        }

        public void setSifraValute(int sifraValute) {
            this.sifraValute = sifraValute;
        }


    }

    package springboot;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.web.WebApplicationInitializer;

    import springfox.documentation.swagger2.annotations.EnableSwagger2;

    @SpringBootApplication
    @EnableSwagger2
    @ComponentScan("springboot")

    public class Main extends SpringBootServletInitializer implements WebApplicationInitializer {

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

        @Override
           protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
              return builder.sources(Main.class);

       }


    }


    app.properties file:


    --------not used when trying with jndi :

    server.port = 8084  
    server.context-path=/spring-boot

     Oracle settings


    spring.datasource.url=jdbc:oracle:thin:@harlond.antegra.com:1521:bi 
    spring.datasource.username=pcexpert
    spring.datasource.password=h5rl0nd123y
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
    spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver


    --------not used when trying with jndi



    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
    spring.datasource.jndi-name= jdbc/asebabi

pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>
          <groupId>io.springboot</groupId>
          <artifactId>spring-boot</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <name>Spring Boot 1.0</name>
          <packaging>war</packaging>

          <parent>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-parent</artifactId>
                 <version>1.5.5.RELEASE</version>
          </parent>
         <br> 
          <properties>
                 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                 <java-version>1.7</java-version>
          </properties>
         <br> 

          <dependencies>

                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>

                </dependency>

                <!--      
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc8</artifactId>
                    <version>12.2.0.1</version>
                    <scope>provided</scope>
                </dependency>
              -->

                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>

                 <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>provided</scope>
                </dependency>

                <dependency>
                    <groupId>com.querydsl</groupId>
                    <artifactId>querydsl-core</artifactId>
                    <version>4.1.4</version>
                </dependency>


                <dependency>
                    <groupId>com.querydsl</groupId>
                    <artifactId>querydsl-jpa</artifactId>
                    <version>4.1.4</version>
                </dependency>

              <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger2</artifactId>
                    <version>2.7.0</version>
                    <scope>compile</scope>
                </dependency>

                <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger-ui</artifactId>
                   <version>2.7.0</version>
                     <scope>compile</scope>         
                </dependency>


          </dependencies>

           <build>
                <plugins>

                    <!-- Package as an executable jar/war -->

                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>

                   <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>

                         <configuration>
                             <source>1.7</source>
                             <target>1.7</target>
                         </configuration>
                   </plugin>

               <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                       <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                       <manifest>
                          <addDefaultImplementationEntries>
                                false
                          </addDefaultImplementationEntries>
                       </manifest>
                    </archive>
                 </configuration>
              </plugin>

                </plugins>
            </build>

        </project>

我在数据库中存储的程序:

procedure vratiSveRacune(pIndSistema   in varchar2,
                          pMaticni_broj in b_jk2komitenti.maticni_broj%TYPE,
                          pSifra_Valute in b_jg2valute.sifra_valute%type,
                          pCur out tCur)
   is
   lIzlaz tCur;
   begin

   open lIzlaz for 'select * from table(if4ws_chatbot_pkg.VratiSveRacune(:pIndSistema, :pMaticniBroj, :pSifra_Valute)) ' using pIndSistema, pMaticni_broj, pSifra_Valute;
   pCur := lIzlaz;

   exception
     when others then
          pCur := null;

   end;

0 个答案:

没有答案