What is Data access object (DAO) in Java

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage. That definition from: http://en.wikipedia.org/wiki/Data_access_object Check also the sequence diagram here: http://www.oracle.com/technetwork/java/dataaccessobject-138824.html Maybe a simple example can help you understand the concept: Let’s say we have an entity to represent an employee: public … Read more

Why put a DAO layer over a persistence layer (like JDO or Hibernate)

You make some points. But I nevertheless use a Dao layer, here’s why: Database accesses are calls to a remote system. In all such cases (also web-service, ajax etc…), the granularity of interaction need to be big enough. Many tiny calls would kill performance. This performance necessity requires often a different view of the system, … Read more

How to test DAO methods using Mockito?

Here is a good start using Mockito to test your UserDAO. This code uses a good amount of the Mockito features, so you can see how to use them. Let me know if you have questions. import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import … Read more

Hibernate: CRUD Generic DAO

here’s mine @Component public class Dao{ @Resource(name = “sessionFactory”) private SessionFactory sessionFactory; public <T> T save(final T o){ return (T) sessionFactory.getCurrentSession().save(o); } public void delete(final Object object){ sessionFactory.getCurrentSession().delete(object); } /***/ public <T> T get(final Class<T> type, final Long id){ return (T) sessionFactory.getCurrentSession().get(type, id); } /***/ public <T> T merge(final T o) { return (T) sessionFactory.getCurrentSession().merge(o); … Read more

What is DAO factory pattern?

DAO stands for “Data Access Object”. It’s an interface-based class that handles all your CRUD operations with a relational database for a particular object. Here’s an example that uses generics: package persistence; public interface GenericDao<K extends Serializable, T> { public T find(K id); public List<T> find(); public K save(T value); public void update(T value); public … Read more

What is DAO and Service layer exactly in Spring framework?

There is no distinction as far as Spring is concerned. By convention you can mark DAO classes with @Repository and services with @Service. Also the former does some persistence layer exception translation. Since you are asking theoretically: DAO should perform raw database operations and translate them to some higher level constructs (objects, collections). Services should … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)