首页 > 解决方案 > 在 Spring Boot 应用程序中出现新数据库错误

问题描述

我有一个带有 SQL 服务器数据库的 Java 应用程序。它工作正常。现在我们想将数据库迁移到一个新的数据库,我得到了一个新的服务器名称、端口、实例名称以及连接数据库所需的一切。

连接成功,尝试通过应用程序执行某些查询时,出现以下错误。

org.springframework.dao.InvalidDataAccessResourceUsageException:无法提取结果集;SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:238)

客户不希望任何代码更改。指向以前的数据库或新迁移的开发环境的数据库再次正常工作。问题仅与此数据库有关。

我正在做选择操作。下面是模型类

    @Entity(name = "EIDPAT")
    public class UserAuthenticate {
    @Id
    @Column(name="UserPin")
    private String userPin;
    
    @Column(name="FirstName")
    private String firstName;
    
    @Column(name="MiddleName")
    private String middleName;
    
    @Column(name="LastName")
    private String lastName;
    
    
    @Column(name="Email")
    private String emailAddress;

    }

回购类

    public interface UserAuthenticateRepository extends 
    CrudRepository<UserAuthenticate, String> { }

服务等级

    public UserAuthenticate findUser(String userPin) {
        return userAuthenticateRepository.findOne(userPin);
    }

aad 数据库配置.xml

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/tx 
     http://www.springframework.org/schema/tx/spring-tx.xsd">

    <bean id="SqlCon" 
    class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="java:jboss/jdbc/PAT/pat_ds"/>
    </bean>
        
    <bean id="jdbcTemplate" 
    class="org.springframework.jdbc.core.JdbcTemplate">  
        <property name="dataSource" ref="SqlCon"></property>  
    </bean>
    
    <bean id="namedParameterTemplate" 
     
    class="org.springframework.jdbc.core. 
    namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="SqlCon"></constructor-arg>
    </bean>  
    
    <bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa. 
    LocalContainerEntityManagerFactoryBean 
    ">
        <property name="dataSource" ref="SqlCon"></property>
        <property name="jpaVendorAdapter">
            <bean 
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" 
    >
            </bean>
        </property>
        <property name="packagesToScan" value="com.mmm.aad.model"> 
    </property>
        <property name="jpaProperties">
            <props>
                <prop 
    key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.show_sql">true</prop>            
            </props>
        </property>
    </bean>
    </beans>

标签: javasqlsql-serverspring

解决方案


推荐阅读