我使用MyBatis在基于java web的应用程序的postgres数据库中执行一个非常简单的选择
设置如下:

    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.2.2</version>
    </dependency>

以及以下驱动程序:
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.2-1004-jdbc41</version>
    </dependency>

映射器如下所示:
<select id="getLicenseUsage"  parameterType="long"  resultMap="licenseUsage">
    select ('1970-01-01 00:00:00 GMT'::timestamp + (event_time/1000)::text::interval)::date as day, license_key, count(distinct event_id) as recos, max(id) as venm_id
    from venm_raw
    where target_id is not null and id > #{fromId}
    group by license_key,day;
</select>

当我执行此查询时,会出现以下错误:
"ERROR: relation "dual" does not exist"

从网络上的不同读物看来,MybATIS正在幕后寻找一个名为“对偶”的表,该表存在于Oracle中,而不在PASGRESs中。这只是猜测。
我被困在这里,非常感谢你的帮助。提前付款。
完整跟踪如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ERROR: relation "dual" does not exist)
### The error may exist in file [/opt/tomcat/webapps/ROOT/WEB-INF/classes/META-INF/mappers/redshift/LicenseUsageMapper.xml]
### The error may involve com.qualcomm.vuforia.redshift.mappers.LicenseUsageMapper.getLicenseUsage
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ERROR: relation "dual" does not exist)
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
        at com.sun.proxy.$Proxy36.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
        at com.sun.proxy.$Proxy49.getLicenseUsage(Unknown Source)
        at com.qualcomm.vuforia.sumtables.summarizers.SummarizerProcessor.process(SummarizerProcessor.java:60)
        at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)

最佳答案

查看错误的堆栈跟踪,我可以说使用了apache数据库连接池。看起来它的validationQuery配置成了类似于SELECT 1 FROM dual的东西。mybatis本身不使用dbcp,并且有自己的池数据源实现,所以这个dbcp是在您的项目中配置的。
当您能够计算出不存在在该文件中的dual时,您需要将查询改为SELECT 1。有很多方法可以使用dbcp,因此您需要了解如何在项目中使用和配置它。
您使用的是spring,因此很可能在spring上下文中配置了BasicDataSource,并设置了validationQuery
另一种方法是在项目中对dual进行全文搜索。

关于postgresql - MyBatis与postgres引发“错误:关系“dual”不存在”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28030115/

10-12 01:50