hibernate-generic-dao

GenericDAO 本GenericDAO由我本人开发出来的,欢迎大家前来下载使用... 立即下载

原文地址: http://code.google.com/p/hibernate-generic-dao/


Hibernate Generic D.A.O. Framework

The motivation behind the framework

We had worked on a project where we hand-coded all of our DAOs. This produced four irksome difficulties: (1) Method names and implementations were not altogether consistent. (2) It was a pain to make additional columns sortable or filterable, and as a result, a lot of pages lacked good sorting and filtering. (3) Making additional DAOs was tedious and took a fair amount of time. (4) Writing tests for DAOs is tricky and tedious, so no one really did.

This framework aims to ease our troubles.

Why might you consider looking into this framework?

  • Generic DAO: With the sweetness of Java generics, the concept of generic DAOs is not new, and it’s not difficult. However, we’ve put a lot of work into making these easy to use and robust. So if you like the way we’ve done it, then this framework provides ready-made code for you. On the other hand if you’d rather make your own, then simply feel free to look at our source code for ideas and help on a few potentially tricky issues.
  • Search: Search is the most original and sophisticated part of this framework, and it can be used with or without the generic DAO portion of the framework. The search capability is designed around the use-case of a list page with sorting, filtering, column selection and paging. However, its use is certainly not limited to that. The value that the search adds is simpler, more robust querying with less coding and less testing. It is similar to Hibernate Criteria, but it is simpler to use and can easily move across layers of an application including view and even remote layers. Plus is works with both Hibernate and JPA*.
  • Remote DAO (for R.I.A.s?): If you you’re like us, you don’t want to write and configure an individual DAO style remote service for each entity in a R.I.A. or other client-heavy application. This framework may have the solution. We provide utilities and sample code to adapt our single general DAO to any remoting technology interface. Just configure this single remote access point and the client can do any basic CRUD or search operation on any entity. Again, if you don’t like our way of doing things, maybe you can at least get some ideas from our source code.
  • Remote Search (for R.I.A.s?): As mentioned above, the framework can provide a single point for client-server CRUD and search operations. The framework’s search is meant to be able to cross the client-server boundary. So lists and searches in the client application can take advantage of the same easy-to-use features and consistency that the search functionality provides in the server tier or single tier application. This consistency allowed us to create a reusable collection type in Adobe Flex 3 that is associated with a single search object and automatically updates itself from the server according to the search parameters.**

*A fairly simple adapter is required for each JPA provider. Right now we only have an adapter for Hibernate Entity Manager. If anyone would like to contribute an adapter for any other JPA provider (OpenJPA, TopLink, etc.), that would be great.

**If time permits, we would like to eventually post our corresponding Adobe Flex 3 framework and utilities.

More Information

Wiki Documentation: UserGuide

Javadoc: http://hibernate-generic-dao.googlecode.com/svn/trunk/docs/api/index.html

Blog: http://hibernategenericdao.wordpress.com/

Questions and Comments

Please post at http://groups.google.com/group/java-generic-dao.

Code Examples

Creating DAOs for individual model classes:

Simply extend the GenericDAO class with the specific type.

public interface ProjectDAO extends GenericDAO<Project, Long> {

}

public class ProjectDAOImpl extends GenericDAOImpl<Project, Long> implements ProjectDAO {

}

The following methods (and several more) are now available on ProjectDAO

Project project = projectDAO.find(projectId);

List<Project> list = projectDAO.findAll();

projectDAO.save(project);

projectDAO.remove(project);

projectDAO.removeById(project.getId());


Search search = new Search();
search.addFilterEqual("name", "hibernate-generic-dao");

List<Project> list = projectDAO.search(search);

int count = projectDAO.count(search);

SearchResult<Project> result = projectDAO.searchAndCount(search);
list = result.getResult();
count = result.getTotalCount();

search.clear();
search.addField("rating", Field.OP_AVG);
int avgProjectRating = (Integer) prjoectDAO.searchUnique(search);

