[jboss-user] [JBoss Seam] - Re: failed to lazily initialize a collection

quilian do-not-reply at jboss.com
Thu Apr 26 05:27:42 EDT 2007


"Sammy8306" wrote : As far as I know, SMPC is scoped over the conversation. That would be the implicit temporary conversation if no conversation is started manually. 
  | You have two options: either make sure the edits happen in the same conversation (and therefore the same EM) or merge the offending object into the second EM instance (using em.merge()).

Hmm. I thought to have done that. The selectBenutzer() method which is called on selection of a Benutzer in the list calls beginConversation(), which
is marked with @Begin(flushMode = FlushModeType.MANUAL)

then when the save butten is pressed commit() is called which is marked with @End(beforeRedirect=true) and calls em.flush().

Would'nt that mean i span a conversation around the whole edit process ?

"petemuir" wrote : Yes, use a SMPC, not an extended PC.  You don't want the @Transactional on those methods (it's an entity bean)

Can you please explain why thats not needed? Do Entity beans always have an implicit transactional behavior??

"petemuir" wrote : and you probably want to let hibernate take care up updating the relationship for you - call entityManager.refresh(foo) to get hibernate to do this.

cool. So i dont need the add/remove on the list? But where should i do that call? I suppose i cant do it in the entity itself, because that would be ugly despite the fact that the entity doesnt know the PC.

So i tried to do it in BenutzerManager.save() with no luck like that:

  | 	@DataModelSelection
  | 	@Out(required = false)
  | 	private BenutzerImpl selectedBenutzer;
  | 
  | 	private GruppeImpl selectedGruppe;
  | 	
  | 	public void selectBenutzer()
  | 	{
  | 		selectedGruppe = mowitaEntityManager.merge(selectedBenutzer.getGruppe());
  | 		beginConversation();
  | 	//	log.info("BenutzerManager selectBenutzer(#0)\n", selectedBenutzer);
  | 	//	log.info("BenutzerManager editedBenutzer(#0)\n", editedBenutzer);
  | 
  | //		benutzer= selectedBenutzer;
  | 	}
  | 
  | 	@End(beforeRedirect=true)
  | 	public void commit()
  | 	{
  | 		log.info("Merging selectedBenutzer: #0", selectedBenutzer);		
  | 		mowitaEntityManager.merge(selectedBenutzer);
  | 
  | 		log.info("refreshing selectedGruppe: #0", selectedGruppe);				
  | 		mowitaEntityManager.refresh(selectedGruppe);
  | 		
  | 		log.info("flushing...");			
  | 		mowitaEntityManager.flush();
  | 		
  | 		mowitaEntityManager.refresh(selectedBenutzer.getGruppe());
  | 		mowitaEntityManager.flush();
  | 		
  | 	}
  | 

I get an java.lang.IllegalArgumentException: Entity not managed by the call to
mowitaEntityManager.refresh(selectedGruppe);

The question is, how to get the gruppe that was selected before the user choose a new one, because if i call selectedBenutzer.getGruppe() in the save() method i already get the new Gruppe. Refreshing that newly selected Gruppe seems to work although i gat a lazy initialisation exception afterwards, when trying ot show the list of Gruppen.

Thanks for your help,
Tobias


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4040889#4040889

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4040889



More information about the jboss-user mailing list