我正在尝试实现以下 ibatis 插入注释,但不断收到以下错误消息:
org.apache.ibatis.binding.BindingException:未找到参数“person”。可用参数有 [arg1, arg0, param1, param2]
到目前为止,这是我的代码。我如何解决它?
@(Insert("INSERT INTO profile (person, school) VALUES (#{person}, #{school})";)
void insertOne(TestTextMessage person, String school)
Run Code Online (Sandbox Code Playgroud)
一些背景:
试过这个...@(Insert("INSERT INTO profile (person, school) VALUES (#{arg0}, #{arg1})";)但现在得到一个 java.lang.Assertion 错误。TestTextMessage 是一个包含以下值的类:
@Data
@NoArgs
@EqualsAndHashCode
public class TestTextMessage {
private long id;
private String name;
private int age;
}
Run Code Online (Sandbox Code Playgroud)
目前我这样称呼它:
messageMapper.insertOne(new TestTextMessage(person1), SchoolType.EDENGLEN);
Run Code Online (Sandbox Code Playgroud)
如果我将学校类型移到班级,那么它应该可以工作,但是我如何为学校类型赋值?
我遇到了一个我认为纯粹是UTC的代码中意外的夏令时问题.我正在使用Java 1.6,iBatis SQL映射器(2.3.3)和Oracle XE(Oracle 10.2的eval版本)和Oracle瘦驱动程序.
该数据库包含表示电视广播时间表的表.每个"资产"(程序)都有一个start_time和结束时间.这是相关的切片:
create table Asset
(
asset_id integer not null, -- The unique id of the Asset.
[...]
start_time timestamp, -- The start time.
end_time timestamp, -- The end time.
[...]
constraint asset_primary_key primary key (asset_id),
constraint asset_time check (end_time >= start_time)
);
Run Code Online (Sandbox Code Playgroud)
2009年11 asset_time月1日这个即将到来的星期天早上,跨越美国中央夏令时调整的节目正在开启oracle 约束.
我有这个数据传输对象(日期是java.util.Dates):
public class Asset
{
protected Long asset_id;
[...]
protected Date start_time;
protected Date end_time;
public Date getStart_time() { return start_time; }
public Date getEnd_time() { return end_time; } …Run Code Online (Sandbox Code Playgroud) 我问了一个问题,其标题可能会产生误导,所以我将尝试用更详细的东西再次提出这个问题.(我知道问题似乎很长但请耐心等待我)
我正在尝试做什么:我只是想为我的DAO编写测试用例并使其工作.我知道我的DAO在容器(app服务器)内工作正常但是从测试用例调用DAO时它不起作用.我认为因为它在容器之外.
在我的spring-for-iBatis.xml中填充
<bean id="IbatisDataSourceOracle" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/RSRC/my/db/oltp"/>
</bean>
<bean id="MapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config-oracle.xml"/>
<property name="dataSource" ref="IbatisDataSourceOracle"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
在我的sql-map-config-oracle.xml中填充
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="jdbc/RSRC/my/db/oltp"/>
</dataSource>
</transactionManager>
<sqlMap resource="mymapping.xml"/>
</sqlMapConfig>
Run Code Online (Sandbox Code Playgroud)
我的抽象类:
public abstract MyAbstract {
public SqlMapClientTemplate getSqlTempl() SQLException{
public static final String ORCL = "jdbc/RSRC/PIH/eiv/oltp";
try {
ApplicationInitializer.getApplicationContext().getBean("MapClient");
SqlMapClient scl = (SqlMapClient) ApplicationInitializer.getApplicationContext().getBean("MapClient");
DataSource dsc = (DataSource) MyServiceLocator.getInstance().getDataSource(ORCL);
return new SqlMapClientTemplate (dsc, scl);
}
catch (NamingException e)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个使用myBatis进行持久化的项目.下面的方法"A"工作正常,直到我添加了一些外键并将我的表从myISAM转换为innoDB.转换后,方法"A"将无声地失败,甚至在日志中都没有警告.转换后,只有方法"B"才能成功插入.两种方法都将正确的sql写入日志,但只有"B"才有效.
任何人都可以告诉我为什么我现在需要提交,但以前没有必要提交?
//doesnt work, but worked previously
public void A(Role role) {
SqlSession session = sqlSessionFactory.openSession();
try {
RoleMapper mapper = session.getMapper(RoleMapper.class);
mapper.updateByPrimaryKeySelective(role);
}catch(Exception e){
logger.error(e);
} finally {
session.close();
}
return;
}
//works correctly, but why?
public void B(Role role) {
SqlSession session = sqlSessionFactory.openSession();
try {
RoleMapper mapper = session.getMapper(RoleMapper.class);
mapper.updateByPrimaryKeySelective(role);
session.commit();
}catch(Exception e){
logger.error(e);
} finally {
session.close();
}
return;
}
Run Code Online (Sandbox Code Playgroud) 我在批处理作业中执行了不同的操作.
但在开始所有这些步骤之前,我需要清理一个表格.是否有任何简单的方法来编写将直接从作业xml文件中删除表的tasklet?
我使用ibatis作为ORM
我有一个Java生产者线程,每隔n毫秒从Oracle表中提取项目.当前实现依赖于Java时间戳来检索数据,而不再重新检索它们.
我的目标是摆脱时间戳模式,并直接更新我从数据库中提取的相同项目.
有没有办法选择一组项目并同时更新它们以将它们标记为"正在处理"?
如果没有,依赖于IN子句的单独UPDATE查询是否会成为主要的性能影响?为此尝试使用临时表,但我发现性能受到严重影响.
不知道它是否有帮助,但应用程序正在使用iBatis.
我想将 HSQLDB 用作嵌入式数据库,但无法让它自动递增。
据我了解,[CALL] IDENTITY()可以用来获取最后一个主键值。然而,通过 iBatis 和 HSQLDB 的实验DatabaseManagerSwing不断返回 0 值。
如何获得自动增量以与 HSQLDB 一起使用?
编辑:
我没有提到我使用DDLUtils来自动生成表。以下不适合 HSQLDB:
<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database.dtd">
<database name="testdb">
<table name="users">
<!-- using autoincrement attribute below causes
"primary key already exists" exception -->
<column name="id" type="INTEGER" primaryKey="true" />
<column name="username" type="VARCHAR" size="30" />
<column name="password" type="VARCHAR" size="100" />
</table>
</database>
Run Code Online (Sandbox Code Playgroud)
此外,这里是用于域类的 iBatis SQL 映射:
<insert id="insertUser" parameterClass="user">
<selectKey keyProperty="id" resultClass="int">
CALL IDENTITY()
</selectKey>
INSERT …Run Code Online (Sandbox Code Playgroud) 我试图使用mybatis运行一个简单的SQL查询但它给我以下异常
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mycom.myproject.db.mybatis.dao.UserMapper.countByExample
org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:660)
org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:495)
org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:488)
org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:236)
org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:71)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:39)
$Proxy9.countByExample(Unknown Source)
com.mycom.myproject.controller.LoginController.login(LoginController.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Run Code Online (Sandbox Code Playgroud)
我的UserMapper.xml是
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mycom.myproject.db.mybatis.dao.UserMapper" >
<select id="countByExample" resultType="int">
select count(*) from users
</select>
</mapper>
Run Code Online (Sandbox Code Playgroud)
我的UserMapper是
public interface UserMapper {
int countByExample();
}
Run Code Online (Sandbox Code Playgroud)
我试图在我的LoginController中访问它
public class LoginController
{
static final Logger logger = …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)