在使用 PostgreSQL 在 MyBatis 中运行 select 时出现此错误:
\n\n### The error may exist in data/mapper.xml\n### The error may involve Transaccion.selectDeFraude-Inline\n### The error occurred while setting parameters\n### SQL: SELECT transaction_id, card_number, transaction_date, fraud FROM transactions.? ORDER BY card_number, transaction_date ASC;\n### Cause: org.postgresql.util.PSQLException: ERROR: error de sintaxis en o cerca de \xc2\xab$1\xc2\xbb\nRun Code Online (Sandbox Code Playgroud)\n\n我在 mapper.xml 中收到错误:
\n\n<select id="selectDeFraude" parameterType="String" resultMap="result">\n SELECT transaction_id, card_number, transaction_date, fraud FROM transactions.#{tabla} ORDER BY card_number, transaction_date ASC;\n</select>\nRun Code Online (Sandbox Code Playgroud)\n\n这是调用 select 的方法:
\n\npublic List<Transaccion> selectDeFraude(String tabla){\n\n …Run Code Online (Sandbox Code Playgroud) 当我尝试从我的应用程序调用一个过程时出现错误,提示ORA-01002: fetch out of sequence
使用的技术:
这里有趣的一点是,只有当我对服务类中的调用方法使用@Transactional (org.springframework.transaction.annotation.Transactional) 注释时才会发生错误。如果我删除@Transactional,则没有 ORA 错误。
我正在使用 @Transactional,因为我将几个 DAO 注入到服务中。请找到我粘贴在下面的代码。
@Transactional
public boolean saveavgFlyHrs(AverageFlyingHoursReport averageFlyingHoursReport) throws TransactionDataException {
String status = null;
boolean isOk = false;
if(averageFlyingHoursReportDAO.saveavgFlyHrs(averageFlyingHoursReport)) {
status = averageFlyingHoursReportDAO.updateCheckEff(averageFlyingHoursReport.getSubFleet());
logger.debug("OUT_STATUS:"+status);
if(ConstantStringUtil.SUCCESS.equalsIgnoreCase(status)) {
isOk = true;
} else {
isOk = false;
}
}
return isOk;
}
Run Code Online (Sandbox Code Playgroud)
任何人请帮助我。
我正在尝试在 mybatis 映射器中删除一个表,但是。
<update id="dropTable" parameterType="String">
DROP TABLE #{name}
</update>
Run Code Online (Sandbox Code Playgroud)
这会生成如下查询:
删除表“TEMP_TABLE”;
Oracle 不喜欢这种语法。我正在寻找一种方法来添加 #{name} 参数而不使用“'”字符。
我一直在尝试从 mybatis2 转换为 mybatis3,它给了我各种各样的问题。从堆栈跟踪即时得到一个Error Parsing Mapper XML为sqlMapConfig.xml我把它这意味着有什么不对劲的地方,但是我无法看到它。我将不胜感激任何帮助。
sqlMapConfig.xml
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheModelsEnabled" value="true" />
<setting name="enhancementEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="maxRequests" value="128"/>
<setting name="maxSessions" value="10"/>
<setting name="maxTransactions" value="5"/>
<setting name="defaultStatementTimeout" value="0"/>
<setting name="statementCachingEnabled" value="true"/>
<setting name="classInfoCacheEnabled" value="true"/>
</settings>
<mappers>
<mapper resource="com/fidelity/cmplnr/datasource/search_sql.xml"/>
</mappers>
</configuration>
Run Code Online (Sandbox Code Playgroud)
bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean …Run Code Online (Sandbox Code Playgroud) 在"applicationContext-base.xml"中我添加如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
>
.....
<!-- transaction support-->
<!-- PlatformTransactionMnager -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable transaction annotation support -->
<tx:annotation-driven transaction-manager="txManager" />
Run Code Online (Sandbox Code Playgroud)
我想在"控制器"中为一个函数设置一个事务
@Controller
@RequestMapping("/ywdata")
public class YwController extends BaseController{
....
@Transactional(timeout=1)
private void submitNewSXSQ(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception {
...//STEP1 :do some db insert and update STEP1
if(true)
throw new Exception("test …Run Code Online (Sandbox Code Playgroud) 我用MyBatis创建了Spring MVC 4.我很确定我的设置都正确.出于某种原因,我收到了这个错误.任何帮助表示赞赏
Apr 30, 2015 7:22:56 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [myBatisServlet] in context with path [/APMS] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'one' not found. Available parameters are [0, 1, 2, param5, 3, 4, param3, param4, param1, param2]] with root cause
org.apache.ibatis.binding.BindingException: Parameter 'one' not found. Available parameters are [0, 1, 2, param5, 3, 4, param3, param4, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:165)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:186)
at …Run Code Online (Sandbox Code Playgroud) Mybatis 可以用反射设置值吗?我有一个类,它有一个属性,它的 setter 是 protected 。所以我必须使用反射来设置这个值?Mybatis 可以工作吗?
需要使用 SpringBoot 将 Camel 和 MyBatis 与应用程序集成。SpringBoot 为 Camel 和 MyBatis 提供了开箱即用的支持。还提供Camel和MyBatis SpringBoot启动器。
但是,当我尝试将 Spring Boot 应用程序与 Camel 和 MyBatis 集成时,它失败了。
我正在使用基于 Java DSL 的 Camel Route。还使用 Mybatis Spring 启动依赖项。注释映射器,在 application.properties 文件中添加数据库属性。我期望发生的事情:1)SpringBoot 在启动时设置数据源和映射器、sqlsessionfactory。2)接下来调用Camel-MyBatis消费者,(1)中完成的设置将允许Camel成功使用mybatis进行数据库调用。
我创建了 spring 带注释的配置类并用它来创建/获取 DataSource bean。
我怎样才能让Camel使用这个dataSource bean?如何告诉 Camel 使用新构建的 SQL 会话工厂,而不是尝试从配置文件构建?
在 github 中创建了示例应用程序,它使用内存数据库(h2)
示例应用程序
获取 NPE Consumer[mybatis://getClaimInfo?statementType=SelectOne] 失败的轮询端点:Endpoint[mybatis://getClaimInfo?statementType=SelectOne]。将在下次投票时再试一次。引起的:[org.apache.ibatis.exceptions.PersistenceException -
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.4.0.jar:3.4.0]
Run Code Online (Sandbox Code Playgroud)
在 org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100) ~[mybatis-3.4.0.jar:3.4.0] 在 org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession( DefaultSqlSessionFactory.java:47) ~[mybatis-3.4.0.jar:3.4.0]
我正在尝试使用带有 Spring Boot 的 MyBatis Cursor 来迭代一个大型查询:
映射器:
@Mapper
@Repository
interface UserMapper {
@Select("SELECT * FROM huge_user_table")
Cursor<User> getUsers();
Run Code Online (Sandbox Code Playgroud)
消费者:
@Component
public class UserProcessor {
@Autowired private UserMapper userMapper;
public boolean process() throws IOException {
Cursor<User> users = userMapper.getUsers();
//users.isOpen() == false
for (User user : users) {
//Never iterates
System.out.println(user.getId());
}
Run Code Online (Sandbox Code Playgroud)
当我将光标取回时,尽管它已关闭,但没有返回任何记录。
我错过了什么吗?
一开始我没有使用@Param注解,这是我的mapper.java
public void changeUserAuth(Integer userId,int identity);
Run Code Online (Sandbox Code Playgroud)
,这是我的 mapper.xml
<update id="changeUserAuth">
update user
<set>
<if test="identity != 0">identity = #{identity}</if>
</set>
<where>
<if test="userId != 0">userId = #{userId}</if>
</where>
</update>
Run Code Online (Sandbox Code Playgroud)
那么就正常运行了!我继续这样写,如下:
//this's mapper.java
public void updateUserStatus(Integer userId);
<!--this is mapper.xml>
<update id="changeUserAuth">
update user
set deleteFlag= true
<where>
<if test="userId != 0">userId = #{userId}</if>
</where>
</update>
Run Code Online (Sandbox Code Playgroud)
然而,它给出了一个错误,消息是
'class.java.lang.Integer' 中没有名为 'userId' 的属性的 getter
我可以理解mybatis无法解析Integer,但是为什么它不像我第一次使用那样错误,仅仅因为我有一个int类型的参数?在第二种方法中,我必须使用@Param注解
mybatis ×10
spring ×5
java ×4
ibatis ×2
oracle ×2
spring-mvc ×2
annotations ×1
apache-camel ×1
plsql ×1
postgresql ×1
spring-boot ×1
xml ×1