dao

Hibernate Tools - DAO generation

独自空忆成欢 提交于 2019-12-08 05:44:30
问题 I am using the eclipse hibernate tools plug-in to reverse engineer my database. I spent my whole day looking for how to force the DAO generator to use HQL/Criteria with the session factory, transaction, etc. Right now, if I have the table TABLE in my database, I obtain the DAO class TableHome. This class uses the persistence EntityManager. I found tutorials using an older version of hibernate tools generating TableDAO instead, and this is what I exactly need. Thank you very much. 回答1: Whether

BeetlSQL ,更好的Dao工具

烂漫一生 提交于 2019-12-07 21:48:34
beetlsql 入门 同时具有Hibernate 优点 & Mybatis优点功能,适用于承认以SQL为中心,同时又需求工具能自动能生成大量常用的SQL的应用。 SQL 以更简洁的方式,Markdown方式集中管理,同时方便程序开发和数据库SQL调试 数据模型支持Pojo,也支持Map/List这种无模型的模型 SQL 模板基于Beetl实现,更容易写和调试,以及扩展 无需注解,自动生成大量内置SQL,轻易完成增删改查功能 简单支持关系映射而不引入复杂的OR Mapping概念和技术。 支持跨数据库平台,开发者所需工作减少到最小 具备Interceptor功能,可以调试,性能诊断SQL,以及扩展其他功能 内置支持主从数据库,通过扩展,可以支持更复杂的分库分表逻辑 代码例子 // 执行/user.md 里的select sql List<User> list = SqlManager.select(“user.select”,paras,User.class); // 使用内置的生成的sql执行 User user = SqlManage.selectById.unque(User.class,id); SQL例子 selectUser === select * from user where 1=1 @if(user.age==1){ and age = #user.age# @

mybatis02映射&动态sql&关联查询&spring整合mybatis

∥☆過路亽.° 提交于 2019-12-07 19:03:11
输入映射和输出映射: 动态sql: 关联查询_一对一: 关联查询_一对多: 一对一,一对多操作的区别: 一对一,resultMap里面关联另一个实体时用 association 一对多,resultMap里面关联另一个实体时用 collection 相同: 只用一方维护表关系即可。 传统dao开发spring整合: mapper代理形式开发dao: 只要使用接口,就必须满足四个条件: * 1、映射文件namespace必须是接口全类路径名 * 2、映射文件Statement的id必须和接口方法名相同 * 3、接口和映射文件必须在同一个目录,且名称相同 * 4、输入参数类型必须和parameterType参数类型一致 * 5、输出参数ResultType必须和接口方法返回值类型一致* 如果sqlMapConfig.xml中引入外部映射文件使用 <mappers> <mapper resource="sqlMap/user.xml"/> </mappers> 则是上面的4个条件,去掉条件3 如果直接写接口,就必须满足上面所有条件。 <mapper class="cn.itcast.dao.IUserDao"/> <package name="cn.itcast.dao"/> 相关代码链接: https://github.com/lqingfang/mybatis 来源: oschina

maven多模块工程打包部署

非 Y 不嫁゛ 提交于 2019-12-07 14:25:26
一般maven多模块工程结构如下图, 图中分为dao数据层和上层web层(当然还可以有service层),在进行多模块划分的时候,一般将dao层采用jar进行打包,web层进行war打包。在进行war包部署时,发现dao是以jar包形式存在于lib包目录下,如果在部署服务器上需要进行相关配置修改会比较麻烦。因此研究了下用maven进行合并打包的方法: 1.确保dao pom.xml中有以下配置 <resources> <resource> <directory> ${basedir}/src/main/java </directory> <includes> <include> **/*.xml </include> <include> **/*.properties </include> </includes> </resource> <resource> <directory> ${basedir}/src/main/resources </directory> </resource> </resources> 2.在dao目录下执行:mvn clean install -Dmaven.test.skip=true,以生成jar包 3.在web工程pom.xml添加以下插件配置 <plugin> <groupId> org.apache.maven.plugins <

Hibernate Update Query issue

