简体   繁体   中英

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.

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 ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM