Java Hibernate enableFetchProfile->;未知的
我想在实体示例中使用带有DAO的FetchProfile 这是我的实体上的注释:Java Hibernate enableFetchProfile->;未知的,java,hibernate,spring-mvc,hibernate-annotations,Java,Hibernate,Spring Mvc,Hibernate Annotations,我想在实体示例中使用带有DAO的FetchProfile 这是我的实体上的注释: @FetchProfiles({ @FetchProfile(name = "example-profile", fetchOverrides = { @FetchProfile.FetchOverride(entity = Example.class, association = "association1", mode = FetchMode.JOIN), @FetchProfile.Fetch
@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) })
})
这是我的刀:
@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:Unknow获取配置文件[示例配置文件]
我是否缺少映射或其他内容?请确保您的具有此类@FetchProfiles的实体已由
SessionFactory
加载
@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);
}