Questions tagged [spring-data-jpa]
Spring Data - JPA is part of the Spring Data umbrella project which makes it easy to implement JPA based repositories
22,542
questions
0
votes
0
answers
7
views
Spring JPA transaction error for Stream query using CompletableFuture
I have the following code:
public void getAllData(List<Pair<Long, Long>> minMaxPairList) throws InterruptedException, ExecutionException {
Queue<String> globalQueue = new ...
1
vote
0
answers
11
views
Spring Data - Callable statement being closed while reading bytes from a Blob
Background
I have a Spring Boot 3.0 application that uses Spring Data JPA to call a stored procedure. Here's the Spring Data repository that calls the stored procedure:
public interface CarRepository ...
0
votes
0
answers
14
views
How to fix "No migrations found. Are your locations set up correctly?" Flyway migration at MySQL?
I'm creating a project Java with Spring Boot 3, using:
Flyway migration with a file: application.properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource....
0
votes
0
answers
6
views
Getting latest distinct values on a table using JPA
I have a table with multiples different user options (key with some value). And I want to recover the latest values the user have selected in all keys. The idea is to show on the UI the latest ...
0
votes
0
answers
16
views
Why i get this exception( UnsatisfiedDependencyException)
Exception
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-09-29T20:44:57.421+04:00 ERROR 28232 --- [ main] o....
0
votes
1
answer
10
views
Jakarta Persistence - create table
I have this entity:
@Entity
@Table(name = "t_message",
uniqueConstraints = {
@UniqueConstraint(columnNames = "key"),
@...
0
votes
0
answers
6
views
filter list of entities using spring specification
can I use spring specification to filter list of entities beside the retrived entities form the database
I have a static class that has all the specifications that i use to filter
@AllArgsConstructor
...
0
votes
0
answers
24
views
Data not saving in MqSQL database which requests through a JSON request - Springboot
When I run the code and send the JSON request, the requested data according to the JSON passes to the line, "patientService.saveUser(user, patient, roleName);" and I've already checked it ...
0
votes
1
answer
33
views
Springboot Application started successfully but the required table is not created in MySql Workbench
I am new to spring framework. I am trying to create a CRUD application. After running the Spring application, the application starting successfully but database is not getting updated. My database ...
0
votes
2
answers
48
views
Not a managed type importing entity
I have a maven multi module project.
It is composed by two spring boot 3 application and one common library, sharing dtos.
Both spring boot application works just fine. What I'm trying to do is to use ...
0
votes
1
answer
25
views
How to create postgres index for query using multiple fields
How to create postgres index for a query using multiple columns
JPA table declaration
@Index(name = "foo_a_b_idx", columnList = "a, b")
JPA repository implementation
List<Foo&...
0
votes
2
answers
29
views
JPA passing list to IN clause in native query
I have this query:
@Query(
value = "select distinct ID_RIGHT from TDK_SEC_HOTEL_RIGHT osrr where osrr.ID_RIGHT in ?1",
nativeQuery = true)
List<String> ...
0
votes
0
answers
14
views
RestTemplate auto retry when JPA insert has error
I have an use case like this:
I have a table named user, then I renamed it to user_info.
I use restTemplate.exchange(...) to call external API to get user info then save it to my table
Everything ...
0
votes
1
answer
20
views
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException
I upgraded from spring 2 to spring 3 and from java 8 to java 17. Now I have this error message:
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Parameter 2 of ...
0
votes
0
answers
15
views
GCP Pub/Sub Pull Subscription consumer with Jpa backed repos resulting in connection issues
Have a typical Springboot web application (simplying the names) with HelloController, HelloService, and HelloRepository. The HelloRepository is using JPA to fetch data from CloudSQL (Postgres). And ...
0
votes
0
answers
19
views
Delete children and parent with the least amount of SQL queries
I have the following JPA entities:
// Father
@ManyToOne(optional = false)
@JoinColumn(name = "GODFATHER_ID", nullable = false)
private GodFather godfather;
@OneToMany(mappedBy = "...
0
votes
0
answers
9
views
Duplicate records being returned from JoinTable
I have three tables: Users, Groups, and GroupUsers, with GroupUsers being a join table between the other two. When using the following method to find all users for a specific tenant,
@Transactional(...
0
votes
0
answers
11
views
Hibernate L2 cache & entityGraph
I'm using Hibernate 6 with L2 cache and Redis.
I'm trying to avoid useless loadings from database.
I have an entity A that is associated with entity B using ManyToOne. The fetch mode for this ...
-1
votes
0
answers
19
views
Find SUM of last digit in a string value Using JPQL
I have a table which contain one column ...in that column I give names and those names are Seperated with underscore('-') and after the last underscore there will be a digit .and need to find that ...
0
votes
2
answers
37
views
How to write parametrized SQL Native query where parameters could be Null?
I have a customer table having following colums - customerId-primary key, customer_name, food_preference, country, wallet_balance.
The requirement is to get all customer data with -
food_preference is ...
-1
votes
0
answers
22
views
Cannot resolve reference to bean 'jpaSharedEM_NEntityManagerFactory' while setting bean property 'entityManager' spring boot 3 with two datasource
i'm trying to upgrade my spring boot app from 2.6.6 to 3.1.3
First as documented i upgrade to 2.7 ( enter link description here ) and everything's has been work will , then i upgrade to 3.1.3 , i fix ...
2
votes
1
answer
67
views
Storing ZonedDateTime in Postgres in UTC
I receive a variable as ZonedDateTime in UTC and I want to persist in a Postgres column in UTC. The column currently is type of timestamptz and I want to read is back in the same ZonedDateTime format. ...
0
votes
0
answers
7
views
org.hibernate.mapping.SingleTableSubclass and org.hibernate.mapping.RootClass are in unnamed module of loader 'app'
Iam trying this code locally:
https://github.com/ali-bouali/spring-boot-3-jwt-security
When running the application iam getting this error:
org.springframework.context.ApplicationContextException: ...
2
votes
1
answer
71
views
Why is Springboot's JPA entity abstract?
I inherited a Springboot based piece of software, in which each entity is represented by at least two data types. For example:
The DTO:
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public ...
0
votes
0
answers
33
views
In Spring data jpa, how to use external sql file having multiple queries in @Query annotation
I have a requirement to delete an entity, let's say, main_entity and this entity has many dependent entities. So, I need to perform deletion in this manner:
delete from dependent_entity_1 where ...
0
votes
0
answers
15
views
Spring data jpa which is best to use for persisting or loading entities and having complex queries to load the entities
I see that there are different ways to load or save entities. I am comfortable with having creating proper entity graphs and avoid writing queries by leveraging JPA Specification. I am curious to know ...
0
votes
1
answer
21
views
Which will be executed first, added column to entity or flyway migration?
I added new parameter to my entity and want to populate this column in the db using flyway. If I write migrations file with INSERT statements, and run program will it be able to see the new column (...
0
votes
0
answers
22
views
spring boot tests with liquibase + h2 fails - not able to find information_schema
I am trying to run a spring boot test for one of the config file, I am using mariadb as my main db but h2 in memory database for tests and liquibase for migration. When I run the test I am seeing ...
-1
votes
0
answers
33
views
Java program throws "Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument", but in VSCode it works
I'm working in the final project for my degree but I have some problems and I don't find any answer.
I have my code in VSCode, and it works fine. I build the project this way:
enter image description ...
0
votes
1
answer
38
views
JDBCTemplate delete row with date only as criteria
I need to delete from Oracle some users using Birthday as criterium in Java.
Table in ORACLE:
create table users{
..
birthday DATE not null,
...
}
Data stored looks like:
user1, 17.03.1976
user2, 28....
0
votes
0
answers
31
views
how to retrieve only distinct entities by a specific column using Spring Data Specification
I need to find the only FlightSeat entities that don't share the common flight(flight.id).
That is one FlightSeat per Flight.
If I get list of FlightSeats using current implementation there are ...
0
votes
0
answers
14
views
Hibernate 6.3.1 Final getting NoClassDefFoundError for org/hibernate/type/descriptor/converter/spi/EnumValueConverter
Caused by: java.lang.NoClassDefFoundError: org/hibernate/type/descriptor/converter/spi/EnumValueConverter
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang....
0
votes
1
answer
34
views
Spring boot application build failure (Failed to load ApplicationContext) [closed]
I don't know what is wrong. But most of the error are caused by the test class and here is the surefire report for the build failure
[ERROR] Errors:
[ERROR] BackendApplicationTests.contextLoads » ...
0
votes
1
answer
20
views
spring-jpa - Create table with VARBINARY Type
I have this entity:
@Entity
@Table(name = "users",
uniqueConstraints = {
@UniqueConstraint(columnNames = "username"),
@...
-1
votes
1
answer
57
views
Spring Boot Double Spend Attack [closed]
I have database of gift card codes. Similar to amazon, users can redeem these gift card codes to increase the balance of an account. The function of my program first checks if the card is used, then ...
0
votes
0
answers
7
views
Version increment happening for multiple reads for LockModeType.PESSIMISTIC_FORCE_INCREMENT using Spring JPA
So my setup is:
Java Framework: Spring JPA
Backend Database: Postgres
@Override
@Lock(LockModeType.PESSIMISTIC_FORCE_INCREMENT)
Optional<User> findById(UUID id);
I am trying to add locking to ...
0
votes
1
answer
26
views
Spring Data JPA - "No property 'findAll' found for type 'Auteur'" Exception
this is AuteurRepository interface**
package com.example.api.repository;
import java.awt.print.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework....
0
votes
1
answer
15
views
Cascade behavior for bidirectional relationship
I have a problem with my bidirectional relationship.
I have entities:
public class Order {
@OneToMany(
mappedBy = "order",
cascade = CascadeType.ALL,
orphanRemoval = true)...
0
votes
0
answers
26
views
Spring Hibernate: Unable to find entity with Id even data available in the database (Only in one to many relationship)
In the spring boot project I have 2 entities named Assessment and Request andtheir relationship is defined as given below.
@Entity
public class Assessment {
@Id
@...
-1
votes
0
answers
20
views
Spring JPA query findByEntity
I have a problem with my Spring JPA repository query.
I have a class User that has a OneToOne reference to Country
When I do a Jpa repository query like:
public interface UserRepository extends ...
0
votes
0
answers
10
views
How can I pass a custom parameter from a hibernate entity to a service that defines a custom UserType which is in another project?
I have an entity model in a spring boot project A:
public class MyEntity{
@Type(type="custom")
private CustomType type;
}
I have another project B that defines the custom user type and ...
0
votes
1
answer
21
views
Adding a unique check, without adding the unique constraint on the database level using spring boot and mysql
I am working on an application and need to maintain a "topic" entity. The entity contains the following fields- id, text, and status(for deleted/active). For example, if we talk about news, ...
-1
votes
1
answer
51
views
@Transactional avoids exception in repository methods
I am using @Transactional for service method
Suppose we have such methods
@Transactional
public void doWork() {
User user = new User(1);
user = userRepository.save(user);
...
0
votes
0
answers
13
views
Error excuting correct native query with pageable, regular expression
I'm migrating a project from Spring Boot 2.7.14 to 3.1.2. I have the following pageable, native query:
@Query(value = "select * from user where (is_external_user is false) " +
&...
0
votes
0
answers
16
views
Set role in JWT using java sprinboot. Using auth0-jwt library
I am trying to implment role based authentication in springboot.I cannot find a way to set role in JWT
Here is my code
AuthService
@Service
public class AuthService implements UserDetailsService
{
...
0
votes
0
answers
8
views
Spring data available to the API client, but not at the runtime
I am implementing the Spring data jpa for the rest api project where I need to fetch the data from a table (with 5 sub-levels (child within in child)). The spring data jpa repository implementation ...
-1
votes
0
answers
34
views
After adding columns to model object in hibernate native query is giving Invalid column name exception [closed]
I have added few columns to a Entity object to work on my story. Once I added the columns in entity object, the existing hibernate native query written by some one started failing with Invalid column ...
0
votes
1
answer
37
views
Setting Default Values for JPA Column Via Enviromental Variable (Spring Boot)
I have an entity class where I want to set the default value for a column. I tried this:
@Column(name = "column", columnDefinition = "double")
@Value("#{new Double('${env.var:-...
0
votes
2
answers
53
views
JPA transaction even without @Transactional/@EnableTransactionManagement
I'm trying to understand how transactions work with Spring. I have a repository interface extending CrudRepository:
@Transactional
public interface MessageRepository extends CrudRepository<Message, ...
0
votes
0
answers
32
views
What is the most generic solution to look after changes of the fields of an entity in Java?
I was looking around to find what it is the best solution regarding observing changes of the fields of an entity. I want something generic and maybe to be used in other application in the future ( i ...