A GeneralDAO is also provided with DAO methods for any entity:

public interface GeneralDAO {

        public <T> T find(Class<T> type, Serializable id);

        public <T> T[] find(Class<T> type, Serializable... ids);

        public <T> T getReference(Class<T> type, Serializable id);

        public <T> T[] getReferences(Class<T> type, Serializable... ids);

        public boolean save(Object entity);

        public boolean[] save(Object... entities);

        public boolean remove(Object entity);

        public void remove(Object... entities);

        public boolean removeById(Class<?> type, Serializable id);

        public void removeByIds(Class<?> type, Serializable... ids);

        public <T> List<T> findAll(Class<T> type);

        public List search(ISearch search);

        public Object searchUnique(ISearch search);

        public int count(ISearch search);

        public SearchResult searchAndCount(ISearch search);

        public boolean isAttached(Object entity);

        public void refresh(Object... entities);

        public void flush();

        public Filter getFilterFromExample(Object example);

        public Filter getFilterFromExample(Object example, ExampleOptions options);
}

Search DTO usage examples

Search search = new Search(Project.class);

//filtering
search.addFilterEqual("name", "hibernate-generic-dao");

search.addFilterLessThan("completionDate", new Date());

search.addFilterOr(
    Filter.equal("name", "Jack"),
    Filter.and(
        Filter.equal("name", "Jill"),
        Filter.like("location", "%Chicago%"),
        Filter.greaterThan("age", 5)
    )
);

search.addFilterIn("name", "Jack", "Jill", "Bob");

search.addFilterNot(Filter.in("name","Jack", "Jill", "Bob"));

//sorting
search.addSort("name");
search.addSort("age", true); //descending

//projection
search.addField("name");
search.addField("location");

//or with column operators
search.addField("rating", Field.OP_AVG);
search.addField("developerCount", Field.OP_MAX);

//paging
search.setMaxResults(15); //a.k.a. results per page
search.setPage(3);

//controlling eager fetching of relationships
serach.addFetch("owner");

Nested properties are also fully supported...

search.addFilterEqual("status.name", "active");
search.addFilterGreaterThan("workgroup.manager.salary", 75000.00);

search.addSort("status.name");

HibernateGenericDAO框架资料 HibernateGenericDAO是一款googlecode上的开源持久层框架,基于Hibernate。 本人偶然找到该框架,研究发现对于快速开发Hibernate的持久层程序非常有帮助,因此下载研究并写了一个Maven的示例工程和一篇快速入门攻略供大家学习交流。 立即下载

相关推荐

可以用来被继承的用Hibernate连接数据库的GenericDAO类(转)

方便你使用的abstract类,继承起来非常方便

Hibernate Generic DAO的介绍安装和使用

  这个项目以Maven的形式发行,所以你可以以Mave依赖的方式下载这个框架。另外,这些JAR文件也可以从Maven仓库中下载。 1、介绍: Hibernate Generic DAO框架可以和原始的Hibernate框架一起使用,也可以和Hibernate JPA实现一起使用。当然,理论上,它也可以和其他的JPA实现如OpenJPA或TopLink通过一些额外的配置一起使用。   2...

ccgkren的专栏 714

Hibernate封装dao层

Hibernate封装dao层

com.googlecode.genericdao

com.googlecode.genericdao使用

nrdjaoaoeijagj的博客 1219

GitHub漏洞挖掘与CVE提交实战指南:从发现到编号的完整链路

GitHub开源项目是现代软件供应链的核心节点,其安全漏洞直接影响全球数百万系统的机密性、完整性与可用性。理解漏洞本质需回归CIA三元组原理,而真实可利用性依赖对协议解析层、配置加载区和依赖传递链等高危模块的精准识别。技术价值在于将模糊的‘可疑逻辑’转化为符合MITRE CVE标准的可验证事件,支撑SDL流程、威胁情报建设与供应链风险管理。典型应用场景包括甲方安全工程师推动供应商修复、独立研究者参与负责任披露,以及DevSecOps团队构建自动化风险坐标系。本文基于27次CVE提交经验,聚焦GitHub代码

