0

In my current spring setup i would like to implement a slightly different architecture, here is my setup:

I have a "base" DAO interface, which lists all CRUD operations:

public interface BaseDao {

    public boolean create(Object obj);

    public List<Object> read();

    public boolean update(Object obj);

    public boolean delete(Object obj);

}

Next i have "specific" DAO interface, which extends from the "base" one:

public interface ArticleDao extends BaseDao {

    public List<Article> getArticlesByAttribute(String attribute);

}

And finally, the Repository, which implements the interface:

public class ArticleDaoImpl implements ArticleDao {

    public boolean create(Article article) {
        // code
    }

    public List<Article> read() {
        // code
    }

    public boolean update(Article article) {
        // code
    }

    public boolean delete(Article article) {
        // code
    }

    public List<Article> getArticlesByAttribute(String attribute) {
        // code
    }
}

So the idea is simple:

I want every Repository to implement all crud operations + "the methods from the specific dao-interface"

But i get the following error:

ArticleDaoImpl is not abstract and does not override
abstract method delete(java.lang.Object) in BaseDao

etc..

So this is probably because i defined Object as a parameter in the interface and "Article" as a parameter in the actual implementation..

Anybody got the idea how i can follow this pattern correctly? Should i consider working with generics?

Thanks and Greetings

1 Answer 1

2

No. You should work with Spring Data JPA/MongoDB etc. It will make MOST of your boilerplate code go away. Seriously - forget about DAO and go with Spring Data JPA: https://spring.io/guides/gs/accessing-data-jpa/

Sign up to request clarification or add additional context in comments.

4 Comments

No need to reinvent the wheel ;)
mhm, but what about hibernate, how can i integrate it in this context? i mean, i installed hibernate just for querying/saving data, do i even need it now?
It would be best to just follow Spring Data JPA turorial (which uses Hibernate) for a complete but clear Hibernate configuration. If you are using Spring Boot then it will be a breeze. Check out this example: github.com/netgloo/spring-boot-samples/tree/master/…
hey, yea you are right, but just in case... could you refer how to implement my question above? use of generics?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.