How to add a Selector with MDB 3.0 ?

Message selectors allow an MDB to be more selective about the messages it receives from a particular topic or queue. Message selectors use Message properties as criteria in conditional expressions. These conditional expressions use Boolean logic to declare which messages should be delivered to a client. With MDB 3.0 it’s easier to configure a selector … Read more

How can I retrieve the id of a Transaction started by JBoss ?

Sometimes it an be useful for debugging purpose to retrieve the id of a transaction; one typical scenario could be a transaction started by an EJB deployed as CMT. The javax.transaction.TransactionManager interface provides two ways to fetch the transaction id: The simplest strategy is to call the toString method to print complete information about the running … Read more

Versioning Entity with Hibernate Envers

The Envers project aims to enable easy auditing/versioning of persistent classes. This can simplify storing and retrieving historical sets of data from the DB. Similarly to Subversion, Envers has a concept of revisions. Basically, one transaction is one revision (unless the transaction didn’t modify any audited entities).   As the revisions are global, having a revision … Read more

How to create a MDB 3.0 singleton ?

You can specify the maximum number of JMS Sessions that are available to concurrently deliver messages to an MDB using the maxSession property. Here is an example: @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = “maxSessions”, propertyValue = “1”), @ActivationConfigProperty(propertyName = “destinationType”, propertyValue = “javax.jms.Queue”), @ActivationConfigProperty(propertyName = “destination”, propertyValue = “TASK.QUEUE”) }) public class BuildTasksMessageListener implements MessageListener { … Read more

How to set EJB timeout period ?

EJBs support two types of transaction management: Container managed and Bean managed. Container managed transactions provide a transactional context for calls to bean methods, and are defined using Java annotations or the deployment descriptor file ejb-jar.xml. Bean managed transactions are controlled directly using the Java Transaction API (JTA) . In both cases, you can set … Read more

EntityListeners in your Entity made simple

It is often useful for the application to react to certain events that happen inside the persistence mechanism. The JPA specification provides a simple mechanism for that: you can add the  @EntityListeners annotation to capture persistence events in callback methods. Example: Consider the following Note class: import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; … Read more

How to schedule EJB automatic Timers

Automatic timers are created by the EJB container when an enterprise bean that contains methods annotated with the @Schedule or @Schedules annotations is deployed. An enterprise bean can have multiple automatic timeout methods, unlike a programmatic timer, which allows only one method annotated with the @Timeout annotation in the enterprise bean class. Automatic timers can … Read more

Developing MDB with WildFly / JBoss EAP

MDB are a type of Enterprise Beans that are able to asynchronously deliver messages sent by any JMS producer. In this tutorial we wil learn how to develop and deploy a Message Driven Bean on the top of WildFly Application Server or JBoss EAP.

Read more

Configuring Timeout policies for your EJBs

In the most recent version of WildFly (20) it is now possible to configure a default timeout setting for all your Stateful beans. Let’s recap in this article all timeout policies you can define for your EJBs: StatefulTimeout: This timeout policy is used to force passivation of Stateful beans which are inactive for a certain … Read more

WildFly: How to call an EJB from an EJB located in another application

The purpose of this tutorial is to demonstrate how to lookup and invoke an EJB deployed on an WildFly server instance from another EJB located in another application. Here is our scenario: If, on the other hand, your scenario requires invoking an EJB from a standalone remote Client, then check this tutorial: WildFly remote EJB … Read more