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,774
questions
0
votes
1
answer
17
views
Prevent Spring from dropping tables and instead drop the schema only
I'm using Postgres and Spring Boot JPA and would like specific application instances to cleanly
spring.jpa.hibernate.ddl-auto: create-drop
their respective schemas (each instance has its own ...
0
votes
1
answer
13
views
Spring Data is not scanning my MongoDb repositories, why?
I have a demo app showcasing various practices. It inserts data in a MySQL database AND in a MongoDb database.
It used to show these lines in logs :
Bootstrapping Spring Data JPA repositories in ...
0
votes
0
answers
34
views
"Spring Data JPA - Exception: 'No Property Found for Type' with Inheritance Between Repository Interfaces"
I have two repository interfaces.
One is more generic:
@NoRepositoryBean
public interface JpaGenericRepository<T> {
List<T> find(Query<T> query);
long count(Query<T> ...
1
vote
0
answers
17
views
Spring Boot JPA Specification for Exists query
my table data looks like below,
Employee Table
EMP_ID EMP_VERSION EMP_STATUS EMP_NAME
123 1 ACTIVE Kathy
123 2 DRAFT Kathy
245 1 ...
0
votes
4
answers
46
views
Spring Boot/JPA - How i can delete a record from database with DeleteMapping?
my problem is that I want to delete a record from the database by id by selecting a button, but when I click the button to delete the corresponding record with the parameter id I get this error:
> ...
0
votes
1
answer
41
views
Spring Boot - dynamically choose datasource with different SQL flavours based on a feature toggle
I have a number of existing Spring Boot applications that use either Crud or Jpa repositories. I'm working on migrating them from SQL Server to Postgres. I'd like to be able to dynamically swap the ...
0
votes
0
answers
19
views
Use SpEL in JpaRepository Query Hint
I am using spring-data-jpa 2.7.8 and I want to use a parameter in application.yml of a spring boot application to set the HINT_FETCH_SIZE like the following example, Is it possible to use SpEL in the ...
0
votes
0
answers
27
views
Build single object for save with JPA instead of multiple saves and updates
I have a Spring Boot rest API where I use JPA to write the request & response messages for several dependency applications to a Postgresql database:
Entities are structured as follows:
@Builder
@...
0
votes
3
answers
68
views
Spring Data JPA - Exception thrown when using DeleteById with a non existing id
I am using a spring data JPA with a Postgresql db. I have an elementary table, a primary key (varchar) and some attributes. I have a repository and a service using this repository.
I am facing an ...
0
votes
1
answer
10
views
Ignore property when persisting to ES, don't ignore when persisting to DB
Using spring-data(-elasticsearch), I want to persist a property to a PSQL DB but not to Elasticsearch, i.e. the opposite to this question: Spring data: How to ignore field for relational database but ...
0
votes
1
answer
25
views
Spring JPA how to persist a nested object
Context:
Lets say I have 3 entities. Entity A (Portfolio) which contains a list of Entity B (Categories) which contains a list of Entity C (CategoryItems)
Let's say I already have a Portfolio with ...
0
votes
1
answer
34
views
Spring boot - Use external jar to manage database connection and it's required dependencies
I have a main spring boot application that connects to a mongodb to perform certain actions.
It's main class:
@EnableMongoRepositories(repositoryBaseClass = CustomMongoRepositoryImpl.class)
@...
0
votes
0
answers
22
views
How to handle constraint violation when using Spring Data JPA with Oracle Identity column and a different column as primary key?
Spring JPA with Oracle DB : Our database schema has a table with an Oracle Identity column (id) and another column as a primary key uuid. The problem I am running into is when using save operation on ...
0
votes
1
answer
25
views
Spring Data DynamoDB NoSuchMethodException on everything except save
The service is using a DynamoDB with Spring Data. Database access, object mapping etc. all work without errors, I can save objects in the database as expected.
My problem is that no method except the ...
0
votes
0
answers
18
views
In spring data cassandra updating udf field via update.query results in error
I'm trying to update cassandra nested field (udt) using spring data query API:
cql.update(Query.query(
Criteria.where(Attachment.Key.MESSAGE_ID).is(5),
Criteria.where(...
0
votes
0
answers
18
views
Spring Data and Cassandra @Query with variable table names
I have a Spring Cassandra entity class as follows:
@Builder
@Table(value = "#{@environment.getProperty('my.table.name')}")
public class UserEntity {
@PrimaryKeyColumn(name = "id",...
0
votes
3
answers
81
views
Spring JpaRepository findAll method execution returns empty/no data silently
In my production code I was using spring JPARepository.findAll method, we suspect that for one of its execution it returned an empty list (though db table is having the data )instead of throwing an ...
-1
votes
1
answer
39
views
when I added spring-security (basic Auth) then the getMpping works but the postMaping show 403 Forbidden
@RestController
public class UserController {
@Autowired
UserService userService;
@PostMapping("/adduser")
public String addUser(@RequestBody Users user){
return userService.addUser(...
0
votes
1
answer
27
views
Cycles in custom JPA repository
I recently update my Spring Boot from 2.3.4 to 2.7.11 and my tests (but not the application) seem to have stopped working. The error I got was
The dependencies of some of the beans in the ...
0
votes
1
answer
17
views
How can I save only unique models in Spring Data?
I try to fix exception: Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint when save model with help repository.save(model).
How will I fix this ...
0
votes
1
answer
32
views
Spring Boot - Is there a way to create folders with date parameter names?
I would like to know if there is any method or function in Spring Boot that allows you to create folders with names of year, month and day, and that they are subsequently created with the current ...
0
votes
1
answer
34
views
Set<Enum> attribute in JPQL query returns exception at runtime
I migrated an application from Spring Boot 2 to Spring Boot 3. It worked before, but now I have a problem.
Given an entity with this attribute:
@JsonIgnore
@ElementCollection(fetch = EAGER)
...
0
votes
1
answer
27
views
Missing required property 'Builder.<variant kind>'
public void getMaxMinPrice(String category, String subcategory) {
var nativeQueryBuilder = new NativeQueryBuilder();
nativeQueryBuilder.withQuery(queryBuilder ->
...
0
votes
0
answers
22
views
Spring tiles Error : Cannot render an attribute that is not a string, toString returns: null
I am making a spring mvc project and getting this error. Have checked everything multiple times but getting through it.
Please have a look at my code and help me identify with where and what I am ...
1
vote
0
answers
21
views
SpringDataCouchbase - Not able to save map with collection as value
Tried to save Person entity with below attributes in couch base, but not able to save getting error, see below error log.
Note: Issue in Spring boot 3.X onwards, Spring-data -couch 5.X onwards not ...
2
votes
0
answers
33
views
Eclipselink to Hibernate migration: em.persist fails in hibernate when not null is set in DB
We are migrating our application from eclipselink to hibernate.
In our legacy code we are persisting the object first, then setting the values.
This used to work in eclipselink but fails in hibernate ...
0
votes
0
answers
23
views
SpringBoot 2.7.4: Initialize Datasource from active profile properties
We are initializing datasource as per the active profile as below and we are providing the CONFIG_DIR as environment variable during the startup as SET CONFIG=-DCONFIG_DIR=src\main\resources, am ...
1
vote
2
answers
57
views
Field orderRepository in app.service.OrderService required a bean named 'entityManagerFactory' that could not be found
I am trying to create REST API Service with Spring. I have following structure and classes
app\
├── controller\
│ └── OrderController.java\
├── dto\
│ └── OrderDto.java\
├── model\
│ └── Order....
0
votes
0
answers
22
views
Jpa, operations with Entity and String primary key
I have this Entity:
@Entity
@Getter
@Setter
@Table(name="PEOPLE")
public class People implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(...
0
votes
1
answer
39
views
Deleting or adding child entities to parent with Spring Boot Hibernate JPA
I have the following entities:
class Question {
String question;
QuestionType type;
List<QuestionOption> options;
}
class QuestionOption {
String option;
Question question;
}...
0
votes
0
answers
28
views
How to get values which do not exist in databse by comparing with the list values in spring boot
I am having a spring boot application which reads values from the Microsoft access file and then checks if the value exists in the database then gets updated or else inserted as the new record however ...
0
votes
0
answers
43
views
how to make a relationship between tables in Java Spring
I have a request SQL and can't implement in Java spring`
SELECT DISTINCT
mo.MName AS 'Boss',
tdg.DName AS 'Name group',
it.IName AS 'Name item',
tpis.mDesc AS 'Item ',
...
0
votes
2
answers
32
views
why I getting this error on write query in JPA repository in spring-boot?
package com.example.demo.Repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org....
0
votes
2
answers
44
views
Why are all of my tables being deleted when I shut down my Spring application?
I'm running a Spring Boot application on an EC2 instance. It seems to be connecting to the database just fine. However, when I shut it down (Ctrl+C), it deletes all of the tables in the database
...
4
votes
2
answers
367
views
Parameter of constructor required a bean of type that could not be found?
I have the following Spring Repository:
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ...
0
votes
1
answer
21
views
Spring Data MongoDB array match
We are storing objectIds in array in a document.
{
"members": [ ObjectId("a"), ObjectId("b"), ObjectId("c") ]
}
(storing members' ID here)
Now we get list of ...
0
votes
0
answers
11
views
SpecificationExecutor.delete does not delete related entities with Cascade.ALL
I have following entities.
@Entity
public class Demand {
@Id
private String id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "demand", orphanRemoval ...
0
votes
0
answers
25
views
Is there any inbuilt method for UPSERT in spring JPA?
Is there any inbuilt method for UPSERT in Spring JPA ?
Not the save() method which internally fired 2 query, 1. select and based on first query value it done insert or update.
My requirement is any ...
0
votes
0
answers
15
views
Spring Data MongoDB - Randomly select documents but in order of an enum
I want my query to randomly select 3 entries, but it should always select all entries with status "NEW" first, only if there are no entries in status “NEW” anymore it then should select ...
1
vote
1
answer
20
views
Couchbase spring data with Transactional service
I am utilizing Spring Data Couchbase Starter to handle my Couchbase operations, and I need to implement transactions. However, whenever my event document is created by the transactional service, I ...
-1
votes
1
answer
49
views
When using the @ManyToOne and @OneToMany annotations, a stackoverflow exception is thrown
It seems like all the anotations for Hibernate are above variables in classes, but for what day I can't get rid of stackoverflow. I also use spring-data.
Here's what the exception is:
Root Cause
java....
1
vote
3
answers
76
views
two tables got created in mysql with names blog and blog_seq through spring boot entity annotations
I am new in Spring Boot and such things, this is the first project I was trying to explore and was following a lecture for project creation, I made an entity class with @Entity and @Table annotations, ...
0
votes
1
answer
77
views
SPR-16876 TransactionSynchronizationManager not returning correct values in implementation of AbstractRoutingDataSource
I am following this link https://vladmihalcea.com/read-write-read-only-transaction-routing-spring/ to set up the database master and replica instance in my spring boot app. The only difference is I am ...
1
vote
1
answer
25
views
Spring - Is there a way to display the id of a record after being registered with Thymeleaf?
In my project I want to show the id of the record in the view with Thymeleaf after it has been inserted successfully.
Is there any way to get that result?
Entity:
@Entity
@Table(name = "users&...
0
votes
1
answer
45
views
Implementing horizontal sharding in Spring Boot project
I have a project which uses Spring Boot with Spring Data JPA to store data in a MySQL instance. Now my data is growing at a rapid rate. I searched and found some text regarding horizontal sharding of ...
1
vote
3
answers
108
views
Spring Data/JPA - How can I check if a record already exists by name?
I have a question with Spring Data/JPA, I would like to know if there is any way to check if a name is already registered in the database with some function in the Repository with parameters.
I have ...
1
vote
1
answer
173
views
How to check if record exists before insert - Spring JPA [duplicate]
In the project that I am doing, I want to check if a record with the same data already exists in a specific field in the database, if it already exists then do not insert, if it does not exist that ...
0
votes
1
answer
28
views
Deleting large volume of data at once in spring boot in fraction of a second
How can I delete large amount of data more than 10 million records in fraction of a second in spring boot project, the code I'm having right now takes more than 1 minute and 30s to delete these ...
1
vote
0
answers
28
views
Why isn't Spring Data Rest compatible with Spring's Feign on query parameter list?
Using @FeignClient to pass a collection via:
@GetMapping("/api/cars/search/findCarsByIdIn")
CollectionModel<Cars> getCars(
@RequestParam("carIds")
...
0
votes
0
answers
39
views
How to share database connection between legacy web application and spring
I have a legacy web application and plan to migrate it slowly to spring. One of the first steps is to migrate a small part of the applications persistence layer to spring data with JPA, while also not ...