Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8025

Re: JSF/JPA problem

From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: JSF/JPA problem
Date 2011-09-14 10:36 -0700
Organization A noiseless patient Spider
Message-ID <j4qomr$ci6$1@dont-email.me> (permalink)
References (2 earlier) <XcPbq.17471$CQ4.165@newsfe09.iad> <j4om1r$a40$1@dont-email.me> <EWRbq.10526$EP3.6864@newsfe05.iad> <j4or6k$ctb$1@dont-email.me> <MqTbq.18258$YA4.3466@newsfe14.iad>

Show all headers | View raw


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.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JSF/JPA problem markspace <-@.> - 2011-09-13 09:19 -0700
  Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 17:24 -0300
    Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 17:40 -0300
      Re: JSF/JPA problem markspace <-@.> - 2011-09-13 15:38 -0700
        Re: JSF/JPA problem markspace <-@.> - 2011-09-13 17:06 -0700
          Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 22:28 -0300
            Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 22:31 -0300
              Re: JSF/JPA problem markspace <-@.> - 2011-09-13 19:27 -0700
                Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-14 05:59 -0300
            Re: JSF/JPA problem markspace <-@.> - 2011-09-14 10:36 -0700
              Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-14 17:51 -0300
      Re: JSF/JPA problem markspace <-@.> - 2011-09-13 16:12 -0700

csiph-web