繁体   English   中英

Hibernate懒惰属性获取配置

[英]Hibernate lazy property fetching configuration

我需要使用Hibernate延迟加载实体属性(图像文件),但是我不了解其所需的配置。

根据https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#performance-fetching-lazyproperties,我需要设置字节码检测工具来延迟加载属性。

    <taskdef name="instrument" classname="org.hibernate.tool.instrument.InstrumentTask">
        <classpath path="${jar.path}"/>
        <classpath path="${classes.dir}"/>
        <classpath refxml:id="lib.class.path"/>
    </taskdef>
    <instrument verbose="true">
        <fileset dir="${testclasses.dir}/org/hibernate/auction/model">
            <include name="*.class"/>
        </fileset>
    </instrument>
</target>

我不明白我必须给“ lib.class.path”和“ $ {testclasses.dir}”指定什么路径。

您可以使用注释来指定要针对该特定参数的提取类型。

@Entity
@Table(name = "USER")
public class UserLazy implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "USER_ID")
    private Long userId;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
    private Set<OrderDetail> orderDetail = new HashSet();

    // standard setters and getters
    // also override equals and hashcode

}

这也是一些额外的解释: https : //howtodoinjava.com/hibernate/lazy-loading-in-hibernate/

暂无
暂无

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

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