0

エンティティ例の DAO で FetchProfile を使用したいと考えています。

これは私のエンティティの注釈です:

@FetchProfiles({ @FetchProfile(name = "example-profile", fetchOverrides = {
    @FetchProfile.FetchOverride(entity = Example.class, association = "association1", mode = FetchMode.JOIN),
    @FetchProfile.FetchOverride(entity = Example.class, association = "association2", mode = FetchMode.JOIN) }) 
})

これは私のDAOです:

    @Autowired
private SessionFactory sessionFactory;

public Example getExample(Long id) {
    sessionFactory.getCurrentSession().enableFetchProfile("example-profile");
    return (Example) sessionFactory.getCurrentSession().get(Example.class, id);
}

getExample を呼び出すと、次の例外が発生しました。

org.hibernate.UnknownProfileException: 不明なフェッチ プロファイル [example-profile]

マッピングか何かがありませんか?

4

2 に答える 2

0

改訂

@Autowired
private SessionFactory sessionFactory;

public Example getExample(Long id) {

    Session session = sessionFactory.getCurrentSession();
    session.enableFetchProfile("example-profile");

    sessionFactory.getCurrentSession().enableFetchProfile("example-profile");
    return (Example) sessionFactory.getCurrentSession().get(Example.class, id);
}
于 2016-05-30T15:40:59.663 に答える
0

そのような@FetchProfilesを持つエンティティが によって読み込まれることを確認してくださいSessionFactory

于 2012-05-25T15:52:01.947 に答える