Questions tagged [spring-projections]
28 questions
17
votes
5 answers
Spring Projections not returning the State Details
I have a Country and State table for which I have integrated with Spring Data JPA. I have created a function public Page getAllCountryDetails in my CountryServiceImpl for getting all the Country and the corresponding State details.…

Alex Man
- 4,746
- 17
- 93
- 178
4
votes
1 answer
How to handle Spring Boot/ Spring Data projections with entity relationships (nested projection)
I'm trying to get nested projections working in Spring Boot. I have 2 entities, Parent and Child, wheras Parent has a unidirectional @OneToMany relationship to Child.
Here are the classes: (using Lombok-Annotations)
@Entity
@Data…

Philip Müller
- 141
- 3
- 8
3
votes
1 answer
Spring Data Jpa + Spring Projections using @Query (native and JPQL) returns null for related entities
What I'm trying to achieve is write the same query using 3 different approaches in Spring Data Jpa using JpaRepository interface:
Named Method Strategy.
@Query with JPQL.
@Query native SQL.
Here you can see how I've created Visit Entity with all…

Antyfan
- 35
- 2
- 5
2
votes
0 answers
How to make native query for nested projection in Spring Data JPA
I need to write a native query for my projection with nested interfaces.
My TransactionView interface:
public interface TransactionView {
Long getId();
TransactionType getType();
LocalDate getDate();
…

Vladimir
- 33
- 1
- 1
- 5
2
votes
2 answers
Spring data projection for native query not mapped to interface
This my repostoriy for retrieve items
@Query(value = "SELECT DISTINCT M.ID as \"id\", "
+ " M.NAME_PRIMARY_LANG as \"name\" "
+ " FROM ECOMMERCE_CORE.MERCHANT_ITEMS M , "
+ " ECOMMERCE_CORE.PRODUCT_UNIT_OF_MEASURE P , "
…

Ahmed Elemam
- 396
- 3
- 12
2
votes
0 answers
Exception caused by Jackson JsonMappingException - must be an interface
I'm having a problem getting Projections to work with Joda LocalDateTime.
public interface SomeProjection {
Long getId();
LocalDateTime getDateCreated()
}
Results in the following error:
Caused by:…

Gregg
- 34,973
- 19
- 109
- 214
2
votes
1 answer
Spring Projection @Value field fails when a mapped entity returns 'null'
I've been trying to use Spring Data JPA Projections. Also using @Value annotation to concat some properties of some referenced projections.
The problem occurs when one of the referenced projections return 'null' because that particular column is…

Vishnu
- 65
- 1
- 3
- 10
2
votes
2 answers
Change Spring findAll() return type
I want to run Spring JPA's findAll() method but return all records but then without returning all the records. I want to return values from a Projection. Like
public interface StudentRepository extends CrudRepository{
//How can…

KNDheeraj
- 834
- 8
- 23
1
vote
1 answer
How to support sorting and filtering for a field which is not mapped with another entity using spring boot
I have an entity Person which has fields id,name,email
Another entity Employee which has fields id,name,personid (stores the string id of person but not mapped with person table)
Now I want to get paginated list which contains person name, employee…
1
vote
0 answers
How to use java expression in spring data projection using SpEL
The projection for converting a string field to JSONObject using default method as below works fine:
public interface ResponseProjection {
@JsonIgnore
@Value("#{target.extraData}")
String getExtras();
default JSONObject…

CdVr
- 323
- 3
- 15
1
vote
2 answers
Spring Data JPA fetching list always returns at least a single result
I've noticed a slight problem with how my API is working where I'm using Spring Data JPA.
My query looks something along the lines of:
@Query("SELECT p.id AS id, COUNT(l) AS likes FROM Post p LEFT JOIN Like l ON l.post = p WHERE p.location.id =…

BouncingFrog
- 11
- 2
1
vote
0 answers
Spring Projection maps wrong result when use extends interface
I have two projection interface,
First, ProductMinimal.java:
public interface ProductMinimal {
long getId();
String getName();
Long getOwnerId();
String getOwnerName();
String getFeaturedImage();
}
and second…

Mohd Erwin
- 33
- 7
1
vote
1 answer
Spring Rest Data projection @OneToOne property not loading
I have these three classes:
@Entity
public class Trip {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List legs;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List details;
…

onnoweb
- 3,038
- 22
- 29
0
votes
0 answers
Spring open projections + jackson: JsonType annotation written even if a @Value throws an exception
The project
I am using open projections with an annotation that sets the type name. Impacts are a recursive interface that adds a property impacts to all objects that have impacts.
I only copied relevant/cleaned up code to keep it clear.
…

Jente Sondervorst
- 48
- 1
- 6
0
votes
0 answers
Spring Data Neo4j custom query that maps node entity inside COLLECT aggregate
I'm having an issue when trying to map a node entity inside a COLLECT aggregate.
For example, consider that a Company has zero or more Employees. In a graph database, I can create the following relationship between two nodes:
MATCH (e:Employee {…

Michael Cronk
- 63
- 2
- 6