ibatis

16-二级缓存

老子叫甜甜 提交于 2019-11-28 11:10:24
目录 一、SqlMapConfig.xml 二、IUserDao.xml 三、JAVA 代码 四、Log 输出 五、总结 二级缓存: 它指的是 Mybatis 中 SqlSessionFactory 对象的缓存。由同一个 SqlSessionFactory 对象创建的 SqlSession 共享其缓存 二级缓存的使用步骤 让 Mybatis 框架支持二级缓存(在SqlMapConfig.xml配置) 让当前的映射文件支持二级缓存(在IUserDao.xml中配置) 让当前的操作支持二级缓存(在select标签中配置) 一、SqlMapConfig.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <properties resource="jdbcConfig.properties"/> <settings> <!--默认为 true--> <setting name="cacheEnabled" value="true"/> </settings> <typeAliases>

MyBatis parameter from HashMap

和自甴很熟 提交于 2019-11-28 09:00:00
问题 In mapper interface I have: ArrayList<Item> select(@Param("filterId")int filterId, @Param("filterData")HashMap<String,Object> filterData); In mapper xml I have: <select id="select" parameterType="map" resultMap="RM"> SELECT ... FROM .... WHERE id=#{filterData["id"]} </select> No errors but the result is not as expected (it returns empty set but I know item with such id exists). The #{filterData["id"]} seems not to work. Where is my mistake? 回答1: I found the answer: <select id="select"

Ibatis的缓存机制

被刻印的时光 ゝ 提交于 2019-11-28 07:10:57
我们知道Hibernate有自己的缓存机制,Hibernate中分为一级缓存和二级缓存,其中的一级缓存是session缓存,是Hibernate封装好的,不需要我们做任何配置的,一级缓存是与session绑定的,当session生命周期结束的时候对应的一级缓存也就消失了。Hibernate的二级缓存需要自己配置的,很遗憾,一直没去深入了解过,等过了这阶段比较忙的时间一定得好好研究研究Hibernate 至于我们的Ibatis,也是有着自己的缓存机制的,使用ibatis的缓存的时候我们要特别的小心谨慎,保证对缓存对象操作的同步性。 <!-- 定义缓存 --> <cacheModelid="query_cache_xy" readOnly="false" serialize="true" type="LRU"> <flushInterval hours="24" /> <flushOnExecute statement="xueyuan.save" /> <flushOnExecute statement="xueyuan.edit" /> <flushOnExecute statement="xueyuan.del" /> <property value="600" name="size" /> </cacheModel> 这是一个典型的缓存例子

MySql.Data.MySqlClient.MySqlException: Timeout expired

╄→尐↘猪︶ㄣ 提交于 2019-11-28 07:10:14
问题 In recent times, a particular page in my web app throws the Exception Details: MySql.Data.MySqlClient.MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Though I use Ibtais as persistence layer, this error occurs. I have restarted the MySql service instance but stil i get the same error. It didn't happen earlier but happens frequently in recent times. All the web applications deployed on the server uses Ibatis and

iBatis get executed sql

浪子不回头ぞ 提交于 2019-11-28 05:58:00
Is there any way where I can get the executed query of iBatis? I want to reuse the query for an UNION query. For example: <sqlMap namespace="userSQLMap"> <select id="getUser" resultClass="UserPackage.User"> SELECT username, password FROM table WHERE id=#value# </select> </sqlMap> And when I execute the query through int id = 1 List<User> userList = queryDAO.executeForObjectList("userSQLMap.getUser",id) I want to get SELECT username, password FROM table WHERE id=1 Is there any way I could get the query? Thanks. Nando It's posible to show this information.iBatis uses some the Logging framework

When to use $ vs #?

天涯浪子 提交于 2019-11-28 05:26:57
I am confused about using $ vs # . I didn't found any guides for this. I used them as name = #{name} , name like '%${word}%' , order by name ${orderAs} , where name = #{word} Sometimes , these are work fine but at the sometimes , parameters aren't included or gave me error like org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'name'....... So, I'd like to know when to use $ or # ? Following the myBatis guidelines #{} is used in your sql statements. If you take a look any of MyBatis Reference in the Section Mapper XML Files it says explicity: Notice the

Hibernate Vs iBATIS [closed]

旧城冷巷雨未停 提交于 2019-11-28 02:35:53
For our new product re-engineering, we are in the process of selecting the best framework from Java. As the consideration is to go for database agnostic approach for model, we are working on options between Struts + Spring with iBATIS or Hibernate. Please advice which is best as both offer persistence. Ibatis and Hibernate are quite different beasts. The way I tend to look at it is this: Hibernate works better if your view is more object-centric . If however you view is more database-centric then Ibatis is a much stronger choice. If you're in complete control of your schema and you don't have

mybatis- 3.1.1. how to override the resultmap returned from mybatis

安稳与你 提交于 2019-11-28 02:17:32
问题 we using mybatis 3.1.1. we found for oracle the result map returned contains column name in Capital letters and in case of mySql the result map returned contains column name in small letters. My question is : Is there is any way i can to write some sort of interceptor so that i can modify the result returned by result map. Thanks. 回答1: I'm afraid the answer is that MyBatis doesn't provide any direct way to control the case of the keys in a result map. I asked this question recently on the

Get the id of last inserted record in mybatis

会有一股神秘感。 提交于 2019-11-27 20:53:42
I am newbie to mybatis. I am trying to get the id of last inserted record. My database is mysql and my mapper xml is <insert id="insertSelective" parameterType="com.mycom.myproject.db.mybatis.model.FileAttachment" > <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" > SELECT LAST_INSERT_ID() as id </selectKey> insert into fileAttachment <trim prefix="(" suffix=")" suffixOverrides="," > <if test="name != null" > name, </if> <if test="attachmentFileSize != null" > size, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="name != null" > #{name

异常处理

天大地大妈咪最大 提交于 2019-11-27 19:21:42
1、异常:Field bookMapper in com.aaa.lee.springboot.service.BookService required a bean of type 'com.aaa.lee.springboot.mapper.BookMapper' that could not be found. 原因:在service中使用@Autowired注解注入了mapper,最终mapper没有注入成功,也就是mapper并没有以bean的形式配置进application.xml配置文件(没有mapper的扫描器) 需要添加@Mapper注解; 2、使用注解的形式写上SQL语句,实体类的属性和数据库的字段映射问题:   当使用@Select @Update @Delete @Insert来替代mapper.xml的时候,需要把数据库表中字段名和实体类的属性要完全一致! 1 package com.aaa.liu.springboot.mapper; 2 3 import com.aaa.liu.springboot.model.Book; 4 import org.apache.ibatis.annotations.Delete; 5 import org.apache.ibatis.annotations.Insert; 6 import org.apache