[Use iBATIS history]
The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the SqlMap.xml documents, are still very uncomfortable thing.
[Hibernate and iBATIS integration]
Later, considering the integration of Hibernate and iBATIS of mind, that is, Hibernate handle CRUD, iBATIS is responsible for complex inquiries. After practice is feasible, the current projects are also accepted and widely used.
However, Hibernate is to have its own caching mechanism, and iBATIS did not like Hibernate so strongly the concept of cache latency (which, of course, iBATIS has CacheModel, but also the result set cache, rather than an object is new cache.) and, Hibernate is the last one-time flush affairs, a panel of other operations are the operation of the cache. and iBATIS in operation within a transaction are to operate directly on the connection.
Is because between Hibernate and iBATIS has such a big difference, we must deal with Hibernate and iBATIS call attention to the order.
[JDBC implementation using the basic CRUD functionality, replace Hibernate]
However, recent又在想, now that is just a simple CRUD functions on the painstaking efforts to use Hibernate, but also bring a lot of unnecessary trouble, so consider JDBC implementation based on their own CRUD functionality, iBATIS is also because of direct connection operations, JDBC is the same, then the Service as compared with Hibernate and iBATIS integration of the many easy to avoid a lot of unnecessary trouble.
[Dependent on JPA's Entity, Id, Column of Annotation Configuration]
In the basic implementation, taking into consideration the continued use of the Annotation to configure JPA to maintain Entity Bean, after use, although the feeling of redundancy comparison, but pretty good. Annotation unfamiliar because, at present only @ Id, @ Column Writing in the configuration, etc. getter methods. The current implementation does not deal with any fault-tolerant, field must be marked @ Column.
Something quite simple, MO amiss. The specific contents can see the project code, project-based Eclipse3.4, Spring2.5, Mysql.
Rar the lib project has already included all the dependent jar package. Rar project also has a basic description of language.
Extract the basic code:
Entity Bean
@Entity(name = "ONE")
public class OneBean extends BaseBo {
private BigDecimal id;
@Id
@Column(name = "ID")
public BigDecimal getId() {
return id;
}
// ...
}
CrudDao the use of
public class OneBeanService implements IOneBeanService {
private CrudDaoFactory crudDaoFactory;
public void noException() throws Exception {
CrudDao<OneBean> crudDao = crudDaoFactory.getCrudDao(OneBean.class);
OneBean bean = this.createOneBean(new BigDecimal(100));
crudDao.insert(bean);
}
// ...
}
Spring configuration
<bean> <property name="dbType" value="mysql"/> <property name="dataSource" ref="dataSource"/> </bean> <bean> <property name="crudDaoFactory" ref="crudDaoFactory"/> </bean>
The following is a run-time Test.java output log information:
16:48:11,156 DEBUG CrudDao:36 - INSERT INTO ONE(NAME, ID, PASSWORD, SEX, BIRTH_DATE_TIME) VALUES ('xx', 200, 'psw', null, '2009-02-23 16:48:11.156')
16:48:11,171 DEBUG CrudDao:66 - SELECT NAME, ID, PASSWORD, SEX, BIRTH_DATE_TIME FROM ONE WHERE ID = 200
16:48:11,203 DEBUG CrudDao:124 - NAME,ID,PASSWORD,SEX,BIRTH_DATE_TIME
16:48:11,203 DEBUG CrudDao:128 - xx,200,psw,null,2009-02-23 16:48:11.156








Responses to “Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao”