-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Base DAO
PostPosted: Wed Nov 03, 2004 2:59 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
I am trying to build a BaseHibernateDAO. Looking at the caveatemptor example I wonder why no Base DAO was used? Do Hibernate guys dont like the idea? If yes any reason?

This is what I have come up with :

public interface BaseHibernateDAO {
public Serializable addObject( Object object ) throws InfrastructureException, DAOException;
public Serializable updateObject( Object object ) throws InfrastructureException, DAOException;
public void deleteObject( Object ) throws InfrastructureException, DAOException;
public Object retrieveObject( Class c, Long id ) throws InfrastructureException, DAOException;
public Collection findAll( Class c ) throws InfrastructureException, DAOException;
}


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2004 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No particular reason, there are many variations of the DAO pattern and all of them make more or less sense. Use what works best for you.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2004 3:41 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
can u identify other variations? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 6:19 pm 
Beginner
Beginner

Joined: Mon Sep 06, 2004 9:36 am
Posts: 35
ok i identify another variation. In it I define :
* a DAO fatory class
* a DAO interface
* a concrete class that implements the DAO interface
* data transfer objects

In this case for each Serializable class I have to define 3 classes. For example for MOVIE class, I have to define MovieDAOFactory, MovieDAO and MovieDAOImpl.

The variation I am using will need only one class MovieDAO which will be inherited from BaseHibernateDAOImpl.

what do you guys think?


Top
 Profile  
 
 Post subject: Base DAO library in Java 1.5
PostPosted: Sat Nov 20, 2004 8:43 am 
Newbie

Joined: Fri Oct 24, 2003 2:59 pm
Posts: 6
Location: Swalmen, The Netherlands
I've come up with the following DAO library, relying on Java 1.5 generics. Showing only the main interfaces.

// Default DAO
public abstract class DAO<E,K extends Serializable> {
public E findById(K key) throws HibernateException {}
protected void save(E entity) throws HibernateException {}

public void update(E entity) throws HibernateException {}

public void update(Iterable<E> entities) throws HibernateException {}

public void delete(E entity) throws HibernateException { }

protected E find(String queryName,Object... args)
throws HibernateException {}

public List<E> findAll() throws HibernateException {}

protected List<E> query(String name,Object... parameters)
throws HibernateException {}
}

// creates a per-thread DAORegistry
public interface DAOService {
DAORegistry getDAORegistry() throws HibernateException;
}

// Opens Hibernate Session when needed,
// Instantiates DAOs on demand (if not already in registry)
public interface DAORegistry {
<T> T getDAO(Class<T> daoClass) throws HibernateException;
void close() throws HibernateException;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.