Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate enableFetchProfile->;未知的_Java_Hibernate_Spring Mvc_Hibernate Annotations - Fatal编程技术网

Java Hibernate enableFetchProfile->;未知的

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

我想在实体示例中使用带有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) }) 
})
这是我的刀:

    @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);
}