ibatis

java架构

隐身守侯 提交于 2019-12-05 02:17:30
技术架构是以 Spring Framework为核心容器,Spring MVC为模型视图控制器,MyBatis作为数据访问层, Apache Shiro为权限授权层,使用Ehcahe对常用数据进行缓存。采用分层设计、双重验证、提交数据安全编码、密码加密、访问验证、数据权限验证。使用Maven做项目管理,提高项目的易开发性、扩展性。 MyBatis 本是 apache 的一个开源项目 iBatis , 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。2013年11月迁移到Github。 iBATIS一词来源于“internet”和“abatis”的组合,是一个基于Java的 持久层 框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAOs) 来源: https://www.cnblogs.com/hshy/p/11897132.html

How to set fetchSize for iBatis select statement

青春壹個敷衍的年華 提交于 2019-12-04 21:31:49
问题 I'm using iBatis as ORM framework in Java. I have a select statement <select id="getList" resultMap="correctMap"> SELECT * FROM SOME_TABLE </select> And I'm using queryForList method: List<MappedObject> list = getSqlMapClientTemplate().queryForList("getList"); But it retrieves a big amount of data and performance of this query is pretty slow. My assumption about this issues that iBatis has default fetch size (e.g. like in JDBS is 10) so that is why it so slow. So I want to set bigger fetch

很开心,在使用mybatis的过程中我踩到一个坑。

眉间皱痕 提交于 2019-12-04 20:32:24
这是why技术的第14篇原创文章 在实际开发过程中我踩到了mybatis的一个坑,我觉得值得记录、分享一下。 先说说这个坑是什么吧。如果你踩过这个坑,并且知道具体的原因,那这篇文章可以加深你的印象。如果你没有踩过,那你可得好好看看,因为你总会遇到的。 具体如下:在mybatis中的OgnlOps.equal(0,"")返回的是true。 首先这里返回为true就违背了我们的常识,其次返回为true,会带来什么问题呢? 看完本文你就清楚了。 本文会按照遇到问题 --> 分析问题 --> 解决问题的行文思路,用追踪源码的方法,对这个问题进行剖析。 同时分享一下我是怎么用逆向排查的方法,通过Debug模式找到最关键的那一行源码,然后明白前因后果,最后解决这个问题的。 本文源码:mybatis 3.5.3版本。 背景介绍,需求分析 先铺垫一下背景,模拟一个需求。 有一个订单表,表结构如下: 为了简化问题,我们假设表里面只有两条数据: > 订单号为1234的订单状态为0【关闭】 > > 订单号为4321的订单状态为1【开启】 已经开发好的功能是模糊查询订单名称,接口如下: 其对应的mapper.xml是这样写的,功能正常: 现在需要在已有功能上添加一个根据状态过滤订单的功能: 假设某个页面有这样的一个下拉框,可以根据订单状态过滤订单数据。 当用户选择【已支付】时,后台接收到的是数字1

注解开发中一对一关系的处理方式

佐手、 提交于 2019-12-04 18:39:45
package com.hope.dao;import com.hope.domain.Account;import org.apache.ibatis.annotations.One;import org.apache.ibatis.annotations.Result;import org.apache.ibatis.annotations.Results;import org.apache.ibatis.annotations.Select;import org.apache.ibatis.mapping.FetchType;import java.util.List;/** * @author newcityman * @date 2019/11/17 - 19:50 */public interface IAccountDao { /** * 查询所有账户信息 */ @Select("select * from account") @Results( id = "accountMap",value={ @Result(id=true,column = "id",property = "id"), @Result(column = "uid",property = "uid"), @Result(column = "money",property = "money"),

PostgreSQL - integer[] best practice

半城伤御伤魂 提交于 2019-12-04 18:07:12
Working on a web app lately I decided to use integer[] in the data model. Having 2 tables, one with articles' data and a second with tags (tag id and description), decided to the tag ids an article would be tagged with in a article.tags integer[] column. As Milen A. Radev pointed out: Tip: Arrays are not sets; searching for specific array elements can be a sign of database misdesign. Consider using a separate table with a row for each item that would be an array element. This will be easier to search, and is likely to scale better for a large number of elements. Not only that, but having to

How to prevent concurrency issue in UPDATE via iBatis

跟風遠走 提交于 2019-12-04 16:14:21
Our Java EE web application performs database operations using iBatis (ORM). The database operation flow is as below Flow : JSP --->Action--->ServiceIMpl--->DaoImpl---->Calling update query thru' IBatis Note : The Action, Service & DAO classes are instantiated using Spring 2.5's Dependency Injection technique. We use Struts2. Problem : 2 concurrent users search for the same record and User1 updates Attribute1 while User2 updates Attribute2. User1 first clicks on 'Save' and then User2 clicks on save (they follow each other with a difference of few seconds). When we see the data in database,

Running multiple mysql statements in one transaction in Mybatis migration tool

∥☆過路亽.° 提交于 2019-12-04 15:36:52
I'm using the Mybatis migration tool to maintain the schema to our database but I'm having the following problem. Currently, if we use multiple statements in a migration they are each run in a separate transaction. So if I want to alter 2 tables (or run multiple statements) as part of a feature and one of them breaks, any that were run first have to be manually reverted. The mybatis migration however is only marked as complete in the changelog table if all statements completed successfully. This is really frustrating because there's no way to maintain a constant db state if the entire

Multiple statements in single mapper method in MyBatis

╄→尐↘猪︶ㄣ 提交于 2019-12-04 14:19:58
I have a mapper method to delete all records in a table. But first I need to delete all records from associated junction table. This is what I tried: @Delete("delete from COC_BLOCK_FIELD; delete from COC_BLOCK;") void deleteBlocks(); That seemed reasonable, yet MyBatis throws an exception when processing my mapper: Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to

Log SQL queries in project using MyBatis and Spring

泄露秘密 提交于 2019-12-04 13:28:09
问题 In my project i have <bean id="ABCSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="ABCDataSource" /> <property name="mapperLocations"> <list> <value>classpath:com/myco/dao/XYZMapper.xml</value> </list> </property> <bean> and log4j.logger.java.sql.Connection=debug, stdout, abclog log4j.logger.java.sql.PreparedStatement=debug, stdout, abclog log4j.logger.java.sql=debug, stdout, abclog log4j.logger.org.mybatis=debug, stdout, abclog log4j.logger

How to Select a BLOB column from database using iBatis

送分小仙女□ 提交于 2019-12-04 12:50:48
One of a table's column is of BLOB datatype (Oracle 10g). We have a simple select query executed via iBatis to select the BLOB column and display it using Struts2 & JSP. The result tag in the iBatis xml file had the jdbctype as java.sql.Blob <result property="uploadContent" column="uploadcontent" jdbctype="Blob"/> Should we be mentioning any typeHandler class for Blob column ? Currently we are getting an error stating column type mismatch. Note: This column is selected and mapped into a java bean who has an attribute of type java.sql.Blob I think you cannot use native jdbctype for LOB types in