weixin_33646989的博客 652

潜行游戏设计:核心机制与关卡设计解析

潜行游戏作为动作游戏的重要分支,通过视觉遮蔽、声音传播和AI行为树等复杂系统,为玩家提供独特的策略体验。视觉隐蔽系统采用视野锥和光照值的双重判定,声学传播模型模拟距离衰减和材质穿透,而敌人AI行为树则包含巡逻、警戒和团队协作等状态节点。这些技术不仅提升了游戏的真实感和挑战性,还在《合金装备》《刺客信条》等经典作品中得到广泛应用。潜行游戏的关卡设计强调多路径拓扑结构和环境叙事元素,通过沙漏模型和动态难度调节,平衡自由度和开发成本。未来,基于ML的适应性AI和物理模拟的隐蔽系统将成为创新方向。

weixin_42497762的博客 182

hibernate-generic-dao介绍

hibernate-generic-dao 地址:http://code.google.com/p/hibernate-generic-dao/

王星乐的博客 1542

群晖Hyper Backup还原实战:加密与非加密备份的完整操作指南

本文详细介绍了群晖Hyper Backup在加密与非加密备份场景下的完整还原操作指南。通过实战案例和高级技巧,帮助用户应对硬盘故障或系统崩溃时的数据恢复挑战,特别是加密备份恢复中的关键节点和常见陷阱。

weixin_29323365的博客 443

[Hibernate] - Generic Dao

