dao
Room DAO Order By ASC or DESC variable
Use CASE Expression for SQLite to achieve this in Room DAO, @Query(“SELECT * FROM Persons ORDER BY CASE WHEN :isAsc = 1 THEN first_name END ASC, CASE WHEN :isAsc = 0 THEN first_name END DESC”) List<Person> getPersonsAlphabetically(boolean isAsc);
Hibernate or JPA or JDBC or? [closed]
Here’s my take: JPA: Agnostic way to do Java persistence without coupling your clients to Hibernate, TopLink, etc. Hibernate: Good choice if you have an object model to map to. JDBC: All Java persistence is built on this. Lowest level DAO: More of a pattern than a technology; CRUD operation interface. iBatis: Halfway between JDBC … Read more
JSF Controller, Service and DAO
Is this the correct way of doing things? Apart from performing business logic the inefficient way in a managed bean getter method, and using a too broad managed bean scope, it looks okay. If you move the service call from the getter method to a @PostConstruct method and use either @RequestScoped or @ViewScoped instead of … Read more
I found JPA, or alike, don’t encourage DAO pattern
For simple applications, I don’t see any problem in using the EntityManager directly from EJBs and skipping the DAO pattern (I’m tired of writing too much code). And my feeling is indeed that this is what JPA and the Java EE API encourage. But it may still be justified for more complex applications (for data … Read more
Android Room transactions across DAOs
You can use RoomDatabase.runInTransaction(…) Something like: database.runInTransaction(new Runnable(){ @Override public void run(){ Access all your daos here } });
DAO, Repositories and Services in DDD
Repositories are – like you say – an abstraction. They originate from Martin Fowler’s Object Query Pattern. Both Repositories and DTOs can simplify database persistence by mapping persisted data to equivalent collection of entity objects. However, Repositories are more coarse-grained than DAOs by providing control of an entire Aggregate Root (AG) often hiding a lot … Read more
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. It is. And clearly, Java EE doesn’t encourage using the DAO pattern when using JPA (JPA already provides a standardized implementation of … Read more
Single DAO & generic CRUD methods (JPA/Hibernate + Spring)
Here is an example interface: public interface GenericDao<T, PK extends Serializable> { T create(T t); T read(PK id); T update(T t); void delete(T t); } And an implementation: public class GenericDaoJpaImpl<T, PK extends Serializable> implements GenericDao<T, PK> { protected Class<T> entityClass; @PersistenceContext protected EntityManager entityManager; public GenericDaoJpaImpl() { ParameterizedType genericSuperclass = (ParameterizedType) getClass() .getGenericSuperclass(); this.entityClass … Read more
DAO vs ORM(hibernate) pattern [closed]
ORM and DAO are orthogonal concepts. One has to do with how objects are mapped to database tables, the other is a design pattern for writing objects that access data. You don’t choose ‘between’ them. You can have ORM and DAO is the same application, just as you don’t need ORM to use the DAO … Read more