stateless-session-bean

java.lang.ClassCastException with the same class object

不问归期 提交于 2019-12-02 07:36:05
问题 This piece of code irritates me, sometimes it working and some other times it doesn't ! The NamedQuery : (name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") public User findByLogin(String login) { Query query = em.createNamedQuery("User.findByLogin"); query.setParameter("login", login); try { return (User) query.getSingleResult(); } catch (javax.persistence.NoResultException ex) { return null; } } The error make me crazy ! Avertissement: EJB5184: A system

java.lang.ClassCastException with the same class object

核能气质少年 提交于 2019-12-02 03:58:37
This piece of code irritates me, sometimes it working and some other times it doesn't ! The NamedQuery : (name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") public User findByLogin(String login) { Query query = em.createNamedQuery("User.findByLogin"); query.setParameter("login", login); try { return (User) query.getSingleResult(); } catch (javax.persistence.NoResultException ex) { return null; } } The error make me crazy ! Avertissement: EJB5184: A system exception occurred during an invocation on EJB UserFacade , method: public dz.admin.entity.User dz.admin

Java EE 6: How to call Stateful Session Bean from Stateless Session Bean?

纵然是瞬间 提交于 2019-11-30 09:27:05
I have a Stateful Session Bean (SFSB) which acts as authentication module. In the SFSB I store the current user that is logged in. Moreover I have some facades (which are Stateless Session Beans (SLSB)) that handles the JPA/SQL stuff for my entities. In order to check the access permissions of the current user, I try to call the SFSB out of the SLSB. But the current user field is always "null" when called from SLSB. When calling the SFSB directly, the current user field is set correctly... For calling I use the @EJB annotation. Any ideas what the problem might be? Is that somehow a context

@Inject stateless EJB contains data from previous request

穿精又带淫゛_ 提交于 2019-11-29 17:23:22
I have a JAX-RS webservice with a resource for generating testdata. During tests I found out, that the injected EJB is not reinitialized and still contains data from the last request. I have a jar file server.jar containing my business logic with EJBs. To show my problem I have created a stateless bean: @Stateless public class TestService { @EJB SubsequentTestService state2Service; private String value; public void testIt() { System.out.println("####### VALUE: " + value); value = "TestValue"; state2Service.testIt(); } } I am using the subsequent call to SubsequentTestService to show the odd

Java EE 6: How to call Stateful Session Bean from Stateless Session Bean?

邮差的信 提交于 2019-11-29 15:07:37
问题 I have a Stateful Session Bean (SFSB) which acts as authentication module. In the SFSB I store the current user that is logged in. Moreover I have some facades (which are Stateless Session Beans (SLSB)) that handles the JPA/SQL stuff for my entities. In order to check the access permissions of the current user, I try to call the SFSB out of the SLSB. But the current user field is always "null" when called from SLSB. When calling the SFSB directly, the current user field is set correctly...

@Inject stateless EJB contains data from previous request

余生长醉 提交于 2019-11-28 12:08:46
问题 I have a JAX-RS webservice with a resource for generating testdata. During tests I found out, that the injected EJB is not reinitialized and still contains data from the last request. I have a jar file server.jar containing my business logic with EJBs. To show my problem I have created a stateless bean: @Stateless public class TestService { @EJB SubsequentTestService state2Service; private String value; public void testIt() { System.out.println("####### VALUE: " + value); value = "TestValue";

When to use Stateful session bean over Stateless session bean?

孤街醉人 提交于 2019-11-28 02:48:54
A stateful session bean is defined as follows: Stateful Session Beans The state of an object consists of the values of its instance variables. In a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts (“talks”) with its bean, this state is often called the conversational state. A stateless session bean is defined as follows: Stateless Session Beans A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may

Why Stateless session beans?

别等时光非礼了梦想. 提交于 2019-11-27 14:30:37
I was reading about stateless session bean and couldn't understand it's use. Excerpt from sun tutorial below "..Because stateless session beans can support multiple clients, they can offer better scalability for applications that require large numbers of clients" Where stateless session bean is being used? what kind of applications use it? What mechanism has been being used before the advent of 'stateless session bean' to support multiple clients in the similar contexts? Can anyone please provide some details? thank you! To be honest, it is hard to find any reasonable use case for SLSBs. Since

Is it possible to @Inject a @RequestScoped bean into a @Stateless EJB?

梦想与她 提交于 2019-11-27 13:12:56
Is it possible to inject a request-scoped CDI bean into a Stateless session bean? I had asked a related question and thought the specific CDI @RequestScoped into @Stateless question merited its own post. Passing state between EJB methods / @RequestScoped and @Stateless I also asked a similar question about JMS @MessageDriven beans - basically want to know the same about @Stateless. @RequestScoped CDI injection into @MessageDriven bean You can absolutely do what you mention and use @RequestScoped beans in an @Stateless session bean and an @MessageDriven bean. This is a core part of the CDI spec

Why pool Stateless session beans?

Deadly 提交于 2019-11-27 11:56:13
Stateless beans in Java do not keep their state between two calls from the client. So in a nutshell we might consider them as objects with business methods. Each method takes parameters and return results. When the method is invoked some local variables are being created in execution stack. When the method returns the locals are removed from the stack and if some temporary objects were allocated they are garbage collected anyway. From my perspective that doesn’t differ from calling method of the same single instance by separate threads. So why cannot a container use one instance of a bean