相关疑难解决方法(0)

Hibernate ManyToOne与FetchType.LAZY不提取懒惰

我正在使用Hibernate和spring.

我有这样的模型类.


@Entity
@Table(name = "forumtopic")
public final class Forumtopic extends AbstractUserTracking implements
    java.io.Serializable {

/**SNIP **/

    private Forumcategory forumcategory;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FkForumcategoryId", nullable = false)
    public Forumcategory getForumcategory() {
        return this.forumcategory;
    }

    public void setForumcategory(final Forumcategory forumcategory) {
        this.forumcategory = forumcategory;
    }
}

Run Code Online (Sandbox Code Playgroud)

它一般工作,但类不是懒惰加载,但在加载ForumEntry后急切.

Hibernate: 
    select
        forumtopic0_.PkId as PkId19_0_,
        forumtopic0_.CreateDate as CreateDate19_0_,
        forumtopic0_.FkCreateUserId as FkCreate3_19_0_,
        forumtopic0_.FkLastUserId as FkLastUs4_19_0_,
        forumtopic0_.LastChange as LastChange19_0_,
        forumtopic0_.FkForumcategoryId as FkForum10_19_0_,
        forumtopic0_.PublishCategory as PublishC6_19_0_,
        forumtopic0_.State as State19_0_,
        forumtopic0_.Text as Text19_0_,
        forumtopic0_.Topic as Topic19_0_, …

spring maven-2 hibernate lazy-loading many-to-one

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×1

lazy-loading ×1

many-to-one ×1

maven-2 ×1

spring ×1