0
votes

I want to create a rest API that will take the stored procedure name as input with the procedure parameter as a rest API parameter. while I create an entity class I just get one table access for example I have a customer table but my stored procedure access different tables and views it gives me an error: "invalid column name id" this is because the executed procedure doesn't use columns and table that we mentioned in the entity class.

I want to create this API with spring rest using spring mvc and jpa.

I also want to authenticate if the system id exists in the table or not, example tablename:customer { sysid : ram, procedure_name:sp_byid }.

for now, How it work is check the systemid input with table(customer) used in entity classes , I am not even able to get a single data ie procedure_name as we cant pass "select colname from table name where id = x" in @query annotation. If a record exists we want to check what stored procedure mapped with the id. sp_byid is the stored procedure that gets data from different table "user" but we are not able to do that due to entity class not having the same table as used by stored procedure and gives error of "invalid column name id". this is the use case example of one stored procedure with only one record I have many to be added.

how do we work with this, is there any alternative to jpa to work without entity and just pass custom queries?

example rest URL : localhost:8080/get/systemid/procedurename

1
You can use EntityManager for this. Here is a blog post explaining it in action: vladmihalcea.com/best-way-call-stored-procedure-jpa-hibernate - Ghokun
works fine! @Ghokun - Dhrumin Shah

1 Answers

0
votes

I found an answer to do a custom query is by making a custom repository to get data via Entitymanager. but custom query returns a query type which can be converted to list of object. you cant get key-value pair like entity.