ejb-3.1

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

旧时模样 提交于 2019-12-05 19:17:52
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 and representative): @Singleton(name = "MyClass") @ConcurrencyManagement(value = BEAN)

EJB 3.1 Singleton + JPA + JSF design advice needed

倖福魔咒の 提交于 2019-12-05 13:08:31
Given: simple JSF webapp (no Seam), having JSF beans calling few EJB's which in turn load and persist JPA entities. What I want to is to use @Singleton annotation for ejb's and inject EntityManager instead of EntityManagerFactory : @Singleton public class MyEJB { @PersistenceContext(unitName = PERSISTENCE_UNIT_NAME) protected EntityManager em; // not EntityManagerFactory } Spec says that @Singleton is thread-safe, supports concurrency and transaction attributes which (from my pov) makes it safe for calling from JSF beans. I expect also performance benefits because of EntityManager not being

Transaction management and CDI

大憨熊 提交于 2019-12-05 10:50:32
I would like to develop an application with CDI (I use Spring usually) to discover this technology. I have read many articles about CDI to learn how it works. I have a simple question about transaction management (for persistence in database for example): Is it mandatory to use EJB 3.1 to have transaction management or is it possible to have it with CDI only ? Thanks. No, you can do it with CDI. You simply need to create an interceptor that starts, commits or rollsback a transaction. It's really not that hard. In Java EE 7 there will be a @Transactional for all managed beans (JSF, CDI, EJB,

Controlling CDI Startup inside EJB 3.1

半腔热情 提交于 2019-12-05 09:55:10
I'm new in here and also new to the CDI world, and the first task I got in my job was to find out a way to controlled CDI uploading. We are using both EJB 3.1 and CDI 1.0 , and because they are controlled by different containers, we can control when and in what order the EJB Managed Beans will be up by using @Startup and @Singleton annotations. But the @Inject CDI bean I have declared in my class is coming as null since the CDI Container hasn't started yet. I have been trying for several days now to look up for solutions and the one I found here did not worked (still came as null). We are

What is the difference between mappedName and lookup attributes of @Resource annotation in EJB?

会有一股神秘感。 提交于 2019-12-05 07:32:47
I'm confused between two attributes of @Resource annotation. Java Documentations says : mappedName : A product specific name that this resource should be mapped to. The name of this resource, as defined by the name element or defaulted, is a name that is local to the application component using the resource. (It's a name in the JNDI java:comp/env namespace.) Many application servers provide a way to map these local names to names of resources known to the application server. This mapped name is often a global JNDI name, but may be a name of any form. lookup : The name of the resource that the

Are CDI event observer methods compatible with EJBs?

妖精的绣舞 提交于 2019-12-05 03:39:47
I have a Singleton EJB (javax.ejb.Singleton version. sigh.) which has a CDI observer method on it. When I try to deploy this to glassfish 3.1 the server fails to deploy the EAR file without any real explanation - simply saying there was an exception during deployment without any more details. SEVERE: Exception while loading the app SEVERE: Exception while shutting down application container .... SEVERE: Exception while shutting down application container : java.lang.NullPointerException This is the CDI event listener : public void updateFromGranule(@Observes @CloudMask GranuleAvailableEvent

How does @SessionScoped work with EJB? Is CDI only for web-tier?

大兔子大兔子 提交于 2019-12-05 02:11:59
How is the session defined in @SessionScoped CDI bean? Is this annotation valid only when called from Servlet container, where the session is well defined in form of HttpSession ? If not, than how an EJB with @Inject @SessionScoped MyBean myBean can know what the session really is ? I mean, methods of this EJB could have been invoked by a standalone client, RESTful WS or by some other view. What should happen in such case? Should the annotation have no meaning, should it inject fresh MyBean instance for each request or maybe it should retain the same instance across all requests? Taken from

@Singleton @Startup @PostConstruct method guaranteed to return before EJBs made available for client calls?

眉间皱痕 提交于 2019-12-05 02:01:42
In the context of a Java EE 6 application run on WebSphere 8.0, I need to execute a number of startup tasks before any business method can be executed. Using a @Startup @Singleton bean for this purpose seems like a promising solution. However, it is not entirely clear to me how exactly the application lifecycle would look like. The EJB 3.1 spec states the following: By default, the container is responsible for deciding when to initialize a Singleton bean instance. However, the bean developer can optionally configure the Singleton for eager initialization. If the Startup annotation appears on

Stateless Session Beans Identity with @EJB and @Inject

巧了我就是萌 提交于 2019-12-04 15:33:32
I have been looking into section 3.4.7.2 of the EJB3.2 specifications lately und done some tests. The specifications: @EJB Cart cart 1 ; @EJB Cart cart 2 ; … if (cart1.equals(cart1)) { // this test must return true ...} … if (cart 1 .equals(cart 2 )) { // this test must also return true ...} The equals method always returns true when used to compare references to the same business interface type of the same stateless session bean. The specifications cite explicitly the @EJB Annotation so I did some tests and I could confirm - if (cart1.equals(cart2)) return always true - the identities

Why session bean method throw EjbTransactionRolledbackException when RuntimeException was thrown

别等时光非礼了梦想. 提交于 2019-12-04 13:52:15
问题 I am trying to persist the entity with constraint validation, when invoke persist - there is constraint that thrown and the caller get EjbTransactionRolledbackException ... so I try to call the validation explicit and throw ConstraintViolationException / RuntimeException and still the caller get EjbTransactionRolledbackException ... when I throw MyException extends Exception - the caller get MyException Even when I call explicit sc.setRollBackOnly it's still happened :( This shouldn't be the