标签: mybatis

Android应用程序和myBatis

我想在Android应用程序中使用myBatis(iBatis 3).有没有人尝试过这样的事情或知道任何资源?

sqlite android ibatis mybatis

7
推荐指数
2
解决办法
5052
查看次数

算术异常,数字溢出或字符串截断

我使用firebird作为我的数据库和mybatis来操作数据,但是当我使用长度大于5的关键字运行查询时,会发生以下错误:

### Cause: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -303
arithmetic exception, numeric overflow, or string truncation
No message for code 335544914 found.
Run Code Online (Sandbox Code Playgroud)

如果它的长度小于6,它运行正常.我将mybatis和firebird更新到最新版本,结果是一样的.

详细的sql如下:

 select b.*, bt.type_no as "type.id" , bt.type_dsc "type.name", 
  bt.show "type.show", bt.del "type.del" 
from 
  book b,book_type bt 
where 
  b.type_no=bt.type_no and bt.del=0 
  and b.del=0 and b.type_no in (74) 
  and (( lower(title) like '%aaaaaaaaa%' ) or ( lower(content) like '%aaaaaaaaa%' )) 
order by bt.show desc,b.type_no,b.id 
Run Code Online (Sandbox Code Playgroud)

其次是错误日志:

2012-07-03 23:20:14 [DEBUG](org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl:42) ooo Using Connection [org.firebirdsql.jdbc.FBConnection@1389b3f] …
Run Code Online (Sandbox Code Playgroud)

sql firebird mybatis

7
推荐指数
1
解决办法
9676
查看次数

是java.lang.NoClassDefFoundError:org/apache/ibatis/session/SqlSessionFactory与mybatis和Spring

我是Mybatis的新手并尝试使用Spring实现mybatis但在启动tomcat时遇到以下运行时错误.

这是我的 pom.xml

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

和应用环境:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="uactivityDS"/>
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

错误是:

the resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory
Run Code Online (Sandbox Code Playgroud)

但是该mybatis-spring-1.0.0.jar文件存在于war/web-inf/lib.

知道这种情况下发生了什么吗?

spring spring-jdbc spring-aop mybatis

7
推荐指数
1
解决办法
2万
查看次数

Mybatis - 未映射的继承属性

我有两个类,其中一个继承另一个.我正在尝试将我的resultSet映射到子类,而Mybatis忽略了超类上的属性(Setters也在超类上)

代码如下:

public class CocTreeNode extends CocBean implements TreeNode<CocTreeNode> {

  private String level1, level2;

  public void setLevel1(String level1){...}
  public void setLevel2(String level2){...}

  public String getLevel1(){...}
  public String getLevel1(){...}

}

public class CocBean {

  protected String name;
  protected Double volume;

  public void setName(String name){...}
  public void setVolume(Double volume){...}

  public String getName(){...}
  public Double getVolume(){...}

}
Run Code Online (Sandbox Code Playgroud)

我的resultMap是 -

<resultMap id="simpleRow" type="CocTreeNode">
  <id property="level1" column="LEVEL1"/>
  <id property="level2" column="LEVEL2"/>
  <result property="name" column="NAME"/>
  <result property="volume" column="VOLUME"/>
</resultMap>
Run Code Online (Sandbox Code Playgroud)

生成的CocTreeNode对象使用"level1"和"level2"属性填充,但不填充"name"和"volume".

我尝试使用扩展,但没有任何区别.

任何想法将不胜感激.

java generics mybatis

7
推荐指数
1
解决办法
7676
查看次数

如何将myBatis选择结果(列表)设置为object的属性?

通常,myBatis的select方法返回单个对象或通用List类型.例如,我想取一个班级的所有学生:

<select id="fetchStudentsOfClass" parameterType="int" resultMap="resultMapStudent">
    SELECT * FROM students WHERE class_id=#{id}
</select>
Run Code Online (Sandbox Code Playgroud)

我很容易得到这样的结果:List<Student>.

现在,如果我想得到这样的结果而不是List<Student>:

class MyClass
{
    List<Student> getStudents{return this.students;}
    void setStudents(List<Student> students){this.students = students}
    private List<Student> students;
}
Run Code Online (Sandbox Code Playgroud)

我能怎么做?

mybatis

7
推荐指数
1
解决办法
3万
查看次数

MyBatis可以创建数据库模式吗?

MyBatis有任何功能允许从像Hibernate那样的de Class Model创建SQL模式吗?

