Spring Data投影在派生界面上运行不正常

时间:2018-03-30 05:52:32

标签: spring-data-jpa

我发现Spring Data(spring-data-jpa:1.11.4.RELEAE)投影Spring Data JPA Projections在派生界面上无法正常工作。

对于

@Entity
public class Foo extends Serializable{

    private static final long serialVersionUID = -7096149328600371740L;

    @Id
    @Column(length = 36)
    private String id;

    private String code;

    private String name;

    private Boolean deleted;

    //...
}

public interface FooRepository extends PagingAndSortingRepository<Foo>{
       <T> List<T> findAllByDeletedIsFalse(Class<T> type);
}

派生界面失败。错误是找不到属性text ...

public interface IdText {
    String getId();

    String getText();
}

public interface IdTextFromIdName extends IdText{

    String getId();

    String getName();

    @Override
    default String getText() {
        return  getName();
    }
}

/// Failed.
List<IdTextFromIdName> foos = repo.findAllByDeletedIsFalse(IdTextFromIdName.class);

/// if getText() is annotated as  
///
///    @Value("#{target.name}") 
///    String getText();
///
/// previous repo call is failed too.

public interface IdTextFromIdName {

    String getId();

    String getName();

    default String getText() {
        return  getName();
    }
}

/// Pass
List<IdTextFromIdName> foos = repo.findAllByDeletedIsFalse(IdTextFromIdName.class);

用例是,我希望在不同实体之间获得IdText的通用视图。

List<IdText> idTexts = ... 

0 个答案:

没有答案