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
11
votes
6 answers

Hibernate loses connection

I am using hibernate to connect my mysql database and perform transactions. I am using a single SessionFactory throughout the application and i don't have other connections to the database, yet, i am receiving the exception…
Buddy
  • 2,074
  • 1
  • 20
  • 30
11
votes
4 answers

Should the relationship between a Service and DAO be one to one or one to many?

The code that sparked this question was a Service in my company's code base that contained four different DAO's. I didn't think much of this until I saw that this Service had become conflated with methods that belonged in a completely different…
stevebot
  • 23,275
  • 29
  • 119
  • 181
11
votes
2 answers

Spring DAO Test Fails - says "requires JUnit 4.12 or higher"

I'm trying to write a DAO test using Spring. When I run the test, it errors out with the following stack trace below. I don't know why I am getting an error when I believe I am including the proper version of…
Scott Stella
  • 111
  • 1
  • 1
  • 5
11
votes
2 answers

DAO vs ORM - Concept explained in the context of Sequelize.js

I've been working with Sequelize.js recently and come across the term "DAO" pretty frequently. Coming from ActiveRecord (in Rails), the idea of an ORM seems pretty straight forward. Could someone explain to me what a DAO is? How does it differ…
The Dembinski
  • 1,469
  • 1
  • 15
  • 24
11
votes
1 answer

How to programmatically get transaction manager in a thread?

I have a wicket page , which contains two Spring-managed beans , one is DAO , another is Service Object : public class MergeAccountsPage extends WebPage { @SpringBean private MergeEmailDao mergeEmailDao; @SpringBean private MergingService…
smallufo
  • 11,516
  • 20
  • 73
  • 111
11
votes
4 answers

Spring-Hibernate DAO naming convention?

Is it typical to name DAOs in the following way: UserDAO - interface UserDAOImpl - implements UserDAO I am wondering if its standard to use the suffix 'Impl' for the implementation or if something more meaningful is the best practice. Thanks.
oym
  • 6,983
  • 16
  • 62
  • 88
11
votes
2 answers

New to Java - What's JPA and DAO?

I'm new to Java and i'm trying to make a web project with servlets. I'd like to query my database but I think I don't understand everything about JPA and DAO. I've been taught to do things this way : Create class com.package.entity.User (generated…
mimipc
  • 1,354
  • 2
  • 14
  • 28
10
votes
5 answers

DAO package structure

I'm writing some simple DAOs in Java using JDBC (no Spring, Hibernate or anything else). Is it better to put the implementation DAOs in the same package as their interfaces or to put them in a…
dhalsim2
  • 936
  • 2
  • 12
  • 35
10
votes
3 answers

LiveData observe() not called

My observer callback is not being called, can you point out what am I doing wrong ? My application is really simple since I'm just testing this architecture MainActivity code viewModel =…
Greggz
  • 1,873
  • 1
  • 12
  • 31
10
votes
2 answers

DAO pattern and the Open-Closed Principle

I've seen and worked with a lot of older, JDBC-based DAO code that usually start out with CRUD methods. My question relates specifically to the retrieval methods, or 'finders'. Typically what I find is that the DAOs start out with two…
user620884
10
votes
4 answers

Correct handling of return data

I have a question related to correct handling of returns of the DAO library I'm writing for one project. This library probably is going to be used by another people, and I want to do it correctly. How I should deal with return statements of the…
Serhiy
  • 4,073
  • 3
  • 36
  • 66
10
votes
1 answer

Checking if RoomDatabase is empty while using LiveData

I am trying to use RoomDatabase in my Android App. And I am using LiveData to be able to refresh my changes automatically inside my fragment. The first time I am running my app I am getting the data from the API, creating my RoomDatabase and storing…
yalematta
  • 1,389
  • 1
  • 21
  • 36
10
votes
2 answers

Should Kotlin's DAO return Optional or null?

Prior to Kotlin/JPA , I used to write my DAO layer like this : public interface UserDao extends JpaRepository { Optional findBySsn(String ssn); } And in the caller side , if I want to find someone or create user by SSN , I can…
smallufo
  • 11,516
  • 20
  • 73
  • 111
10
votes
4 answers

Junit test case for database insert method with DAO and web service

I am implementing a webservice based university management system. This system adds certain courses to database. here below is the code that I am using. Course.java public class Course { private String courseName; private String location; …
energycycle
  • 194
  • 1
  • 3
  • 9
10
votes
1 answer

How to avoid repeatig DAO methods in Service classes? @Transactional annotated DAO and Service classes - is it acceptable practice?

I know that the best practice is having both service and dao layers and to add @Transactional annotations on the service level. But in my case it means most of my service classes is created just to repeat DAO methods... It is quite irritating. eg.…
Patrycja K
  • 731
  • 7
  • 14