DAO and Service layers (JPA/Hibernate + Spring) [duplicate]

A DAO should provide access to a single related source of data and, depending on how complicated your business model, will return either full fledged Business objects, or simple Data objects. Either way, the DAO methods should reflect the database somewhat closely. A Service can provide a higher level interface to not only process your … Read more

Android Room SQLite_ERROR no such table

Another reason for this error could be the entity is not listed in the AppDatabase.java file: @Database(entities = {XEntity.class, YEntity.class, ZEntity.class}, version = 1, exportSchema = true) Make sure you have the latest db file in the databases folder, and if you export your schema, make sure your .json schema file under app\schemas is being … Read more

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

It seems like your query returns more than one result check the database. In documentation of query.uniqueResult() you can read: Throws: org.hibernate.NonUniqueResultException – if there is more than one matching result If you want to avoid this error and still use unique result request, you can use this kind of workaround query.setMaxResults(1).uniqueResult();

Enumerations in Hibernate

using hibernate or JPA annotations: class User { @Enumerated(EnumType.STRING) UserType type } UserType is just a standard java 5 enum. I can’t imagine this is just limited to just annotations but I don’t actually know how to do this with hbm files. It may be very version dependant, I’m guessing but I’m pretty sure that … Read more

Where should “@Transactional” be placed Service Layer or DAO

Ideally, Service layer (Manager) represents your business logic and hence it should be annotated with @Transactional. Service layer may call different DAOs to perform DB operations. Lets assume a situation where you have 3 DAO operations in a service method. If your 1st DAO operation failed, other two may be still passed and you will … Read more

Room “Not sure how to convert a Cursor to this method’s return type”: which method?

Recently I’ve had the same problem but I was using Coroutines within the Dao function, e.g.: @Query(“SELECT * FROM Dummy”) suspend fun get(): LiveData<List<Dummy>> And was unable to compile, but after removing the suspend everything worked just fine. It’s not needed when returning LiveData. suspend and LiveData seem not to work together (as of now).

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

Your example terms; DataMapper, DAO, DataTableGateway and Repository, all have a similar purpose (when I use one, I expect to get back a Customer object), but different intent/meaning and resulting implementation. A Repository “acts like a collection, except with more elaborate querying capability” [Evans, Domain Driven Design] and may be considered as an “objects in … Read more

Unsure if I understand TransactionAwarePersistenceManagerFactoryProxy

Answers are directly available on documentation I realize it can help make my DAOs work with a plain JDO PersistenceManagerFactory. Yes. TransactionAwarePersistenceManagerFactoryProxy proxy allows DAOs to work with a plain JDO PersistenceManagerFactory reference, while still participating in Spring’s (or a J2EE server’s) resource and transaction management. You can surely use it in your app. But … Read more

Data access object (DAO) in Java

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage. That definition from: http://en.wikipedia.org/wiki/Data_access_object Check also the sequence diagram here: http://www.oracle.com/technetwork/java/dataaccessobject-138824.html Maybe a simple example can help you understand the concept: Let’s say we have an entity to represent an employee: public … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)