You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Data JPA @Query是否支持投影?(Spring Boot 1.5.10等版本)

@Query Projection Support in Spring Data JPA 1.11.10 (Spring Boot 1.5.10) & DATAJPA-885

Hey there! Let's break down your question about @Query support for projections in your specific Spring Data JPA version and the DATAJPA-885 issue you encountered.

First, the short answer: @Query does support projections in Spring Data JPA 1.11.10, but with limitations that are exactly what DATAJPA-885 addresses.

Here's the detailed breakdown:

  • Supported Projection Scenarios
    Interface-based projections work reliably with @Query as long as the fields you select in your JPQL match the getter methods of your projection interface. For example:

    // Projection Interface
    public interface MyEntityProjection {
        Long getId();
        String getName();
    }
    
    // Repository Method
    @Query("SELECT e.id, e.name FROM MyEntity e WHERE e.status = 'ACTIVE'")
    List<MyEntityProjection> findActiveEntitiesProjection();
    

    This setup will correctly map the query results to your projection interface.

  • DATAJPA-885 Limitations
    The issue DATAJPA-885 highlights is that constructor-based projections and some advanced projection use cases (like combining @Query with Specifications) don't work as expected in this version. You might encounter exceptions like No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [your.projection.class] when trying these patterns.

Workarounds & Fixes:

  • If you need interface-based projections: Stick to matching query selected fields with your projection's getters, and this should work without issues.
  • If you need constructor-based projections: In this version, you'll have to either manually map query results (using a ResultTransformer or post-processing the results) or upgrade to a newer Spring Data JPA version (2.0.x and above, which corresponds to Spring Boot 2.0+). DATAJPA-885 was resolved in later releases, fully supporting constructor projections with @Query.
  • Alternative: Use Spring Data's derived query methods with projections instead of @Query—this pattern is fully stable in 1.11.10.

内容的提问来源于stack exchange,提问作者John Zhang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:14:36