DirtyMind
DirtyMind

Reputation: 2563

Fetch Data from Database using JPA and Spring Boot without entity or POJO class?

I have created a config table in MS SQL Db. I want to fetch all the details of config table. But I don't want to create a POJO class for that. How can I fetch the detail using JPA 2.2 and spring boot in this scenario?

I looked for something on google and I found this. Which Uses Hibernate EntityManager. But I am wondering is this the best way to do this. Already I have given connection detail in application.properties file. Do I need to give the details again in persistence.xml file.

Upvotes: 0

Views: 2924

Answers (1)

DirtyMind
DirtyMind

Reputation: 2563

I found the solution for this. What I did, create entity manager using below annotation:

@PersistenceContext
private EntityManager em;

and inside any method just call like this:

List<Object[]> category = em.createNativeQuery("SELECT * FROM CATEGORY" ).getResultList();

Got hint from this answer [Spring boot - configure EntityManager ]

Upvotes: 2

Related Questions