Questions tagged [spring-data]
Spring Data is an umbrella open source project which contains many subprojects that are specific to a given database. The projects are developed by working together with many of the companies and community that are behind these exciting technologies.
11,294
questions
0
votes
0
answers
26
views
Spring Data Mongo: Compare Two Dates in the Same Document
A brief overview of the document I am working with:
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Data
@SuperBuilder(toBuilder = true)
public class BreachBrand {
@Id
private String ...
0
votes
1
answer
24
views
Redis repository and polymorphism don't work together
I have this code :
@Getter
@Setter
@RedisHash
class Root {
private Base base;
}
public interface Base {
}
@Getter
@Setter
public class Implementor implements Base {
// ...
}
I have a ...
0
votes
0
answers
9
views
spring data mongodb: compare LocalDateTime query
I have the below object
@Document(collection = "qr_code")
public class QrCode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String ...
-1
votes
0
answers
30
views
What is exactly the role of @JoinColumn in Sping Boot?
I create a database with a table named country and another table named companies.
Relation between this two tables is Many-to-One.And inside the Company table I put @JoinColumn(name="country_id) ....
0
votes
1
answer
13
views
How do I fetch specific types inheriting from an abstract class from spring-mongodb with one query?
I'm using Spring MongoDb Data, and I have two classes A and B inheriting from class C.
Both A and B has the '_class' field.
I want to fetch a list of documents with both A and B in them, and have them ...
1
vote
0
answers
19
views
Is it possible to save an object while saving another object?
public class RexorDTO {
private Rexor rexor; //an object without an id, I create it in the usual way via save
private Transit transit; //without id
private Service service;
}
@Entity
@...
0
votes
1
answer
40
views
Is it really needed to use Spring Data JPA Named Queries?
After making some search on the web, I think that when using Spring Data JPA Named Queries, we need some extra implementation or definitions comparing to the derived or dynamic queries in Spring Data ...
0
votes
0
answers
22
views
How do I get old value and new values from audit table for all columns
I am using Spring boot, Spring JPA, and @auditable in order to maintain the audit logs in tables.
This is the duplicate question of - how do i get old value and new value from audit table.
Solution ...
0
votes
0
answers
20
views
I can't send a request with the same id for the flower entity
When saving an object, an error thrown: "could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute ...
0
votes
2
answers
60
views
get API in spring boot with one to many relation
I have two models that are having one to many relation (customers have many invoices)
so i create one - many relation on it, this is my customer class :
@Entity
@Table(name = "customer")
...
0
votes
0
answers
30
views
java.nio.file.NoSuchFileException: C:\Users\PC\Desktop\
I'm trying to assign a png file to all the products in my database, Spring boot doesn't recognize either the path or the file
I've assigned the value "unknown.png" to the photoName attribute ...
1
vote
0
answers
15
views
Spring TransactionManager; what means isNewTransaction() exactly?
I am converting a legacy application to spring-boot. For the API-implementation I want to annotate it with @Transactional, but need to implement a custom transactionManager.
When I define:
@Component
...
-1
votes
0
answers
29
views
How to create a table for each selected element in table Spring boot [closed]
I am creating a simple replica of Bolt taxis service. I have user roles --> Customer and Provider and one table of all users. Customer can send order to Provider.
And I don't know how to create a ...
1
vote
0
answers
44
views
+50
Spring Data MongoDb Query malformed SpEL
Hi I want to run the following query to filter items, the problem is in the second expression where I want to filter the filenames that match some pattern in the list, but it is giving me the ...
2
votes
0
answers
32
views
MongoDB Query to Criteria MongoDB conversion throwing exception
I got a Mongo query like this:
{$and:
[
{$or:
[
{"itemNbr": { $in: :#{#itemNbrs} }},
{"deptNbr": { $in: :#{#deptNbrs} }} //I haven't provided the ...
0
votes
1
answer
25
views
Is it possible to pass Query object as parameter of MongoRepository method?
I create mongodb Query object in service layer, then I call repository method and pass Query to it. I don't want to use annotation @Query. So, repository method should look something like this:
List&...
0
votes
1
answer
24
views
H2 in mem database generates database table names in lower case but when insert data from data.sql file, convert table names to upper-case
I have a Spring Boot project with different databases for dev (MySQL) and test (H2 in memory). I also have two data.sql files configured for dev and test profiles.
In test when Hibernate creates ...
-1
votes
0
answers
56
views
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in class path resource
I have been tring to implement spring-security with jwt for my rest api. i have followed this Github link from spring-security to implement.
when i try to send request to /token with username and ...
0
votes
1
answer
14
views
Spring boot Content-Disposition filename in Russian
the problem with downloading a file from the server, the file name may contain Russian text, when downloading it substitutes ??????? instead of Russian letters, and the download breaks, a file without ...
0
votes
1
answer
26
views
Postgresql Spring Data @GeneratedValue without @Id return null value
im working in spring boot project i want to map a property with serial (using my sequence) column in my table and this column is not the ID.
i found this solution :
@Column(name = "...
0
votes
2
answers
30
views
@DataJpaTest breaks after upgrade from Spring Boot 2.6.6 to 2.7.0
After upgrading to the latest Spring Boot Version, several tests in classes that have the annotation "@DataJpaTest" were no longer working. Many things broke, but what was specifically weird ...
0
votes
0
answers
19
views
Springboot Pageable with Specification JPA problem
i have a data problem for my code:
PeopleSpec peopleSpec = new PeopleSpec(req.getSearchFilters(), jsonReqRes.getOrder());
int currentPage = req.getCurrentPage() - 1;
int elementForPage = ...
1
vote
1
answer
11
views
Find multiple MongoDB records with different combination of values using Spring Data MongoDB criteria
I have a collection with first name, last name and birth year.
[
{
"firstName": "John",
"lastName": "Smith",
"birthYear": ...
1
vote
0
answers
24
views
MongoTemplate findAndModify for document insertion
Given a document with the below structure:
{
"_id": "XXXX01",
"otherAttributes", "....",
"child": [{
"_id": "YYYY01",
...
0
votes
0
answers
22
views
spring data mongodb: E11000 duplicate key error collection replica set. Occurs even after checking whether data with unique key exists or not
The issue that I am facing is intermittent and occurs only in the production environment during heavy loads.
MongoDB is set up in replica set mode with an arbiter.
I have a UserDetail class
@Builder
@...
0
votes
0
answers
14
views
MongoListener + Spring Detect updated fields in Document
I have a Springboot application + MongoDB and I need to audit every update made to a collection on specified fields (data analysis purpose).
If I have a collection like:
{
"_id" : ...
0
votes
0
answers
18
views
Any way to specify Spring Data endpoint programatically at runtime?
I am forced to discover my database endpoint at run-time. Specifically I have to discover cassandra contact points (not nodes, the actual contact points) via a web service before I can connect to ...
0
votes
1
answer
26
views
Cannot save more than 256 records R2DBC: Spring WebFlux Cannot exchange messages because the request queue limit is exceeded
I have below code which inserts data into postgres database:
if (employeeList == null || employeeList.isEmpty())
return Flux.empty();
return Flux.fromIterable(employeeList)
...
0
votes
2
answers
52
views
Spring Data JPA: How to use DISTINCT with ORDER BY? [duplicate]
I am running into
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
Here are my Models & Query:
//Models:
@Entity
@Table(name = "Book")
@Data
public class ...
1
vote
2
answers
52
views
JPA Queries Aggregate function COUNT with two tables
I have two entities: Governor and State with ManyToOne association. I need to get all states where there are/were governors and display their count. I'm using PostgreSQL. It looks like this:
SELECT ...
1
vote
0
answers
18
views
Dependency Check (@Required) is not working and giving exception even when i am giving the value to property, Spring Boot
DependencyCheck.Java
package com.yuv.spring.dependencyCheck;
import java.util.List;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation....
1
vote
1
answer
33
views
Got some troubles with JPQL (JPA) query SELECT DISTINCT ORDERED BY
as in title i got some problems with query in JPQL
that's the query I'm using:
@Query(value = "SELECT DISTINCT o.idWhom FROM Message o WHERE o.idWho = ?1 ORDER BY o.date DESC")
List<...
2
votes
1
answer
78
views
Java / MongoTemplate Aggregation, Group and Sum not grouping as expected
I have a mongo collection which has many documents containing information about credits / gifts given to our users.
I would like to be able to run an Aggregated Query to get all the users who have ...
0
votes
0
answers
17
views
How to access 'public' API resources (Spring data REST) from Angular without login requirement both stored on AWS?
My Spring Boot Data REST consists of two separate controllers, one for protected resources and another for public resources (PublicAPIController) - I don't know how or whether it would be possible to ...
0
votes
0
answers
5
views
Inline Querys with : @Query ( nativeQuery= true, value="...") do it work?
MariaDB Execute it but SpringBoot dont whant to get the TRACKING NUMBERS
@Query( nativeQuery = true, value =
"SELECT dc.tracktracenr " +
" FROM ...
0
votes
0
answers
17
views
Is it possible to use the server side certificate of MySQL DB in implementing SSL connections?
I have given a mysql user that has SSL capability. DBA said that there should be no changes on application level since it is a user configuration.
While I can use the said user in MySQL Workbench, I ...
0
votes
0
answers
34
views
Spring data butch insert with fk
I have self referencing model.
@Data
@Entity
@Table(name = "ShopUnit")
@DynamicInsert
public class ShopUnitModel {
@Id
@GeneratedValue
private UUID id;
@NotNull
private ...
-1
votes
0
answers
18
views
Spring Boot Json JPA
I am learning Spring Boot
Please tell me or show me how to put this json into the database using Spring JPA?
I have a mock database. I did it myself, based on this json object.
enter image description ...
0
votes
0
answers
28
views
Number of items fetched per page gets reduced after some number of pages while fetching data from Azure cosmosDB using Spring boot
I have a Cosmos container containing about 24K documents. I am fetching these in pages of size 200 using spring boot. Here's the snippet for the same:
public void ingest() {
var page = ...
0
votes
0
answers
21
views
Spring Open Projection - Object and Additional Value
Let's assume we have a model like this:
class User {
String name;
Integer age;
}
The query returns results, and the extraField is mapped, but the user isn't.
I have a query that joins the ...
0
votes
0
answers
15
views
Is it possible to override/customize the behavior how a Spring Data Key-Value repository evaluates the id of an entity?
Hiho,
We are currently using Spring Data JPA to build a service. The service knows about some Entities. These entities define an identifier that is declared through @javax.persistence.Id. The service ...
0
votes
1
answer
33
views
Unable to create retry-able datasource for spring boot jdbc
I would like to add the retry feature for database connection certain number of times until the app acquires it. For the I have used the spring-retry on the DataSource but it is not working. It is ...
0
votes
1
answer
28
views
How to make one query to the database to find the date between, before, after and pageable?
If startDate not null and endDate not null = beetwen + pageable
If startDate is null and endDate not null = before + pageable
If startDate not null and endDate is null = after + pageable
I also ...
1
vote
0
answers
18
views
Spring Data - One Entity To Many Documents
I keep files entities (AppFile) in MySQL, but their download logs (AppFileLog) are stored as documents in MongoDB.
At document side I have DBRef to entity.
@DBRef
private AppFile file;
At entity side ...
0
votes
1
answer
33
views
Spring Data JDBC + Querydsl: error "JdbcRepositoryFactory does not support Querydsl"
I want to use Spring Data JDBC with QueryDSL support. According to Spring documentation (https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#core.extensions.querydsl) it is supported, ...
0
votes
0
answers
54
views
How to insert entities in one request. Spring Data
I have model
@Data
@Entity
@Table(name = "ShopUnit")
public class ShopUnitModel {
@Id
private UUID id;
@NotNull
private String name;
@ManyToOne(cascade = {CascadeType....
0
votes
1
answer
52
views
How do I make JPA entity field truly write-only
I have a case where I'm persisting a large jsonb field into a PostGres table, but do not want to read it when I fetch the entity; if I do fetch it, my service goes OOM. A better design might be to ...
0
votes
2
answers
114
views
Spring Data JPA : query to find objects by list?
I have 2 classes: book and category which have a OneToMany relationship.
I want to pass a list of string containing categories. The result should return all books which match any of the category in ...
0
votes
0
answers
46
views
using UUID in jpa results in Undefined Behaviors
i produced two different results by just changing type (and generation) of Id in my entities, please help me to understand what causes this
if you want to reproduce or inspect closely
i have two ...
0
votes
0
answers
22
views
How does insert ignore for batches work in Spring Boot repository
I am working in Spring Boot framework.
I have a working way to run batches of "insert ignore" but i don't fully understand how/why it works.
I am using the Persistable interface to have ...