我正在使用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_, …