What to put into jta-data-source of persistence.xml?

The problem is that Persistence.createEntityManagerFactory(“abc”) is the “do it yourself” API and doesn’t take advantage of the Embedded EJB Container. You can get a container managed EntityManager in your test case very easily. Just as with the related jndi/datasource question I recommend you check out the examples in the examples.zip. They’re all designed to take … Read more

Why is PostConstruct not called?

The Java EE bean annotations such as @PostConstruct only apply to container-managed beans. If you are simply calling new BlogEntryDao yourself, the container isn’t going to intercept the creation and call the @PostConstruct method. (Furthermore, you’d be better off using @PersistenceContext or @PersistenceUnit instead of manually fetching the EntityManagerFactory in your initialize() method, and you … Read more

Is it discouraged to use Java 8 parallel streams inside a Java EE container?

A heads up, the graceful degradation to single thread is not available. I also thought it was because of Shorn’s answer and that mailing list discussion, but I found out it wasn’t while researching for this question. The mechanism is not in the Java EE 7 spec and it’s not in glassfish 4.1. Even if … Read more

Difference between Javabean and EJB [duplicate]

Java bean is just a set of conventions. EJB is a standard for J2EE business components. Specifically a Java bean: has a public default constructor; readable property methods precedes with “get”; writable property methods precedes with “set”; and is Serializable. For example, a Java bean with a property of “margin” would minimally look like this: … Read more

JSF Controller, Service and DAO

Is this the correct way of doing things? Apart from performing business logic the inefficient way in a managed bean getter method, and using a too broad managed bean scope, it looks okay. If you move the service call from the getter method to a @PostConstruct method and use either @RequestScoped or @ViewScoped instead of … Read more

What does the @EJBs annotation do?

The @EJB annotation (and @Resource, @WebServiceRef, etc.) serves two purposes: It declares a reference in the component namespace. For example, @EJB(name=”myEJB”) creates a reference java:comp/env/myEJB. If you annotate a field and do not specify a name, then it creates a reference java:comp/env/com.example.MyClass/myField. If the annotation is declared on a field or setter method, then the … Read more

Difference between @Stateless and @Singleton

You’re seeing the same output because there is only one client accessing the EJB at a time. The application server is able to recycle the same stateless EJB object for each call. If you try a concurrent access – multiple clients at the same time – you’ll see new stateless instances appearing. Note that, depending … Read more