gpt4 book ai didi

postgresql - 带有 postgres 的 MyBatis 抛出 "ERROR: relation "dual"does not exist"

转载 作者:行者123 更新时间:2023-11-29 11:59:52 25 4
gpt4 key购买 nike

我正在使用 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 正在幕后寻找一个名为“dual”的表,它存在于 Oracle 而不是在 postgres 中。目前这只是一个猜测。

我被困在这里,非常感谢帮助。提前致谢。

完整跟踪如下:

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 在 postgres 中不存在,所以您需要将该查询更改为 SELECT 1。 dbcp 的使用方法有很多种,因此您需要了解它在您的项目中是如何使用和配置的。

你正在使用 spring,所以很可能你有 BasicDataSource在 spring 上下文中配置 validationQuery 设置。

另一种方法是在您的项目中对 dual 进行全文搜索。

关于postgresql - 带有 postgres 的 MyBatis 抛出 "ERROR: relation "dual"does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28030115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com