2 Replies Latest reply on Jan 21, 2010 7:34 AM by pravu Mi

    what's a DAO

    amira manai Newbie


      I'm reading about DAO so after a long reaserch ,i think that  DAO is a session bean ,it is represented  by the class wich implements the interface .

      interface= contain all method that we can apply it to an Entity bean

      class=implements this interface and instanciates the Entity manager , and apply the method to relationnal tables

      is it right!!




      package comet;

      import java.util.List;
      import javax.ejb.Remote;

      public interface ClientTestBeanRemote {
      public void addClient(Client var);
      public Client rechercherClient(int var);
      public void deleteClient(int var);
      public List<Client> listerTousLesClient();
      public Client updateClient(Client var1, Client var2);


      the class:DAO

      package comet;

      import java.util.List;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      public class ClientTestBean implements ClientTestBeanRemote {

      private EntityManager em; //L'Entity Manager

      public void addClient(Client var) {

      public Client rechercherClient(int var) {
        return em.find(Client.class, var);

      public void deleteClient(int var) {
        Client resReq = rechercherClient(var);
        if (resReq != null) {

      public List<Client> listerTousLesClient() {
        return em.createQuery("SELECT e FROM Client  e").getResultList();

      public Client updateClient(Client var1, Client var2) {
        Client var = em.find(Client.class, var1.getId());
        if (var != null) {





        return var;


      Is it right ,or not !!


        • 1. Re: what's a DAO
          Youssef El Maroufy Newbie

          DAO is not necessarily a session bean, it may be a simple spring bean for example.
          for the method updateClient, I do not think it will update the client :


          public Client updateClient(Client client) {

               Client updatedClient = em.merge(client);

               return updatedClient;



          regarding deleteClient, it can be implemented like this :


          public void deleteClient(Client client) {

          • 2. Re: what's a DAO
            pravu Mi Newbie

            DAO(Data Access Object) is a design patteren and you may get more information about it from internet.


            It may have any kind of implementation by using plain JDBC, hibernate, entity bean , spring-hibernate or any kind of data access API currently available or comming in future.


            Thanks and Regards,