【问题标题】:Hibernate lazy property fetching configurationHibernate 惰性属性获取配置
【发布时间】:2019-09-05 12:39:18
【问题描述】:

我需要使用 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}”指定什么路径。

【问题讨论】:

    标签: java hibernate


    【解决方案1】:

    您可以使用注解来指定您想要对该特定参数进行何种类型的提取。

    @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/

    【讨论】:

    • 你这里说的是懒加载关联,我想懒加载简单的属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 2017-07-26
    • 2016-04-08
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 2011-08-18
    相关资源
    最近更新 更多