The fundamental of ORM is mapping with the objects. But, for some reason, I don't want to create objects for running a query.
Is there any way, in which without creating entities (managed classes), I can run a native SQL query?
The fundamental of ORM is mapping with the objects. But, for some reason, I don't want to create objects for running a query.
Is there any way, in which without creating entities (managed classes), I can run a native SQL query?
Yes. You can.
Create a method in the repository class with specific query (native query):
@Query(value="select * from emp", nativeQuery=true)
Object getAllFromEmp();
Keep this method in the repository interface and call it from the service class
Or you can use EntityManager object as below
Query q = entityManager.createNativeQuery("SELECT * FROM emp e");
List<Object[]> empObject= q.getResultList();
Have a look at createNativeQuery
...
Query query = em.createNativeQuery("select ...");
...
And, I think you can find more about it in this thread: https://stackoverflow.com/a/2110860/672798