我在谷歌寻找,我只找到有关MyBatis Generator的信息(http://mybatis.github.io/generator/).这个工具似乎对从SQL Schema生成Java模型很有用,这与我想要的相反.

java hibernate ibatis mybatis

7
推荐指数
1
解决办法
4484
查看次数

MyBatis"或"标准

我想用MyBatis创建一个查询,它将产生如下内容:

SELECT first_field, second_filed, third_field
WHERE first_field > 1 AND (second_field > 0 OR third_field < 0)
Run Code Online (Sandbox Code Playgroud)

我怎么能用Criteria对象构造它?

java mybatis

7
推荐指数
2
解决办法
1万
查看次数

MyBatis如何为不同的数据库后端生成不同的sql

我正在使用mybatis-spring 1.2.3和Spring4来创建一个Web应用程序.主数据存储是MySQL在生产环境中,但我也在内存数据库H2中进行单元测试.

MyBatis在测试和生产中都能很好地兼容MySQL和H2,但是我遇到了一个问题,有一天我需要force index(idx1)在MySQL的查询中使用它,这将导致单元测试中的语法错误,因为H2不支持force index.结果,单元测试完全被打破.

我想知道MyBatis有什么方法可以处理这种情况吗?(数据库类型在测试和生产方面有所不同,它们对SQL语法的支持也不尽相同.)

这是我的映射文件:

<?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="myproject.mapper.UserMapper">
  <select id="getGameUsersForDate" resultType="myproject.dao.domain.GameUser">
    select
    *
    from game_user
    force index(idx1)
    where
    game_id in
    <choose>
      <when test="gameIds.size() > 0">
        <foreach item="gameId" collection="gameIds" open="(" separator="," close=")">
          #{gameId}
        </foreach>
      </when>
      <otherwise>
        (null)
      </otherwise>
    </choose>
    and uid in
    <choose>
      <when test="uids.size() > 0">
        <foreach item="uid" collection="mids" open="(" separator="," close=")">
          #{mid}
        </foreach>
      </when>
      <otherwise>
        (null)
      </otherwise>
    </choose>
    and `date` = #{date}
  </select>
</mapper>
Run Code Online (Sandbox Code Playgroud)

java h2 mybatis spring-boot spring-mybatis

7
推荐指数
1
解决办法
2062
查看次数

列在MyBatis'IN'子句中

如何将整数列表传递给MyBatis XML,以便在MySQL查询的in子句中使用?

我正在使用Java 7,MySQL 5.6 DB和MyBatis 3.0.4以及mapper-xml文件中的查询.

目前,我正在将这个整数列表转换为字符串,并使用字符串替换(${}运算符)将值放在"IN"子句中 - 虽然它按预期工作,但这种方法使参数容易受到注入.

我尝试过使用一个<foreach>元素,但我无法弄清楚要指定的属性.

下面是一个示例Java代码:

public List<Stripper> getStripperDetails(String club, List<Integer> stripperIds) {
        Map<String, Object> input = new HashMap<>();
        input.put("club", club);
        input.put("stripperIds", stripperIds);
        return stripClubMapper.getStripperDetails(input);
}
Run Code Online (Sandbox Code Playgroud)

映射器xml:

<select id="getStripperDetails" parameterType="java.util.HashMap" resultMap="StripperMap">
    SELECT STRIPPER_ID, STAGE_NAME, REAL_NAME, CLUB FROM EXOTIC_DANCERS WHERE CLUB = #{club} AND STRIPPER_ID IN     
    <foreach item="item" index="index" collection="stripperIds" open="(" separator="," close=")">
        #{index}
    </foreach>
</select>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚要为<foreach>元素指定的属性- 我继续为#{index}的值运行NullPointerException.

你能帮我理解<foreach>元素的正确用法吗?

编辑:

@ 10086,

下面是堆栈跟踪:

org.mybatis.spring.MyBatisSystemException: nested …
Run Code Online (Sandbox Code Playgroud)

java xml mysql in-clause mybatis

7
推荐指数
2
解决办法
2万
查看次数

非法尝试登记多个1PC XAResources

我们有多个交易经理(WebsphereUOWTransactionManagerDatasourceTransactionManager)并使用Mybatis和NamedParameterJdbcTemplate(遗留代码)

用于工作的代码和所做的更改将转移@Transactional到服务级别并sqlsession.commit从mybatis代码中删除.

但是现在存在JdbcTemplate执行遗留代码()的问题.

错误是

20170427 19:22:02.045 [SimpleThreadPoolWorker-2] DEBUG o.s.b.c.r.d.JdbcStepExecutionDao # Truncating long message before update of StepExecution, original message is: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [
                UPDATE JOB_RUN
                SET SYS_RUN_STUS_CD = ?,
                UPDT_USER_ID = 'SYSTEM',
                REC_UPDT_TS = CURRENT_TIMESTAMP
                WHERE  JOB_RUN_ID = ?
            ]; SQL state [null]; error code [0]; enlist: caught Exception; nested exception is java.sql.SQLException: enlist: caught Exception
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660) …
Run Code Online (Sandbox Code Playgroud)

spring transactional jdbctemplate spring-transactions mybatis

7
推荐指数
0
解决办法
1020
查看次数