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
10
votes
3 answers

Should method in data access object (DAO) throw or catch its exception?

I have a Java method in data access object. This very simple method inserts two integer values into database. public void saveHourMin(int hour, int min) throws SQLException{ psInsert.setInt(1, hour); psInsert.setInt(2,…
jnemecz
  • 3,171
  • 8
  • 41
  • 77
10
votes
2 answers

where to handle spring DataAccessException

I develop an application using Struts, Spring, and Hibernate. My DAOs uses spring jdbc and all its method throws DataAccessException(that is uncheked). Where should I handle this exceptions? I know it's an unchecked exception but I think I need to…
rohit
  • 602
  • 4
  • 11
  • 24
9
votes
3 answers

What is the right way to use spring MVC with Hibernate in DAO, service layer architecture

I am using Spring MVC with Hibernatedaosupport for my DAO classes. Confused here where to start the transaction, whether it should be in service layer or DAO layer? My view interacts with Service layer. DAO's are injected into services. What is the…
Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90
9
votes
2 answers

JPA confusion (managed vs non-managed entities)

I'm working on a web project, trying to understand the best way to do this sort of thing over and over again: Read object A from the DB Later on, read another object (B) Make changes to A and B in the DB (as part of a transaction - write all the…
Ivan Maeder
  • 321
  • 3
  • 11
9
votes
2 answers

How to use suspend modifier in Room Dao after kotlin upgrade to 1.6.0?

Upgrading kotlin to 1.6.0 causes Room Dao suspend modifier to break build project with error: "Not sure how to handle query method's return type........". Are there(here) any solutions other than a workaround for running Dao functions…
Vsevolod
  • 332
  • 4
  • 10
9
votes
2 answers

How to insert "Entire" DAO recordset into a table with VBA

I have a DAO recordset that gets created fine and I can transfer the records from the set to a table, this is done row by row and works well but I am transfering a large amount of data at once so this can take a very long time row by row. Is there a…
Steven Whelan
  • 128
  • 1
  • 1
  • 5
9
votes
2 answers

dao pattern and relations

I'm working with DAO pattern in PHP. I understand the benefits that you get from separating your model this way, but what I don't understand is how are you supposed to build DAOs and VOs when your tables are related through associative entity I'll…
luigi7up
  • 5,779
  • 2
  • 48
  • 58
9
votes
4 answers

Is DAO pattern obsolete in Scala?

Let's consider a simple example of DAO pattern. Let Person is a value object and PersonDAO is the correspondent trait, which provides methods to store/retrieve Person to/from the database.trait PersonDAO { def create(p:Person) def find(id:Int) …
Michael
  • 10,185
  • 12
  • 59
  • 110
9
votes
1 answer

Spring Pageable sorting is exposing internal naming of dao

I am building rest microservices build with Spring and Spring Repositories. I want to give the client control of paging and sorting (using spring-data-rest). public PagedResources find( @PageableDefault(page = 0, size = 50) final…
9
votes
2 answers

Should DAO's validate the input

since DAO layer is typically responsible for accessing data from DB given certain input (like a user_id etc), should it concern itself with checking the validity of its input? E.g. if there's a DAO method to fetch a user based on user_uid, which is…
shrini1000
  • 7,038
  • 12
  • 59
  • 99
9
votes
7 answers

Model validation in PHP that requires interaction with the database

Let's say I have this model. (I made it very simple for demonstration purposes.) class User { public $id; public $email; public $password; public $errors = []; public function isValid() { if (strpos($this->email,…
Mikey
  • 6,728
  • 4
  • 22
  • 45
9
votes
7 answers

DAO methods and synchronized

The following are methods I currently have in an Abstract DAO class. If there are concurrent calls, are they safe as they are or should synchronization be used? I know synchronization should be used if there is a reference to an attribute outside…
James P.
  • 19,313
  • 27
  • 97
  • 155
9
votes
2 answers

call service vs dao from another service

I have User And Role entities and Service, DAO layers for them. I need Role list from UserService. Which layer should I use from UserService? Call list method of RoleService vs RoleDAO? Which one is common use and why?
Erlan
  • 2,010
  • 1
  • 22
  • 31
9
votes
2 answers

CurrentDb.RecordsAffected returns 0. Why?

If I use RecordsAffected with CurrentDb.Execute, it always returns 0. If I first make a instance of a Database object it works properly. Why? Like this: Dim Db As Database Set Db = CurrentDb Db.Execute "DELETE * FROM [Samples] WHERE Sample=5" If…
waanders
  • 8,907
  • 22
  • 70
  • 102
9
votes
5 answers

Spring MVC: Generic DAO and Service classes

I am writting web in Spring MVC. I wrote all DAOs using Generic DAO. Now I would like to rewrite my Service classes. How can I write "Generic Service"? There are my DAOs: /* ################################# DAO ################################…
martin
  • 1,707
  • 6
  • 34
  • 62