Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: JSF/JPA problem Date: Wed, 14 Sep 2011 10:36:25 -0700 Organization: A noiseless patient Spider Lines: 57 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 14 Sep 2011 17:36:27 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="12870"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19laWC9n4yLfzOTwRfRTzX2CrxvkMAee5c=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:FoXJsD+usJBsYNxjfvUVxOumuro= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8025 On 9/13/2011 6:28 PM, Arved Sandstrom wrote: > When I call my session bean from my JSF managed bean, I inject it with > @EJB. You're not doing that Yes, that was it exactly. I was pretty confused by all the different types of injection. There's @ManagedProperty, @EJB, @Resource and @Inject at least, off the top of my head. Looks like I'm going to have to study up and make certain I understand when it's appropriate to use each. FYI, I was confused because one of my texts does a sneaky thing. They annotate a class like this (not syntax checked): @Named("user") @SessionScoped @Stateful public class UserBean { @PersitenceContext private EntityManager em; public String getName() {...} // called from JSF view ... // other methods also called from JSF view ... // uses container manged transactions herein too } Which was kinda confusing how they set up this class. However, the source listing, which occurs later, has an important detail. import javax.ejb.Stateful; import javax.enterprise.context.SessionScoped; import javax.inject.Named; @Named("user") @SessionScoped @Stateful public class UserBean { ... Yeah, after 518 pages of using javax.faces.bean.SessionScoped, they switch to the javax.enterprise.context one without calling out the change. I probably should have caught that, but it's a lot to digest all at once. I think we can declare this problem solved (and also PEBCAK). @EJB for injection worked. Incidentally, I also removed the em.flush() from my bean and the data was persisted anyway, which is what should have been happening all along. Data should be persisted on a commit(), which happens at the end of any container manged transaction, so I was confused about that too. So actually that's two mysteries solved.