-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Spring + hibernate : Key initialization in a map
PostPosted: Thu Oct 20, 2011 4:16 am 
Newbie

Joined: Thu Oct 20, 2011 3:58 am
Posts: 1
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 ^^ )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.