23,356 questions
0
votes
0
answers
23
views
How to manage DTO proliferation for different API operations
I'm having trouble managing DTOs.
I'm working as follows: I have a reusable DTO called PhoneResponseDTO that is used in both findAll and findByID. Then I created a DTO for each operation like Created, ...
0
votes
0
answers
26
views
Spring native query (declare..begin..end) with parameters
I have trouble passing parameters for a native query with declare..begin..end style.
This code doesn't work:
@Test
@Transactional
void foo() {
em.createNativeQuery("""
do
...
0
votes
1
answer
9k
views
JPA insert query spring boot
I have class City which is:
@Entity
@Table(name="city",schema="rezervisi")
public class City {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private int ...
2
votes
3
answers
10k
views
How to order by multiple columns in Spring data JPA query with calculation in order by?
I am trying to add the following query to the JPA repository @Query
"select st from Strategy st where st.unId= ?1 order by ( st.totalMargin / st.totalRevenue ) desc"
However, this query does not ...
0
votes
0
answers
62
views
Spring Boot 2.7.x JPA @ManyToOne join returns empty list on GET, but works on POST
In a Spring Boot 2.7.x application with Hibernate/JPA, there are two tables:
tickets
complaint_id (PK, VARCHAR(255))
attachment
complaint_id (FK, VARCHAR(255))
other fields: id, file_name, ...
8
votes
3
answers
13k
views
SpringBoot unit test does not use @EnableAutoConfiguration annotation from Application class
I want to configure a Spring Boot Application so that no DB is used at all.
So I have annotated my Application class for excluding JPA autoconfig classes:
@SpringBootApplication
@...
3
votes
1
answer
1k
views
Do I really need countQuery in a native @Query for pagination?
According to the reference, countQuery is required for native queries pagination (at least there is an example with it). But according to my tests (Spring Boot 2.4.5), @Query pagination works without ...
3
votes
3
answers
8k
views
Spring Data JPA Pagination without count query
According to Spring docs https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.special-parameters returning with List should not issue count query.
But with my spring it ...
1
vote
1
answer
66
views
Why is Spring attempting to use a read-only transaction when I explicitly requested a new write transaction?
I have a service method that performs the following operations in sequence:
Calls a read method annotated with a custom read-only transaction annotation (equivalent to @Transactional(readOnly = true))...
-2
votes
1
answer
79
views
Converting from Java model to JPA
I have implemented a class User that represents a User (so far either a Student or a Teacher). What they have in common is that they both have IDs, and some information about the user (this is stored ...
0
votes
1
answer
9k
views
SQL0913 Row or object table in Schema type *FILE in use
I am having a transaction using spring data , and I am trying to do an save operation (insert operation) . [SQL0913] Row or object table in Schema type *FILE in use.
Following is the entity
@Entity
@...
0
votes
1
answer
79
views
Jakarta Persistence (JPA) Specification for a join
I cannot get this JPA Specification to work for a simple join. I know the ""statusLookup.code" when mapping but does not work here. Does anyone know how to get it to work. Its a ...
2
votes
3
answers
192
views
JPA recursive hierarchy read - StackOverflowError with FetchType.EAGER but LazyInitializationException with FetchType.LAZY
I'm working with these entities:
UserEntity:
@Entity
@Table (name = "users", uniqueConstraints = @UniqueConstraint(columnNames={"name"}))
public class UserEntity {
@Id
@...
1
vote
3
answers
9k
views
How to map oneToMany using ModelMapper
I am using springBoot, I want to map OneToMany relationship from parent to child. Directly using entity with eager fetching I get recursive records, therefore, trying using ModelMapper for DTO mapping ...
1
vote
1
answer
11k
views
Spring-Data JPA: InvalidDataAccessApiUsageException for @Transactional
I run a Spring Boot Application wiht @EnableTransactionManagement and want to use @Transactional(readOnly = true) for some database queries.
But I receive a confusing error message.
I'm using Spring, ...
0
votes
1
answer
67
views
When deleting the cart by id, all the cartItems get rovmved correctly, but the cart still holds its data until I add another item to the cart
I'm working on e-commerce APIs, I have this service that is responsible for the cart operation:
@Service
@AllArgsConstructor
public class CartService implements ICartService {
private final ...
Best practices
0
votes
7
replies
187
views
Best way to write an Oracle Procedure using Spring Data Jpa
I am new to JPA and learning it. Now I have an Oracle procedure in system, which now needs to be made DB Agnostic, that can run on Postgres. For that I want to write the same functionality of ...
2
votes
2
answers
11k
views
Crud method for query of enum list field in Spring Data JPA
I have a user profile class that includes a field which is a list of enumerated roles:
enum UserRole {
USER,
ADMIN;
public static final int MAX_LENGTH = 5;
}
@Entity
@Table(name = "...
0
votes
1
answer
42
views
Enable Hibernate @Filter as default in Springboot for soft delete
I defined a Hibernate Filter to filter out the deleted records.
My wishlist:
The Filter should be enabled all the time as default.
Only in special cases when I need the deleted records, then I would ...
2
votes
2
answers
11k
views
Springdata JPA repository findAllByXXX() return null instead of an empty list
I'm using springboot 2.1.2 and I encounter some problems with repository.
Here are my entity classes:
@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "orders")
public class Order {
@Id
...
1
vote
1
answer
93
views
Sorting over a JPA projection of a UNION query using Criteria API
I have the following (oversimplified) code, that performs an unionAll between two tables using Criteria API, and retrieves a projection given by ProjectionDTO. These entites are just examples.
public ...
0
votes
2
answers
9k
views
Autowired dependencies failed
I am facing an error telling autowired dependencies are failed. I tried all that I can do and I checked many forums and stackoverflow but I couldn't figure out what's going wrong in it.
I am ...
2
votes
1
answer
12k
views
Connection reset by peer in Spring Boot application with Hibernate and Oracle
I'm getting this exception
Caused by: java.sql.SQLException: An operation is being attempted on a closed connection.
------------------------ Cause of Close ---------------------------------
...
1
vote
2
answers
81
views
domain events registered during @PrePersist are not evaluated
I created a simple project with contains only one Entity which inherits from AbstractAggregateRoot and tries to register an event during the @PrePersist JPA lifecycle event.
@PrePersist
fun ...
0
votes
1
answer
62
views
Data truncation error when saving JSON in Spring Boot 3.1.4, Hibernate 6.2.9, and MySQL after upgrade
I recently upgraded my application to Spring Boot 3.1.4, Java 21, and Hibernate 6.2.9. Since the upgrade, I am encountering the following error when trying to save JSON data into my database:
WARN 1 -...