2012-04-06 7 views
0

Ich möchte ein FetchProfile mit meinem DAO für die Entität Beispiel verwenden.Ruhezustand enableFetchProfile -> unknow

Dies ist die Anmerkung in meiner Einheit:

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

Das ist mein DAO ist:

@Autowired 
private SessionFactory sessionFactory; 

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

Als ich getExample nennen, ich diese Ausnahme bekam:

org.hibernate .UnknownProfileException: Unbekanntes Abrufprofil [Beispielprofil]

Fehle ich Mapping oder etwas?

Antwort

0

Stellen Sie sicher, dass Ihre Entität mit @FetchProfiles von SessionFactory geladen wird.

0

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