I have two projection interface,
First, ProductMinimal.java
:
public interface ProductMinimal {
long getId();
String getName();
Long getOwnerId();
String getOwnerName();
String getFeaturedImage();
}
and second ProductStatistic.java
public interface ProductStatistic extends ProductMinimal {
int getTotalVisit();
}
When i use this repository:
Page<ProductStatistic> findMostView(Pageable pageable);
I get result, but wrongly mapped:
[{
name=1, WRONG
id=Name, WRONG
ownerId=administrator, WRONG
ownerName=21_d20024e8-970f-4738-9cea-8dda22d0afdd.jpg, WRONG
featuredImage=1, WRONG
totalVisit=21
}]
it should be:
[{
name=Name,
id=1,
ownerId=1,
ownerName=administrator,
featuredImage=21_d20024e8-970f-4738-9cea-8dda22d0afdd.jpg,
totalVisit=21
}]
but when I put all method in ProductMinimal to ProductStatistic and remove parent interface in ProductStatistic, so ProductStatistic all its own attribute:
public interface ProductStatistic {
long getId();
String getName();
Long getOwnerId();
String getOwnerName();
String getFeaturedImage();
int getTotalVisit();
}
using new this ProductStatistic, now I get expected result.
[{
name=Name,
id=1,
ownerId=1,
ownerName=administrator,
featuredImage=21_d20024e8-970f-4738-9cea-8dda22d0afdd.jpg,
totalVisit=21
}]
I don't like using this way, rewrite all existing property.
What I expect is to be able extends property from ProductMinimal, so i don't need to rewrite code.
Why using interface-based projection that extends other interface projection give wrong result?