stateful-session-bean

sessionscoped managed bean vs stateful ejb

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-28 11:57:08
问题 If I have a @ManagedBean that's @SessionScoped , why would I use a @Stateful EJB? I used it before for shopping carts and maintaining a conversational state, but since a managed bean will be kept during the user session I can store state there, then call SLSB for bussiness logic. Is that correct? If it is, then stateful ejbs will be left for more specific applications such as when you need transactions etc? 回答1: Very often stateless session beans can be used for a lot of business problems.

Stateful session beans unexpected behaviour when packaged in a war and packaged in an ear->jar

怎甘沉沦 提交于 2019-12-24 15:18:45
问题 I am new to ejbs. I wrote a stateful session bean scoped @SessionScoped. Then I injected the ejb into my servlet. @Local @SessionScoped @Statueful public class CartServiceImpl implements CartService { private int i = 0; public int getI() { return i++; } } In my servlet @Inject private CartService cartService; . . . out.print(cartService.getI()); Then I opened two browsers (IE, FF) and have hit the servlet. In IE I see output starting from 0 to n. In firefox also I see the output starting from

Lookup returns new instance of Stateful session bean

一曲冷凌霜 提交于 2019-12-21 05:11:46
问题 I am using Java EE 5 , EJB 3.0 , Jboss AS 4.3.2 . I have simplest Stateful bean @Local public interface IStateBean { } @Stateful public class StateBean implements IStateBean { private static int number = 0; @PostConstruct void init() { number++; System.out.println("@PostConstruct: " + number); } @PreDestroy void destroy() { number--; System.out.println("@PreDestroy: " + number); } } I do lookup in servlet for this bean public class MyServlet extends HttpServlet { @Override public void doGet

Stateless and Stateful Enterprise Java Beans

旧城冷巷雨未停 提交于 2019-12-17 06:20:11
问题 I am going through the Java EE 6 tutorial and I am trying to understand the difference between stateless and stateful session beans. If stateless session beans do not retain their state in between method calls, why is my program acting the way it is? package mybeans; import javax.ejb.LocalBean; import javax.ejb.Stateless; @LocalBean @Stateless public class MyBean { private int number = 0; public int getNumber() { return number; } public void increment() { this.number++; } } The client import

Passing parameters between Request Scoped Managed Beans in JSF + EJB 3.1

依然范特西╮ 提交于 2019-12-12 03:48:29
问题 Our problem is a very basic, simple implementation of editing the database using JSF + EJB. Keeping things short: two separate XHTML views, use two separate Managed Beans @RequestScope. WebuserListBean and EditWebuserBean, and with @ManagedProperty we inject WebuserListBean, so we could obtain selected user data. So far no problems. Views are filled with data succesfully! BUT! We want to be able to edit the user! And here (to my surprise) we cannot overcome the problem. 1st try: Because the

Java EE 6 - Pessimistic Locking - ViewScoped bean + Stateful bean with UserTransaction, PreDestroy and other problems

回眸只為那壹抹淺笑 提交于 2019-12-11 14:11:44
问题 In application I'm working on we need to start transaction before user enters 'edit page' (to lock DB records currently edited) and end it when he clicks the button or left the page. For this purpose I use @Stateful EJB bean which manages the transaction and CDI @ViewScoped bean which is used on the 'edit page'. Of course user can take many actions on edit page, which are supposed to be invoked within the same transaction. Here's sample code: @Stateful @LocalBean @TransactionManagement

How to access EJB from a Quartz Job

我只是一个虾纸丫 提交于 2019-12-11 02:48:35
问题 Well, I'm using Quartz to schedule some jobs that I need in my application. But, I need some way to access a Stateful SessionBean on my Job. I knew that I can't inject it with @EJB. Can anyone help me? Thanks. 回答1: I used the EJB3InvokerJob to invoke the methods of my EJB. Then I created my jobs that extends the EJB3InvokerJob, put the parameters of what EJB and method it should call and then call the super.execute(). The EJB3InvokerJob can be found here: http://jira.opensymphony.com/secure

Stateful session bean multi-threaded access

痴心易碎 提交于 2019-12-10 10:04:15
问题 The EJB 3.2 spec says the following: By default, clients are allowed to make concurrent calls to a stateful session object and the container is required to serialize such concurrent requests. Note that the container never permits multi-threaded access to the actual stateful session bean instance. To me concurrent access and multi-threaded access seem equivalent. So how is it possible to make concurrent calls to a stateful EJB while multiple threads are prohibited? 回答1: You are right:

How to use JNDI to obtain a new Stateful Session Bean, in EJB3?

筅森魡賤 提交于 2019-12-05 05:38:04
问题 I'm trying to use JNDI to obtain a new Stateful Session Bean in a servlet (as a local variable). My doGet() method has the following: Bean bean = (Bean) new InitialContext().lookup("beanName"); I've tried including java:comp/env but all of my attempts have led to naming exceptions. I'm attempting to bind the bean in the @Stateful annotation, using various guesses like @Stateful(name="beanName") and @Stateful(mappedName="beanName") 回答1: What I needed was to use the @EJB annotation on the

LazyInitializationException with CDI Managed Bean and Stateful Session Bean

不羁的心 提交于 2019-12-01 19:36:50
I have a CDI Managed Bean (a bean annotated with @Named that is used on JSF) that has a Stateful Session Bean injected. This session bean is like a service, it has the entity manager (annotated with @PersistenceContext(type= PersistenceContextType.EXTENDED)) and expose come methods to manipulate some entities. Those entities are on the managed bean, who is ConversationScoped. Then, the JSF calls a method of the managed bean and the managed bean calls some method of the "service" (the stateful session bean). I don't know if this is the best design, but it was working well. But there's an Entity