让人想犯罪 __ 提交于 2019-12-07 12:58:05
问题 For this update query update TestDB.dbo.MyEmp set empname=? where empid=? I wrote in my DAO class MyEmployee myEmployee = new MyEmployee(); MyEmployee myEmployee =(MyEmployee )session.load(MyEmployee.class, new Integer(1700)); myEmployee.setName("updatedName"); session.update(myEmployee ); Its working fine, but I need to know for this type of update query mentioned in below update TestDB.dbo.MyEmp set empsalary=? where empid=? && empname = ? (i.e., I need to update the table by using two

YII访问数据库(Yii Dao)

一世执手 提交于 2019-12-07 11:04:04
CDbConnection: 一个抽象数据库连接 CDbCommand: SQL statement CDbDataReader: 匹配结果集的一行记录 CDbTransaction:数据库事务 访问数据库前需要建立数据库连接;使用DAO建立一个抽象数据库链接: $connection = new CDbConnection($dsn, $username, $password); $connection->active = true; // 只有激活了连接才可以使用 // 想要关闭连接,可以这样: $connection->active = false; CDbConnection继承自CApplicationComponent,所以他可以像组件一样在任何地方使用。因此可以这样访问: Yii::app()->db //执行SQL语句需要CDbCommand对象,而该对象由CdbConnection::createCommand()返回,因此: $connection=Yii::app()->db; $command=$connection->createCommand($sql); // 如果SQL语句想要完全有自己写,可以这样: $newSQL = '写下你令人惊讶的SQL语句'; $command->text=$newSQL; //

Spring DaoSupport and @PersistanceContext EntityManager?

懵懂的女人 提交于 2019-12-07 10:13:39
问题 One of the most difficult things about understand Spring is that Spring supports multiple approaches to the same problem. So in my application I using injected EntityManager using the @PersistanceContext annotation, for example: @Repository public class JpaDao extends JpaDaoSupport implements Dao { @PersistenceContext(unitName = "PersistanceUnit", type = PersistenceContextType.EXTENDED) private EntityManager em; Is this approach compatible with extending JpaDaoSupport (which requires

昨天用一天的时间重复制造了一个轮子,又一个OR mapping。

我与影子孤独终老i 提交于 2019-12-07 07:45:19
又一个使用annotation的orm的实现,非常无聊的东西。 不过实现过程中,思考了一下,感觉从select出发的orm往往是非常难用的。再简单的系统,其select语句也会出现复杂的内外连接,分组等查询逻辑。 但是在数据存储部分,也就是upate ,insert,delete部分,逻辑往往是非常简单的,使用orm会得到比较好的效果。 然后,要反思一下DAO模式,在通常理解的DAO模式中,数据的读取和写入是放在同一个DAO类当中的,在实际开发中,select相关的findXXX方法好getXXXX方法非常多,但是update,insert,add,save等方法个数都比较少,个人认为开发DAO或者说数据访问层程序的时候,应该讲DAO分为写入DAO和读取DAO,同时可以考虑在此实现读写分离,写入一个库,读取多个库,读加缓冲池,写直接写入,利用数据库机制表同步,以提高系统的伸缩性。 而且根据@1哥的答案,写入操作本身就是一个非常慢的动作,在写入时加入反射,犹如大象身上的虱子,相对磁盘来说,反射的消耗应该可以忽略。 然后,顺便对于NutzDAO进行一下小小的批评,作为DAO中间件,有些事情做了太多,反而不太好,比如引入所谓的whereClause的条件查询,真实业务中的select的SQL非常复杂,用简单的条件封装,很难满足真实开发需要的。 要知道hibernate一开始也很好用

Is there any good generic JPA DAO implemenation?

被刻印的时光 ゝ 提交于 2019-12-07 04:38:15
问题 According this article, generic JPA DAO(Data Access Object) is a pretty nice pattern. Is there any good implementation? 回答1: You could take a look into the Spring Data JPA. A few new concepts were introduced into Spring Data JPA, for instance the Query creation based on the method name, so you can declare a method like findById(String id) and the "generic" implementation will interpret the method's name and execute something like select Entity from Entity where id = 'given string' Methods

nutz,今晚来一发(18): nutz有数据库表生成bean的工具或方法不?

非 Y 不嫁゛ 提交于 2019-12-07 02:35:18
--------------------------很长很长的分割线------------------ 与quartz的集成, 就是JobFactory的替换,以实现Job类的ioc注入. 直接用类: https://github.com/nutzam/nutzmore/blob/master/src/org/nutz/integration/quartz/NutQuartzJobFactory.java 第二种, 在Setup接口实现类的init方法中, 通过NutConfig实例获取ioc容器,然后取出job所需要的bean 第3种, 通过Mvcs.ctx.getDefaultIoc()来获取 -- 不建议. 来源: oschina 链接: https://my.oschina.net/u/61077/blog/372120