ibatis

Hibernate or iBatis or something else?

冷暖自知 提交于 2019-12-01 08:07:15
In my project i need to switch between databases during runtime. I tried to use Hibernate, but stuck in a place, where i need to map object with table in database. The problem is, that i have several tables with prefix: documents2001, documents2002 ... As i understood, i can't map class with table during runtime. I tried using iBatis, but the problem is in database changing during runtime. In iBatis, it is quite hard to do.\ Maybe some advices, what should i use? My requirements: Ability to connect to different databases during runtime Ability to change table during runtime(if class is mapped

Hibernate or iBatis or something else?

末鹿安然 提交于 2019-12-01 07:12:16
问题 In my project i need to switch between databases during runtime. I tried to use Hibernate, but stuck in a place, where i need to map object with table in database. The problem is, that i have several tables with prefix: documents2001, documents2002 ... As i understood, i can't map class with table during runtime. I tried using iBatis, but the problem is in database changing during runtime. In iBatis, it is quite hard to do.\ Maybe some advices, what should i use? My requirements: Ability to

JAVA持久层框架的概述(ibatis>>mybatis)

纵然是瞬间 提交于 2019-12-01 07:00:46
现在主流的ORM映射框架有Hibernate、Apache OJB;这些基于Java的持久层框架都提供了全自动的对象–关系映射机制,能很好的实现从对象到关系数据的持久化操作。几乎不需要写任何的SQL语句(根据配置好的映射关系文件自动生成对应的 SQL 并调用 JDBC 接口加以执行),以面向对象的形式就能实现对数据库的操作。给我们的编程带来了很大的好处,不需要再接触底层的SQL语句,同时也避免了在书写SQL语句时带来的诸多问题。 但这些ORM框架也是有它的问题的,那就是对于复杂的SQL查询、多表的联合查询实现起来很麻烦,甚至某些业务方面用Hibernate无法实现。举个例子:假如有2张几乎相同的表(在实际的项目中这样的情况是存在的),现在需要把这2张表的数据全部查询出来在页面显示,使用Hibernate可能会这样操作,首先各执行一次findAll,然后在Service中循环,再存到一个List中,最后在页面显示。这样是能实现,但是很麻烦,那么简单的方法是什么呢?使用SQL语句中的union all 关键字,一个SQL语句就能实现,所以在这种情况下使用Hibernate就不是很合适了。面对这样的需求,再次举起 Hibernate 大刀,却发现刀锋不再锐利,甚至无法使用,奈何?恍惚之际,只好再摸出JDBC 准备拼死一搏,但JDBC也很麻烦,对于返回的ResultSet也需要处理

mybaits sqlSession 源码解读

戏子无情 提交于 2019-12-01 05:15:44
SqlSession org.apache.ibatis.session.SqlSession 是 mybatis 操作sql、 获取mapper、处理事务的基本单元。一般意义上我们运用mybatis 都是在操作 sqlSession 类图如下: org.apache.ibatis.session.defaults.DefaultSqlSession 默认实现。 DefaultSqlSession 的初始化过程 SqlSessionFactoryBuilder --> DefaultSqlSessionFactory --> SqlSession SqlSession模式一 所有 <T> T selectOne 、 <E> List<E> selectList 均由 <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) 实现。源码: [@Override](https://my.oschina.net/u/1162528) public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) { try { MappedStatement ms = configuration

one to many relation using mybatis or ibatis

我与影子孤独终老i 提交于 2019-12-01 00:34:30
I have database which has two tables post: id post_name post_desc files: file_id file_name post_attachments post_id file_id In my xml mapping I already have <select id="selectPosts" resultType="com.mycom.myproject.bean.postBean"> select id, post_name as postName from post </select> So its a one to many realtionship. I want all the files attached to a post. I don't understand how I can do the mapping in mybatis. I have my PostBean like public class PostBean extends Post { private List<FileAttachment> filesAttachment; //getter setter } I am using mybatis with spring and mysql as database Please

Fetching a LONGBLOB as a byte array using MyBatis

懵懂的女人 提交于 2019-11-30 23:39:52
I am using MyBatis in a project, where I have a query that gets data from a LONGBLOB field in a MySQL database. I wish to get the result as a byte array ( byte[] ), so I try this: <select id="fetchData" resultType="_byte[]" parameterType="_long"> select blobData from Table where id = #{id} </select> This does not work, however. I get the following error: java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object; at org.apache.ibatis.binding.MapperMethod.convertToArray(MapperMethod.java:146) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:129) at org

MyBatis框架UserMapperTest类的改进及核心配置文件

前提是你 提交于 2019-11-30 19:46:17
一、改造UserMapperTest类的代码 (将公共代码创建factory和sqlSession,关闭sqlSession写在MyBatisUtil里面) 在src下面新建一个包cn.smbms.utils,在新建的包cn.smbms.utils里面新建类MyBatisUtil,将UserMapperTest类里面的创建factory,sqlSession和关闭sqlSession写在MyBatisUtil里面 改造后MyBatisUtil里面代码如下: package cn.smbms.utils; import java.io.IOException; import java.io.InputStream; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; public class MyBatisUtil { private static SqlSessionFactory factory ; static { try {

Passing multiple arguments into a SELECT without using a complex object

非 Y 不嫁゛ 提交于 2019-11-30 14:05:00
问题 I am trying to pass in startSequenceId , stopSequenceId , orderNumber into the SQL map, however, i don't wish to use a typed object, i.e. parameterType="com.abc.Order" , can i do so? <select id="getSequenceIdByOrderNumber" parameterType="?" resultType="int"> select * from log where seq_id between #{startSequenceId} and #{stopSequenceId} and order_no = #{orderNumber} and rownum = 1 </select> 回答1: @Chin I'll post what I had typed anyway with a simple example though you found what your looking

MyBatis - how to create w dynamic WHERE Clause

梦想与她 提交于 2019-11-30 10:38:05
The service gets an unknown object containing a list of three values ​​[column, operator, value] For example, EMAIL - like - "TEST" Based on the resulting list to build the WHERE clause I have but I would also be able to build such a condition as follows (for example) WHERE (email like 'test' AND user_id <> 5) OR (trans_id <100 AND session_id> 500) Does anyone can help me how to do it? I have been rediscovering MyBatis after a long absence myself (I was familiar with iBatis at one time). Rolf's example looks like it might be the .Net implementation, I may be wrong but I don't think the Java

Passing multiple arguments into a SELECT without using a complex object

时间秒杀一切 提交于 2019-11-30 09:23:14
I am trying to pass in startSequenceId , stopSequenceId , orderNumber into the SQL map, however, i don't wish to use a typed object, i.e. parameterType="com.abc.Order" , can i do so? <select id="getSequenceIdByOrderNumber" parameterType="?" resultType="int"> select * from log where seq_id between #{startSequenceId} and #{stopSequenceId} and order_no = #{orderNumber} and rownum = 1 </select> @Chin I'll post what I had typed anyway with a simple example though you found what your looking for. My example using iBatis 2.3.4 <select id="retrieveTestXXX" parameterClass="java.util.Map" resultClass=