使用泛型写了一个通用的Hibernate DAO类。 GenericDao接口 package com.my.dao; import java.io.Serializable; import java.util.List; /** * Generic DAO interface * @author Robin * * @param <...

aili2460的博客 242

基于Simulink的H∞鲁棒控制器设计与仿真建模示例

本文介绍了基于Simulink的H∞鲁棒控制器设计与仿真方法。针对质量-弹簧-阻尼系统存在±50%刚度不确定性的问题,详细阐述了从构建广义被控对象、设计性能加权函数,到使用hinfsyn综合控制器的完整流程。通过Simulink仿真验证,所设计的H∞控制器在参数摄动和外部扰动下均保持良好性能,位移控制误差小于2%,扰动衰减超过20dB。相比传统PID控制,H∞方法展现出显著鲁棒性优势。文章还总结了工程实践中的加权函数调参技巧、控制器降阶方法,并展望了μ-综合等扩展方向,为处理系统不确定性提供了实用解决方案。

amy_mhd的博客 70

Windows 11 安装 Maven:下载、安装、配置国内镜像、验证

本文详细介绍了在 Windows 11 系统中安装与配置 Apache Maven 的完整流程,包括 JDK 环境准备、Maven 下载解压、本地仓库路径设置、阿里云国内镜像加速配置、环境变量设置及安装验证。同时提供了常用 Maven 命令速查表,帮助开发者快速上手依赖管理与项目构建,提升开发效率。

寒水馨 · 轻量级技术文档 · hanshuixin.org 1506

Spring与Hibernate Annotation的实现

最近实现了Spring2.0  Hibernate3.2     Hibernate Annotation 3.3   GenericDao 整合实现 用起来还是很顺手的 代码给出如下 java 代码 package cn.feigme.model;          /**    * @author Feigme     *   ...

feigme H.Guo的专栏 188

Android Framework AudioFlinge 面试题及参考答案

请解释什么是 AudioFlinger? AudioFlinger 是 Android 音频系统中的一个关键服务。它位于 Android 系统的中间层,是连接上层应用和底层音频硬件驱动的重要桥梁。从功能角度来讲,它主要负责音频数据的混合(Mix)以及输出(Output)。 当多个应用程序同时播放音频时,比如一个音乐播放器在播放歌曲,同时手机的闹铃响起,AudioFlinger 就会发挥它的混合功能。它会把这些不同来源的音频数据按照一定的规则和算法混合在一起。这种混合并不是简单的相加,而是要考

大模型大数据攻城狮的专栏 1577

Spring3.2.6 + hibernate4.2.8 + hibernate-generic-dao1.2.0

n多方法都不成功,最后在hibernate-generic-dao官网上的例子hibernate-maven-web(使用其jar包及配置,并将hibernate更新为4.2.8,加入ehcache及c3p0数据库连接池) 由于hibernate-generic-dao1.2.0只支持JPA2.0,而hibernate4.3.0开始支持JPA2.1,故选择hibernate4.2.8版本。 而...

weixin_34297704的博客 103

把 ABAP 接到外部世界的几条路, 从 Web Service 到 RFC、BAPI 与 IDoc 的完整理解

摘要: ABAP 的连接能力是其长期成为企业核心的关键,不仅支持通用协议(HTTP、SOAP、XML),还保留了 SAP 特有的技术(RFC、BAPI、IDoc)。Web Service 是跨系统通信的主轴,依赖 SOAP/WSDL 实现契约化协作,而 Enterprise Service 更强调业务语义的复用与治理。经典技术如 RFC 和 BAPI 因高效稳定仍广泛使用,尤其适合紧耦合场景。ABAP 通过分层工具箱(如代理生成、服务注册)实现灵活集成,平衡新旧技术,满足多样化的企业连接需求。 (字数:15

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 140

RIP协议

一、 Rip简介 早期在unix系统上使用,1988年才发布第一个rip协议标准“RFC1058”,是一种距离矢量(Distance-vector)协议。 1. 特点: 只关心跳数,下一跳,不关心整网拓扑。 基于传闻的路由协议。 2. 场景: 适用于规模小且可靠性要求低的网络环境,部署简单,因为其跳数限制,不适用于大型网络。 3. 工作原理: - 开启RIP发送RIP请求 - 接受请求发出响应...

ledrsnet的博客 8608

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

基于struts2.23 + spring2.5.6 + hibernate3.6.4 + hibernate-generic-dao1.0

来自:[quote]http://www.oschina.net/code/snippet_147955_5079[/quote] 这是我为新项目专门搭建的基于全注解方式的SSH基础框架,虽然是老掉牙的的东西,自我感觉很良好,好东西不敢独享,晒晒等拍砖。 概述:基于struts2.23 + spring2.5.6 + hibernate3.6.4 + hibernate-generic-d...

joe_zhjiang的专栏 150

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

通用DAO和DaoImpl

 public interface GenericDao { void create(T entity); void delete(T entity); void update(T entity);  T findById(Serializable oid); List findAll(); PageModel findByPager(int pageNo, int

java 6920

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

基于全注解方式的SSH基础框架

概述:基于struts2.23 + spring2.5.6 + hibernate3.6.4 + hibernate-generic-dao1.0(除了spring,我整合的都是最新的GA包,hibernate-generic-dao是google项目库中一个开源的basedao,我灰常喜欢,因为我找不到更好更适合我的)   项目代码是基于eclipse3.6创建的,很简单,大家直接导

fygkchina的专栏 584

一个泛型Hibernate DAO实现

自己四处参考,写写抄抄折腾出来的一个泛型Hibernate DAO,用了Spring的HibernateDaoSupport。提供基本的CRUD操作,支持分页查询,可使用HQL、Criteria和DetachedCriteria。 废话不说了,上代码package sgf4web.dao;import java.io.Serializable;import java.util.*;impo

DigitalSonic的自留地 5107

学习Hibernate常用的BaseDao

package org.accp.house.dao.hbimpl; import java.io.Serializable; import java.util.List; import org.accp.house.dao.ICommonDao; import org.

1883
上一篇: 优快云博客,截图上传不了
下一篇: 基于全注解方式的SSH框架
Java_lab
博客等级 码龄14年 4粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值