0

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.

SternK
  • 11,649
  • 22
  • 32
  • 46
DirtyMind
  • 2,353
  • 2
  • 22
  • 43
  • Look at the hibernate [dynamic model](https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#dynamic-model) – SternK Mar 22 '20 at 21:14

1 Answers1

2

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 ]

DirtyMind
  • 2,353
  • 2
  • 22
  • 43