Questions tagged [dao]

A Data Access Object (DAO), is a design pattern in object-oriented software design, creating an object that provides an abstract interface to some type of database or other persistence mechanism.

A data access object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer.

Source: Wikipedia (retrieved version)

More details: - Core J2EE Patterns - Data Access Object

2621 questions
45
votes
3 answers

DAO, Repositories and Services in DDD

After reading several articles, I am starting to understand the difference between DAO and Repositories, but I find myself in trouble trying to understand the difference between Repositories and Services. For putting in short terms, in the OO…
Victor
  • 3,841
  • 2
  • 37
  • 63
43
votes
3 answers

Android Room transactions across DAOs

The official documentation states that: It is recommended to have multiple Dao classes in your codebase depending on the tables they touch. and that one can mark a method with the Transaction annotation like that: @Dao public abstract class…
Alessandro
  • 3,666
  • 2
  • 28
  • 41
42
votes
3 answers

I found JPA, or alike, don't encourage DAO pattern

I found JPA, or alike, don't encourage DAO pattern. I don't know, but I feel like that, especially with server managed JTA managers. After adequate hands-on using DAO pattern, I started designing JPA based application around that pattern. But it…
Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
41
votes
2 answers

JSF Controller, Service and DAO

I'm trying to get used to how JSF works with regards to accessing data (coming from a spring background) I'm creating a simple example that maintains a list of users, I have something like
PDStat
  • 5,513
  • 10
  • 51
  • 86
41
votes
3 answers

Hibernate or JPA or JDBC or?

I am developing a Java Desktop Application but have some confusions in choosing a technology for my persistence layer. Till now, I have been using JDBC for DB operations. Now, Recently I learnt Hibernate and JPA but still I am a novice on these…
Amit
  • 33,847
  • 91
  • 226
  • 299
40
votes
3 answers

Room DAO Order By ASC or DESC variable

I'm trying to make a @Query function in my @Dao interface which has a boolean parameter, isAsc to determine the order: @Query("SELECT * FROM Persons ORDER BY first_name (:isAsc ? ASC : DESC)") List getPersonsAlphabetically(boolean…
aLL
  • 1,596
  • 3
  • 17
  • 30
38
votes
2 answers

What is DAO factory pattern?

I am aware of factory and abstract factory methods, but I want to create a DAO factory pattern in Java. I want to know its importance. Its usage I have checked this link but it is difficult for me to understand. Can anyone explain it with the help…
coder25
  • 2,363
  • 12
  • 57
  • 104
38
votes
2 answers

Responsibilities and use of Service and DAO Layers

I am currently developing a web application using Struts2 with Spring plugin and hibernate and while I was looking at online examples I saw the use of Service and DAO layers now it came to me what are the real use of Service and data access object…
user962206
  • 15,637
  • 61
  • 177
  • 270
38
votes
4 answers

What is DAO and Service layer exactly in Spring framework?

What is DAO and Service layer exactly in Spring framework? I am looking for theoretical answer.
suraj.ratnaparkhi
  • 403
  • 1
  • 4
  • 8
37
votes
18 answers

"Type of the parameter must be a class annotated with @Entity" while creating Generic DAO interface in Room

I am using Room architecture component for persistence. I have created generic DAO interface to avoid boilerplate code. Room Pro Tips But my code doesn't compile saying "Error:(21, 19) error: Type of the parameter must be a class annotated with…
xrnd
  • 1,273
  • 3
  • 21
  • 38
37
votes
1 answer

ActiveRecord batch insert (yii2)

Is it possible to insert multiple rows in one query with Yii's ActiveRecord? Or is this only possible via the lower-level DAO objects? I have two models 1- Transaction 2-TransactionItems There are multiple rows(onclick add row) in transaction…
user1561346
  • 502
  • 3
  • 13
  • 28
36
votes
5 answers

Hibernate: CRUD Generic DAO

My web application has got a lot of service tables/entities, such as payment_methods, tax_codes, province_codes, etc. Each time I add a new entity, I have to write a DAO. The thing is that, basically, they are all the same, but the only difference…
Fabio B.
  • 9,138
  • 25
  • 105
  • 177
33
votes
5 answers

How to test DAO methods using Mockito?

I've started to discovered Mockito library and there is a question for which I didn't find the proper answer. If I have for example such method in my UserDAO class that saves user in database: public class UserDAO{ ... public void create(User user)…
marknorkin
  • 3,904
  • 10
  • 46
  • 82
33
votes
10 answers

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

Data Access Objects (DAOs) are a common design pattern, and recommended by Sun. But the earliest examples of Java DAOs interacted directly with relational databases -- they were, in essence, doing object-relational mapping (ORM). Nowadays, I see…
Todd Owen
  • 15,650
  • 7
  • 54
  • 52
30
votes
7 answers

JPA - FindByExample

Does anyone have a good example for how to do a findByExample in JPA that will work within a generic DAO via reflection for any entity type? I know I can do it via my provider (Hibernate), but I don't want to break with neutrality... Seems like…
Dave
  • 21,524
  • 28
  • 141
  • 221