We are working on a Restful project with lots of DB tables. Though the operations on the tables are almost same and mainly INSERT/UPDATE/DELETE/FETCH.
my questions is:
For insert/update/delete operations such repository may be as simple as:
@Component
public class CommonRepository {
@PersistenceContext
EntityManager em;
@Transactional
public E insert(E entity) {
em.persist(entity);
return entity;
}
@Transactional
public E update(E entity) {
return em.merge(entity);
}
@Transactional
public void delete(Object entity) {
em.remove(entity);
}
}
For more accurate code, refer SimpleJpaRepository implementation