简体   繁体   English

如何在 JPQL 查询中获取 @Basic 字段

[英]How to fetch @Basic fields in JPQL query

The Entity definition is:实体定义是:

@Entity
@DynamicInsert
@DynamicUpdate
public class ProductInformation {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Version
    private Long version;

    private String url;
    private String price;
    private String bookName;
    private String isbn;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String sourceFile;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String information;

    ...
}

I load all the entries using the following JPQL query:我使用以下 JPQL 查询加载所有条目:

from ProductInformation

Afterwards the fields annotated with @Basic are accessed during a Export procedure.然后在导出过程中访问带有@Basic注释的字段。 I can see the following output in the SQL logs (the lazy loading is visible):我可以在 SQL 日志中看到以下 output (延迟加载可见):

select productinf0_.id as id1_0_, productinf0_.book_name as book_nam2_0_, productinf0_.isbn as isbn4_0_, productinf0_.price as price5_0_, productinf0_.url as url7_0_, productinf0_.version as version8_0_ from product_information productinf0_
select productinf_.information as informat3_0_, productinf_.source_file as source_f6_0_ from product_information productinf_ where productinf_.id=?
select productinf_.information as informat3_0_, productinf_.source_file as source_f6_0_ from product_information productinf_ where productinf_.id=?
select productinf_.information as informat3_0_, productinf_.source_file as source_f6_0_ from product_information productinf_ where productinf_.id=?
select productinf_.information as informat3_0_, productinf_.source_file as source_f6_0_ from product_information productinf_ where productinf_.id=?
select productinf_.information as informat3_0_, productinf_.source_file as source_f6_0_ from product_information productinf_ where productinf_.id=?
...

Is there a way to fetch the @Basic(fetch = FetchType.LAZY) annotated fields in the JPQL Query?有没有办法在 JPQL 查询中@Basic(fetch = FetchType.LAZY)注释字段?

See entityGraph and LoadGraphs (javax.persistence.loadgraph) query hint which allows you to specify additional fields to be loaded in your entity, overriding the lazy mapping specification.请参阅 entityGraph 和 LoadGraphs (javax.persistence.loadgraph) 查询提示,它允许您指定要在实体中加载的其他字段,覆盖惰性映射规范。 See https://www.baeldung.com/jpa-entity-graph for examples有关示例,请参见https://www.baeldung.com/jpa-entity-graph

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM