how to query data from a postgres table ex 'pg_stat_statements' in Spring data? - spring

Hello I am using a spring boot application and my requirement is to query pg_stat_statements table for some metrics. I am confused as I cant define a repository because this is not an entity.

Try to create view with this table, add row_number() as Id of this view, then create entity based on this view and use it in HQL

Related

spring boot Filter selected columns from from data table connected by a foreign key using data JPA

I Have two tables as
student (student_id(primary key), student_index(unique key), student_name, student_batch, student_department, student_age)
exam_result_sem_one (result_id, subject_one, subject_two, subject_three, subject_4, fk_student_id)
then I want to get all data from exam_result_sem_one by student_index with the values of student_index and student_name from student table.
I want to do this using spring data JPA instead of using native query. I hopefully waiting for an answer.

which is good idea run large SQL select query script in spring boot or We can execute required things from query and write code in Service level

I am able to obtain all required data from SQL Query. is it good practice to execute big select sql query in JPA in In spring boot. or get required fields from select query. write logic in service level.

how do we handle multiple stored procedure with single entity class

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
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.

Laravel Migration create table from existing table

I am working on such application where table audit should perform to make revision of updated records. Let's say for example I have to log each field update in Users update.
I wants to create clone of existing user table by
CREATE TABLE users_audit LIKE users;
My main question is,
Is there any alternative way or provision in Laravel migration to create table from existing table ?
I know we can run raw sql query in migration up/down method using \DB::raw();
But it would be helpful if any helper function available to create table from existing table like, create or table
Yes, you can, see the below link
Click this link
This statement is used to execute raw queries
DB::statement('CREATE TABLE tablename LIKE existingtablename');

Data insertion issue using cakephp 3.2 to oracle 11g tables

I am just trying to build a simple crud application using cakephp and oracle. But when i am trying to add a new data from my add.ctp its return with this error. can anyone help. Errors are below.
ORA-01400: cannot insert NULL into ("HR"."EMP"."EMP_ID")
CakeDC\OracleDriver\Database\OCI8\OCI8Exception
BTW here 'EMP_ID' is primary key of 'EMP' table and i have also created sequence.
You should try to create all tables strctures using cakephp migrations.
The reason of that - datasource when create table dditionally create not only sequence, but also a triger, to fill id field. Also driver written in way to follow cakephp table field naming conventions. So you can just take EMP schema and get everything work.
Options are: create all tables using migrations from cakephp side, or write trigger that will fill id fields manual on oracle side.

Resources