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
587
votes
19 answers

Where does the @Transactional annotation belong?

Should you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classes which are calling using the DAO objects? Or does it make sense to annotate both "layers"?
Thomas Einwaller
  • 8,873
  • 4
  • 40
  • 55
411
votes
12 answers

Data access object (DAO) in Java

I was going through a document and I came across a term called DAO. I found out that it is a Data Access Object. Can someone please explain me what this actually is? I know that it is some kind of an interface for accessing data from different types…
Vasanth Nag K V
  • 4,860
  • 5
  • 24
  • 48
192
votes
1 answer

Unsure if I understand TransactionAwarePersistenceManagerFactoryProxy

I am trying to use the org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy in my Spring project, but I am not sure how to use it or whether it's exactly what I am looking for. I realize it can help make my DAOs work with a…
megazord
  • 3,210
  • 3
  • 23
  • 31
146
votes
5 answers

What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

I'm trying to brush up on my design pattern skills, and I'm curious what are the differences between these patterns? All of them seem like they are the same thing - encapsulate the database logic for a specific entity so the calling code has no…
Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
111
votes
31 answers

Room "Not sure how to convert a Cursor to this method's return type": which method?

Error:Not sure how to convert a Cursor to this method's return type Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details. Using Room I'm getting this error and I'd like to…
93
votes
7 answers

Where should "@Transactional" be placed Service Layer or DAO

Firstly it is possible that I am asking something that has been asked and answered before but I could not get a search result back. We define transactional annotations on service layer typical spring hibernate crud is…
Shahzeb
  • 4,745
  • 4
  • 27
  • 40
82
votes
2 answers

Enumerations in Hibernate

It is often useful to have a field in a DAO whose value comes from a Java enumeration. A typical example is a login DAO where you usually have a field that characterises the user as "NORMAL" or "ADMIN". In Hibernate, I would use the following 2…
Georgios Gousios
  • 2,405
  • 1
  • 24
  • 34
75
votes
16 answers

org.hibernate.NonUniqueResultException: query did not return a unique result: 2?

I have below code in my DAO: String sql = "SELECT COUNT(*) FROM CustomerData " + "WHERE custId = :custId AND deptId = :deptId"; Query query = session.createQuery(sql); query.setParameter("custId", custId); query.setParameter("deptId",…
user3198603
  • 5,528
  • 13
  • 65
  • 125
70
votes
7 answers

Android Room SQLite_ERROR no such table

I'm trying my hand at using Android Room and after following this tutorial I'm getting the following error when i try to build the app: Error:(23, 27) error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such…
jampez77
  • 5,012
  • 7
  • 32
  • 52
63
votes
2 answers

What is the difference between DAO and DAL?

Having studied Java at school I am quite familiar with the DAO-pattern(Data access object). However at work I use .NET. In .NET there is often talk about the DAL(Data Access Layer). To me their purpose seems quite similar. So the question is are DAO…
simoraman
  • 919
  • 1
  • 8
  • 13
62
votes
5 answers

DAO and Service layers (JPA/Hibernate + Spring)

I'm designing a new app based on JPA/Hibernate, Spring and Wicket. The distinction between the DAO and Service layers isn't that clear to me though. According to Wikipedia, DAO is an object that provides an abstract interface to some type of…
John Manak
  • 13,328
  • 29
  • 78
  • 119
55
votes
8 answers

Writing large number of records (bulk insert) to Access in .NET/C#

What is the best way to perform bulk inserts into an MS Access database from .NET? Using ADO.NET, it is taking way over an hour to write out a large dataset. Note that my original post, before I "refactored" it, had both the question and answer in…
Marc Meketon
  • 2,463
  • 1
  • 24
  • 21
50
votes
3 answers

DAO vs ORM(hibernate) pattern

i read in some articles DAO is not mandatory with hibernate and its implementation is by "it depends", in other words, we can choose between ORM vs DAO pattern. Ok, let's assume that i don't want use a DAO pattern, so im using only session CRUD and…
blow
  • 12,811
  • 24
  • 75
  • 112
49
votes
5 answers

Single DAO & generic CRUD methods (JPA/Hibernate + Spring)

Following my previous question, DAO and Service layers (JPA/Hibernate + Spring), I decided to use just a single DAO for my data layer (at least at the beginning) in an application using JPA/Hibernate, Spring and Wicket. The use of generic CRUD…
John Manak
  • 13,328
  • 29
  • 78
  • 119
47
votes
2 answers

Java EE Architecture - Are DAO's still recommended when using an ORM like JPA 2?

If I'm using an ORM like JPA2 - where I have my entities that are mapped to my database, should I still be using a DAO? It seems like a lot more overhead. For example, I would need to maintain three extra packages: One that specifies my domain…
Brian DiCasa
  • 9,369
  • 18
  • 65
  • 97
1
2 3
99 100