0% found this document useful (0 votes)
565 views

Hibernate-Generic-Dao: Genericdaoexamples

The document discusses examples of using a GenericDAO framework with Hibernate. It shows how to create a DAO interface and implementation class for a Project domain object by extending GenericDAO classes. The implementation can customize methods by adding or overriding queries. A more complex test example is provided in a linked test file. Comments from users ask about externalizing HQL queries using naming strategies and note a typo in the Criteria code sample.

Uploaded by

orangota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
565 views

Hibernate-Generic-Dao: Genericdaoexamples

The document discusses examples of using a GenericDAO framework with Hibernate. It shows how to create a DAO interface and implementation class for a Project domain object by extending GenericDAO classes. The implementation can customize methods by adding or overriding queries. A more complex test example is provided in a linked test file. Comments from users ask about externalizing HQL queries using naming strategies and note a typo in the Criteria code sample.

Uploaded by

orangota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

17/09/13

GenericDAOExamples - hibernate-generic-dao - Examples of using GenericDAO - Generic DAO implementation: extendable, detailed search, remote
My favorites | Sign in

hibernate-generic-dao
Generic DAO implementation: extendable, detailed search, remote service interface Project Home Search Downloads Wiki for Issues Source Search Current pages

Search projects

GenericDAOExamples
Examples of using GenericDAO
Updated Feb 26, 2011 by dwolvert

Here is all the code it usually takes to create a DAO interface and implementation for a P r o j e c tdomain object; all the content is inherited from the superclass:
p u b l i ci n t e r f a c eP r o j e c t D A Oe x t e n d sG e n e r i c D A O < P r o j e c t ,L o n g >{ } p u b l i cc l a s sP r o j e c t D A O I m p le x t e n d sG e n e r i c D A O I m p l < P r o j e c t ,L o n g >i m p l e m e n t sP r o j e c t D A O{ }

This could be customized by adding and/or overriding methods if needed:


p u b l i ci n t e r f a c eP r o j e c t D A Oe x t e n d sG e n e r i c D A O < P r o j e c t ,L o n g >{ p u b l i cP r o j e c tf i n d B y N a m e ( S t r i n gn a m e ) ; p u b l i cP r o j e c tf i n d B y S t a t u s ( S t r i n gs t a t u s ) ; } p u b l i cc l a s sP r o j e c t D A O I m p le x t e n d sG e n e r i c D A O I m p l < P r o j e c t ,L o n g >i m p l e m e n t sP r o j e c t D A O{ / / b a s i ca d d e dm e t h o d p u b l i cP r o j e c tf i n d B y N a m e ( S t r i n gn a m e ){ C r i t e r i ac r i tg e t S e s s i o n ( ) . c r e a t e C r i t e r i a ( P r o j e c t . c l a s s ) ; c r i t . a d d ( R e s t r i c t i o n s . e q ( " n a m e " ,n a m e ) ) ; r e t u r n( P r o j e c t )c r i t . u n i q u e R e s u l t ( ) ; } / / b a s i ca d d e dm e t h o du s i n gs e a r c h p u b l i cL i s t < P r o j e c t >s e a r c h B y S t a t u s ( S t r i n gs t a t u s ){ r e t u r ns e a r c h ( n e wS e a r c h ( ) . a d d F i l t e r E q u a l ( " s t a t u s " ,s t a t u s ) ) ; } / / o v e r r i d i n gam e t h o d @ O v e r r i d e p u b l i cv o i ds a v e ( P r o j e c tp r o j e c t ){ i f( p r o j e c t . g e t I d ( )= =n u l l ) p r o j e c t . s e t S t a t u s ( " N E W " ) ; s u p e r . s a v e ( p r o j e c t ) ; } }

A more complex example can be found in the test code at: http://code.google.com/p/hibernate-generic-dao/source/browse/tags/1.0.0/daohibernate/src/test/java/test/googlecode/genericdao/dao/hibernate/dao/ProjectDAOImpl.java

Comment by [email protected], Jul 14, 2011 Is it possible to use naming strategies to externalize the hql queries. Are there any examples of that? Comment by project member dwolvert, Jul 15, 2011 The framework doesn't provide anything for that. Of course you can always add whatever custom methods you want to your DAO and use any and all Hibernate features. Comment by [email protected], Sep 12, 2012 The Criteria crit getSesion().createCriteria(Project.class); is incorrect

Sign in to add a comment

Terms - Privacy - Project Hosting Help Powered by Google Project Hosting

https://code.google.com/p/hibernate-generic-dao/wiki/GenericDAOExamples

1/1

You might also like