I like the idea of using interface, which extends JpaRepository<T, ID>
. It's very clear and elegant. I also know that this interface is always needs an entity type. But sometimes I don’t have an entity, but I want to use this way of interaction with the DB. I already can use methods which interact with entity A
(or which doesn't even have an entity) in the B
entity repository (JpaRepository<B, ID>
), so obviously this is not a problem for JPA
. But It's not so clear and elegant. I want something like this:
public interface ICustomTableRepo extends JpaRepository<Void, Void> {
@Query(nativeQuery = true, value = "SELECT * FROM custom_table")
List<Object[]> getAllFromCustomTable();
}
I want to annotate method declaration with @Query
which has SQL query.
You can see that I don't want to use entity in this interface at all. But, of course, JpaRepository
with <Void, Void>
does not work.
So, how can I use this or same type of interaction with DB without EntityManager
and without JpaRepository
with different entity?