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
16
votes
7 answers

Get actual type of generic type argument on abstract superclass

I have a class like: public abstract class BaseDao { protected Class getClazz() { return T.class; } // ... } But the compiler says to T.class;: Illegal class literal for the type parameter T. How can I…
t777
  • 3,099
  • 8
  • 35
  • 53
16
votes
1 answer

JPA @Version: how to use it?

@Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version private long version; // ...getters and setters } Is it required to create…
cometta
  • 35,071
  • 77
  • 215
  • 324
16
votes
1 answer

How to create a DAO for join tables?

I'm currently on learning on using Dao pattern in my project. I know, one Table is equivalent to one Dao, am I right? just like StudentDao, SubjectDao. Each Dao performs CRUD operations in their associated tables, but my question is, how am I going…
Jc dev
  • 355
  • 1
  • 6
  • 15
15
votes
4 answers

Is there any command line tool that can generate Java entity classes from db (NOT Netbeans or Eclipse wizard)

I used to use Netbeans wizard (version 6.7.1) to generate entity classes from database. Now I want to look for an independent tool (script, command line tool...) that can do the same task, because some developers in my team use Eclipse instead of…
N. Q. P
  • 395
  • 5
  • 15
15
votes
1 answer

How to implement DAO in Scala?

I would like to implement DAO in Scala as follows: trait DAO[PK,-T,-Q] { // T is a "value object", PK is a primary key, and Q is query parameters. def create(t:T):Unit def update(t:T):Unit def remove(pk:PK):Unit def…
Michael
  • 10,185
  • 12
  • 59
  • 110
15
votes
1 answer

Android - Using Dao Pattern with contentProvider

Is correct to use ContentProvider with dao Pattern. ? or it will bring any performance issue ? I will try to explain. I've a contentProvider. an activity, a dao and a bean .. this is the code : class Bean(){ String name; } class Dao{ …
antonio Musella
  • 534
  • 1
  • 7
  • 20
15
votes
3 answers

Type of the parameter must be a class annotated with @Entity or a collection/array of it

Okey, so I tried to follow this guide: https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1 which led me to this code: https://gist.github.com/florina-muntenescu/1c78858f286d196d545c038a71a3e864 I tried to make my own example when I…
LindaK
  • 151
  • 1
  • 4
15
votes
1 answer

ORM/DAO/DataMapper/ActiveRecord/TableGateway differences?

Can you, please, explain me the differences between the following database representatives, say, in PHP.: ORM DAO DataMapper ActiveRecord TableGateway Any examples would be appreciated.
Miroslav Asenov
  • 173
  • 1
  • 7
15
votes
3 answers

Check table exists

I need to check if a table exists in a database. I currently develop using Yii2. My case is a bit different from this question because the table to be checked is not (and can not be) a model. I have tried (new…
Igbanam
  • 5,904
  • 5
  • 44
  • 68
15
votes
2 answers

Get annotated hibernate tablename from POJO

I have an entity which is declared roughly like: @Entity @Table(name = "myUserTable") public class User implements Serializable { ... } I'm making a generic DAO class, and in doing so I'd like to retrieve the "myUserTable" name. Is there any way I…
niklassaers
  • 8,480
  • 20
  • 99
  • 146
14
votes
1 answer

One DAO per 'container' class or one DAO per table?

I have a 'container' class with fields that are contained in several database tables, and I use the DAO pattern for accessing the data. The question is, should I create a single DAO for this 'container' class, or is it better to have one DAO per…
Anna
  • 177
  • 3
  • 10
14
votes
5 answers

Using Static methods or none static methods in Dao Class?

Hi I generate Dao classes for some DB operations in this manner making methods of Dao class as static or none static is better? Using sample dao class below ,İf more than one client got to use the AddSampleItem method in same time?how this may…
dankyy1
  • 1,094
  • 2
  • 16
  • 32
14
votes
1 answer

PHP Domain Models, DAO, and how to implement

As I asked a question about singular/plural model naming conventions yesterday, I encountered the concept of a Domain Model. As I understand it so far, a Domain Model is simply an object which represents a an entity in my application. To use a very…
ineedhelp
  • 213
  • 3
  • 7
14
votes
2 answers

Standard Naming Convention for DAO Methods

Is there a standard naming convention for DAO methods, similar to JavaBeans? For example, one naming convention I've seen is to use get() to return a single entity and find() to return a List of entities. If there isn't one, what's the one your team…
Tom Tucker
  • 11,676
  • 22
  • 89
  • 130
14
votes
4 answers

Hibernate and Spring - Dao ,Services

I've been reading some tutorials and I could see that most of the MVC implementations are based on: 1) a dao interface for example "IUserDao" 2) a dao impl of that interface - "mySimpleUserDaoImpl" 3) a service interface for persistance :…
Urbanleg
  • 6,252
  • 16
  • 76
  • 139