I am trying to get count from a postgreSQL database using Spring Data JPA createNativeQuery. However, the query is returning null instead of the actual values. Here is the JPA createNativeQuery statement below: I need help mapping the “submitted”, “pending” and “totalApplications…
Tag: spring-data-jpa
Spring Data JPA Distinct Returning Duplicate Values
In my Spring boot application I have a query which should return a distinct List of Focus’ (works perfectly in MySQL) However this does not return distinct values, duplicates are contained in the resulting list. Another issue is that I can’t return a whole entity using @Query annotation – ch…
Connection refused trying to connect to mongoDB docker instance
I’m trying to deploy a simple app with a MongoDB with JPA, but I can’t make it work right. When I deploy the app in a docker container, I keep getting the following error: This is the dockerfile I use to build the image: And the docker-compose.yml I used to run mongoDB: My entities all follow the …
How can I implement a Save Or Update function using Spring Data Jpa?
I am using Spring Data JPA to save a record to my database. Here is the method I am using: and my repository: I want to modify this so it will Save or Update. This is what I have so far: I have a few questions – #1 Is this bad practice (deleting and then re-inserting)? #2 If I implement
Spring JPA-I get error that object is not persisted even though i have persisted it
I am using Spring boot-I have 3 classes User,Role and UserRole.I have pesisted both role object and user object but i get error that role object is not persisted.The mappings- between User and UserRole is OneToMany ,between Role and UserRole OneToMany.In the UserServiceImpl class i have persisted Role object …
post data for foreign key in postman
this is my model class.There is foreign key from another table AssessmentProperties .now when iam posting the data with postman my data looks like this but my input should be looking like this can anyone say me what should i do for this? and by the way this is the controller for post method Answer Instead of …
Escape colon (‘:’) in custom h2 Query
So I am trying to write a custom query for h2 using its JSON_OBJECT function. JSON_OBJECT uses a format of JSON_OBJECT(key:value) so as a simple example in my Spring repository I am writing a query like @Query(value = “SELECT JSON_OBJECT(‘id’:1)”, nativeQuery = true) When executing tha…
How to combine two lists from the same relation in Java-8
I have below entities Manager and Colleague Manager Entity Colleague Entity Above relation can be represented in JSON as I am retrieving the result on managerReposiotry.findAll() as I want to create a super list of all names from Manager and Colleague What I am currently doing is Is there any other way in Jav…
What’s the effective way to insert more a million rows into postgresql server from another postgres server using Java?
I have two postgresql servers and I need to copy table rows with from first server format and convert to another server format (different column names). I use java application with spring boot and jpa repository, which implemented method findAll with stream read fetch size 1000. After reading I convert and in…
JPA does not return default value after saving
I faced a problem. A have an entity: DDL of the related table: I have such logic: Field dateCreate is set by DB function now() but it is not returned by JPA in created entity. Does anyone know how to solve this problem? Without using Hibernate or Spring specific tools. Just JPA. Answer You need to refresh the…