What are Repositories?

Repositories are used to deal with data access and manage persistence of models. Repositories in EasyWeb4J applications are classes which extend the HibernateRepository or the JPARepository class. These classes would collectively be called the "Repository Super Classes" in the rest of the tutorial.

The repository super classes provide methods to facilitate the operations of the actual repository implementations in EasyWeb4J applications.

Tips for Repositories

  • Every repository implementation must deal with the persistence of exactly one model.
  • The type argument must be specified while extending the repository super classes.
  • Do not add presentation or business logic into repositories.
  • Do not design the public API of your applications' repositories to dependent on a specific persistence provider. All persistence specific details must be completely abstracted within the repositories. This will ensure easy migration between different persistence providers.

Repositories' Code

Since this tutorial uses plain Hibernate (without JPA) for ORM, all our repositories would be extending the HibernateRepository class. We do not add any method to our repositories as the HibernateRepository class already provides all ther methods we use in this tutorial.

src/main/java/org/languages/repositories/ParadigmRepository.java:

package org.languages.repositories;

// import statements hidden

public class ParadigmRepository extends HibernateRepository<Paradigm> {
}

src/main/java/org/languages/repositories/ExecutionEnvironmentRepository.java:

package org.languages.repositories;

// import statements hidden

public class ExecutionEnvironmentRepository extends HibernateRepository<ExecutionEnvironment> {
}

src/main/java/org/languages/repositories/LanguageRepository.java:

package org.languages.repositories;

// import statements hidden

public class LanguageRepository extends HibernateRepository<Language> {
}