ejb-3.1

Does it make sense to have static methods in stateless ejbs?

痴心易碎 提交于 2019-12-23 19:09:56
问题 Stateles ejbs are intended to be idempotent and have no memory of previous user interactions. That sounds like a static method to me. so instead of having public void save(Entity e) { em.persist(e); } is it safe to have public static void save(Entity e) { em.persist(e); } inside an EJB? 回答1: No, because static methods do not participate in container-managed transactions, AOP, security, etc. BTW your second example won't compile, em is injected by the application server and it can't be static

JPA transaction rollback fails with call to stateless bean

眉间皱痕 提交于 2019-12-23 12:54:40
问题 Inside a BMT (using a UserTransaction ) I call a method on another stateless EJB. When I rollback this transaction, the entity created in the EJB method is not rolled back. I use EJB 3.1 with JPA 2.0. The transaction begins in method doTheTransaction() : @Stateless @LocalBean @TransactionManagement(TransactionManagementType.BEAN) public class TaskExecutor { @Inject private SomeEntityFacade someEntityEJB; @Inject private RandomEJB randomEJB; @Resource private UserTransaction ut; @Asynchronous

@singleton behaving like @stateless bean

梦想的初衷 提交于 2019-12-23 12:32:08
问题 i am working on an application(enterprize application in java) in which i need is single instance to be shared by multiple thread concurrently for which i have used @singleton . when each user login a value is set in telecallers List by invoking setTeleCallersDetails() remote method. but at certain point when number of user logged in exceed 15 then @singleton starts behaving like @stateless bean as setTeleCallersDetails() start adding value in new tellcaller arraylist. can anybody tell to

Is there any way to know the progress of a EJB Asynchronous process?

我的梦境 提交于 2019-12-23 12:28:08
问题 I'm trying to get the percentage of the progress from a EJB Asynchronous process. Is this possible? Does anyone have an idea how I could do this? 回答1: To get to know the progress of asynchronous processes is always tricky, especially if you don't know if they have actually started yet. The best way I have found is to write another function that just gets the progress, so, if you have some unique id for each call, then update a hashmap with the current process. You may want to look at

Best way to expose business logic to restful services via @Inject

馋奶兔 提交于 2019-12-23 12:02:19
问题 I read a lot on this topic on SO and the web but there seem to be problems when dealing with older posts... I want to expose my EJB business logic to a rest api / inject an ejb into a jersey resource. Using @EJB works fine but there are people out there suggesting not to use @EJB for local beans. There are different methods to inject beans in services with @Inject. The easiest (to me) seems to be the following: @RequestScoped // This line is important! @Path("service") public class Rest {

Create EJB with two interfaces. @Local interface for web module and @Remote interface for local app client

可紊 提交于 2019-12-23 03:11:55
问题 I have a EAR package that contains a web module and EJB. The EJB is currently exposed its contains to local app client via Remote interface @Stateless public class CoreEJB implements CoreEJBRemote { @PersistenceContext(unitName = "CoreWeb-ejbPU") private EntityManager em; @Override public void packageProcess(String configFileName) throws Exception { //Process logics } @Override public <T> T create(T t) { em.persist(t); return t; } @Override public <T> T find(Class<T> type, Object id) { return

ejb - Details requried on javax.annotation.ManagedBean

╄→гoц情女王★ 提交于 2019-12-22 11:35:23
问题 There is lot of information about Stateless, Stateful and Sigleton beans everywhere but almost nothing about javax.annotation.ManagedBean . At a first look I assumed that It's be similar to Spring's @Component but I can't use it without complete information. If I annotate a class with @javax.annotation.ManagedBean will it be singleton or it will have instance pool like stateless? Will the methods inside such class be concurrent? I should make sure as in a singleton they are synchronized by

Issue with EJB 3.1 injected with CDI bean while running JUnit

回眸只為那壹抹淺笑 提交于 2019-12-22 10:25:09
问题 I created a EJB3.1 and injected CDI bean using the @inject but facing some issues while unit testing however when tested from the servlet its working fine. I have the beans.xml in the WEB-INF folder. Below is my EJB code: @Stateless public class CdiUsingEjb { @Inject private HelloServletCDIPojo helloServletCDIPojo; public String greet() { assert helloServletCDIPojo != null; return helloServletCDIPojo.from(); } } Below is my CDI bean: public class HelloServletCDIPojo { public String from() {

Issue with EJB 3.1 injected with CDI bean while running JUnit

大憨熊 提交于 2019-12-22 10:18:47
问题 I created a EJB3.1 and injected CDI bean using the @inject but facing some issues while unit testing however when tested from the servlet its working fine. I have the beans.xml in the WEB-INF folder. Below is my EJB code: @Stateless public class CdiUsingEjb { @Inject private HelloServletCDIPojo helloServletCDIPojo; public String greet() { assert helloServletCDIPojo != null; return helloServletCDIPojo.from(); } } Below is my CDI bean: public class HelloServletCDIPojo { public String from() {

@Singleton bean failed to initialize because of not expected transaction status 4 when it's marked TransactionAttribute=NOT_SUPPORTED

和自甴很熟 提交于 2019-12-22 09:40:10
问题 I'm having difficulty with my EJB3.1 bean initialisation and more specifically to do with it failing due to perceived transaction rollback, even though I've marked the bean with @TransactionAttribute(NOT_SUPPORTED) . This should mean that any client transaction is paused on bean method entry until exit (when it will be resumed. It's definitely the transactional apprach I want. The "gist" of the code and error are as follows (note some of it is hand-cranked to hide details but is all relevant