ejb-3.1

EJB 3.1 @EJB Injection into POJO

谁说胖子不能爱 提交于 2019-12-17 15:46:29
问题 With the new EJB 3.1 spec is it possible to inject an EJB into a pojo? I know in EJB 3.0 the @EJB annotation could be used to inject an EJB but this did not work on simple pojos. If it is not do I have to look the bean up in JNDI as I know you cannot simple use the new keyword. 回答1: Yes, use JNDI lookup. Since your POJO is created by you (I assume), the container is not responsible for injecting the dependencies. 回答2: With the new EJB 3.1 spec is it possible to inject an EJB into a pojo? I

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

Define and inject a map in EJB 3.1 or CDI

心已入冬 提交于 2019-12-14 02:47:20
问题 After several years developing in Spring, I switched to EJB and I am not happy that I have no solution for this use-case. Let's say it is the strategy pattern implemented by a map. In Spring, it could look like this. <bean id="myBean" class="MyBeanImpl"> <property name="handlers"> <map> <entry key="foo" value-ref="fooHandler"/> <entry key="bar" value-ref="barHandler"/> </property> </bean> In EJB/CDI, I have this. @Stateless public class MyBeanImpl implements MyBean { private Map<String, Class

how to access a @Stateless @LocalBean remotely

旧巷老猫 提交于 2019-12-13 18:36:04
问题 I'm following an EJB cookbook, from packt, with the following code: package packt; import javax.ejb.Stateless; import javax.ejb.LocalBean; //@Stateless @LocalBean @Stateless(mappedName="salutationBean") public class Salutation { public String getFormalSalutation(String name) { return "Dear " + name; } public String getInformalSalutation(String name) { return "Hi " + name; } } How do i access this bean from a class which doesn't extend HttpServlet ? The servlet itself works fine: package

AngularJS application with EJB only

江枫思渺然 提交于 2019-12-13 18:18:10
问题 Is it possible to build AngularJS application with only EJB directly without having to expose them as REST services? What I have seen on examples on the web is that in the end you have to use REST services to supply data to AngularJS. Hence you would have to expose your EJB methods as RESTful services to be able to make them work with AngularJS. Is there a way without doing this? Please suggest and provide some help resources if any. We are using EJB 3.1 and IBM WAS 8.5. 回答1: First, you must

Looking up an EJB dynamically

百般思念 提交于 2019-12-13 16:23:02
问题 I'm developing an application on Glassfish 3. I have an EJB that looks like this: @LocalBean @Stateless public class MyBean { public void doSomething() {} } My client code (running inside the same application) looks like this: MyBean mb = (MyBean) InitialContext.doLookup(MyBean.class.getName()); According to a few sources, this should be a valid lookup method, but it throws a NameNotFoundException. What am I doing wrong? 回答1: According to what sources? I would personally use portable JNDI

Can I use EJB Stateless Bean with CDI to maintain user session?

强颜欢笑 提交于 2019-12-13 15:12:00
问题 Based on this post http://www.adam-bien.com/roller/abien/entry/ejb_3_1_killed_the I use in my app @Named @Stateless bean for communication with a database (injecting EntityManager here) and display information on a jsf page. It's great facilitation since Java EE 5, but I have one question. Is it secure to use such beans for maintaining a user session (shopping cart etc)? I read a book about ejb 3.0 and I know that the same stateless bean could be used with many clients. What's the best

Problem using Stateful EJB in ManagedBean with RequestScope

旧巷老猫 提交于 2019-12-13 13:33:19
问题 I'm using JSF 2.0 and EJB 3.1 in the Glassfish v3 app server. And I'm facing actually the follwing problem: In a MenagedBean with RequestScope I want to access a session object (an EJB with @Stateful) which should store some session relevant information as the seleced category, the seleced page (with a datatable paginator for each category), etc. - nothing special I think. The first time a category is selected, the datatable is created and displayed. Allright so far. Now, if an item (row) is

Good way of managing database entity manager

烂漫一生 提交于 2019-12-13 07:03:09
问题 Following recommendations given to me in this thread I am making my DAO accessors @Singleton, @Startup, @LocalBean My question is on the good way to implement the entityManager that is supposed to execute the various queries. Knowing that there are several Dao's, but they shall all point to the same entityManager (also created from a single entityManagerFactory), what's the best practice ? This is so far my implementation, but I have a feeling that it is reeeeealy bad :) Dao's @Singleton

Glassfish doesn't bring up EntityManager if DAO is not Stateless

谁说我不能喝 提交于 2019-12-13 04:14:50
问题 I have an EAR application with an EJB module, that contains one persistence unit and many EJBs (as service and DAO layer). @Stateless public class BranchDAO { @PersistenceContext private EntityManager entityManager; } But DAOs as Stateless beans are not recommended. So I create this annotation using CDI: @Dependent @Stereotype @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface DAO { } After my DAO is changed to not use @Stateless : @DAO public class BranchDAO {