Hello,
I don't think I wanna make an extraordinary thing with hibernate, howewer I'm seeking for my answer on the net for two days now, and it seems that I'm not able to find a solution to my issue.
The point is I got a Map (java.util) filled with objects (key and value) like this :
Code:
private Map<Skill, Level> skill;
The hbm file part concerning this Map is right here :
Code:
<map name="skill" table="QUESTION_SKILL_LEVEL">
<key column="FK_ID_QUESTION" not-null="true" />
<index-many-to-many column="FK_ID_SKILL" class="Skill" />
<many-to-many column="FK_ID_LEVEL" class="Level" />
</map>
I can save this map in database well, but I got trouble when I want to access these datas :
Code:
for(Question q : session2.getQuestions()){
for(Level l : q.getSkill().values()){
System.out.println(l.getDescriptionKey());
// Works well
}
for(Skill s : q.getSkill().keySet()){
System.out.println(s.getDescriptionKey());
// Don't works => LazyInitializationException
}
}
The method getSkill() give me the map. I got the Map, I got the values of the map, but I can't get the keys of the map !
The following code is the request to get this result :
Code:
sessions = getHibernateTemplate().find(
"SELECT distinct s "
+"FROM Session as s "
+"join fetch s.questions as quest "
+"join fetch quest.skill as skill "
+"WHERE s.startingDate >= ? ",
new Object[] {minDate}
);
);
(I got an object session which contains a list of questions, and each question contain the Map which cause trouble)
So the LazyInitializationException came cause the "join fetch quest.skill as skill " (skill is the Map) load only the values of the map (I guess)
So there is my question : How to load the key of this map in order to avoid the LazyInitializationException ?!
Thanks a lot for your answers and please apologize me if I did some mistakes (I'm not an expert in english ^^ )