An EntityManager can be injected directly into an EJB using the @javax.persistence.PersistenceContext annotation. By default, a transaction-scoped persistence context is injected. You can override the default with type() attribute. When the transaction is completed, the EJB container will perform the cleanup. The extended entity manager can only be injected into a stateful session bean.

As mentioned in part 1 of the article, the EntityManager is the central service for all persistence actions. The persistence actions can be summarized as follow:
The javax.persistence.EntityManager is the central service for all persistence actions. Entity beans are plain Java objects that interact with EntityManager to make them persistent. EntityManager has the following role:
- manages the object-relational mapping between a fixed set of entity classes and the underlying data source.
- provides APIs for creating queries, finding objects, synchronizing objects and inserting objects into the database.
- provides caching and manage the interaction between an entity and transactional services.
- tracks state changes to the entity bean.
EntityManager manages persistence context, a set of entity bean instances. When the persistence context is closed, all managed entity objects become detached and are unmanaged.
Message-driven beans are specially designed to consume JMS messages. It is not advisable to “force” a session bean into this role. They are stateless, server-side, transaction-aware components for processing JMS messages. The EJB container manages transactions, security, resources, concurrency and message acknowledgment for MDBs.
All EJB 3.0 containers must support JMS provider and other providers through JCA (for Connector-based MDBs). In order to send a JMS message, we need a connection to the JMS provider and a destination address for the message. Using a connection factory javax.jms.ConnectionFactory similar to javax.sql.DataSource, you can create a connection to the JMS provider.

Each stateful session bean is dedicated to one client for the life of the bean instance. Stateful session beans are primarily used to encapsulate and manage task flow on behalf of the client - they manage the interactions of other beans for the client.
Stateful session beans do not use instance pooling. Each stateful session bean must be passivated before it is evicted from memory in order to preserve the conversational state of the instance. It must then be activated when the bean becomes active again. The process achieves certain level of resource pooling but it is different from stateless session bean’s instance pooling.

The lifecycle of a stateful session bean that do not implement javax.ejb.SessionSynchronization interface can be summarized as follow:
Stateless session beans are lightweight and fast and require no passivation and activation. Therefore, they are particularly suitable for any activity that can be accomplished in one method call, such as report generation, credit card validation and batch processing.
Stateless session beans maintain no state from one method invocation to the next. They have longer timeout period because they are not dedicated to one client. A timeout or removal operation invalidates the EJB object reference but may not destroy the bean instance. A client can also explicitly remove a stateless session bean by invoking a business interface annotated as @javax.ejb.Remove.
Stateless session beans have only two states - Does not Exist and Method-Ready Pool. The actions on the transition of both states include
Class.newInstance()- injections
- (callback)
@javax.annotation.PostConstructor<post-construct>inejb-jar.xml - (callback)
@javax.annotation.PreDestroyor<pre-destroy>inejb-jar.xml
I will be writing a series of articles related to EJB 3.0 in preparation for my SCBCD exam. The main objective is to keep updating the site while studying intensively for one month. The notes are prepared by reading through Enterprise JavaBeans 3.0, Fifth Edition by Bill Burke and Richard Monson-Haefel.
Entity Bean
In EJB 3.0, persistence has been spun off from EJB to its own specification called Java Persistence API. The API defines a way to map plain old Java objects (POJOs) to a database. These plain old Java objects are called entity beans.
The Java Persistence API also defines EJB QL that is tailored to work with Java objects rather than a raw relational schema. Entity beans are different from EJB session beans in that they are POJOs. They do not have a remote or local interface and can be accessed only as POJOs.
In order to “make” a POJO class as an entity bean class, you need to tag the class with @javax.persistence.Entity annotation and have at least one field or getter method that is designated as the primary key using @javax.persistence.Id annotation. All access to an entity goes through EntityManager persistence service that provides query API and life cycle methods.
Continue reading ‘SCBCD Notes: EJB & Java Persistence Architecture’
Happy Thanksgiving to all.
CodeGear announced JBuilder 2007 on Monday, 20 Nov. Who is CodeGear? It is a subsidiary of Borland, which is so new that its official web site is not yet ready. The new subsidiary will focus on developer productivity market while its parent company, Borland continues to grow on Application Life Cycle Management (ALM) market.

Just a week after CodeGear is formed, the young company announced the latest JBuilder that is built on Eclipse 3.2.1 core. The “enhanced” version of Eclipse delivers better plug-in management, enhances enterprise customer support and brings JBuilder innovations to Eclipse. CodeGear hopes that by offloading the maintenance of development tools, potential customers are willing to pay a fee to have a peace of mind.
The IDE is carefully crafted to address the software development trend. Open source is more pervasive than ever and development teams are increasingly distributed around the world. The trend creates a need to collaborate among developers. The easiest solution is to integrate collaboration tools right into the IDE. JBuilder 2007 includes TeamInsight, an integrated collaboration portal and Project Assist that extends far beyond just writing codes.
Ignition Interlock Device: A Concise Overview
0 Comments Published November 22nd, 2006 in Infrastructure.
Mothers Against Drunk Driving (MADD) and the U.S. Department of Transportation with the backing of car manufacturers such as Volvo and SAAB is set to launch a new campaign against drunk driving by mandating a Ignition Interlock Device on every car.
The device is effective to repeated offenders but expensive to nondrinker. Since July 2004, more than 75,000 Ignition Interlock Devices (IIDs) were installed in the U.S. because of DUI and DWI convictions.
What exactly does the device offer? Let’s take Guardian Interlock Systems as an example. The company has been in the business since 1985 and the first to introduce the device in California.
Continue reading ‘Ignition Interlock Device: A Concise Overview’
Second Life is a 3-D virtual world entirely built and owned by over 1.5 million residents. It is digital community where members interact, buy and sell goods, and build property worth real money. 250 of the in-world currency the Linden dollar can be converted to one US dollar at online currency exchanges, LindeX.
Recently, the virtual world began to face nasty troubles - crimes inside and outside the virtual world. The BBC reported that it had to close its doors for a short time on Sunday (19 Nov) after a worm attack called grey goo. The worm is presented as a golden ring inside the virtual world that replicates by user interaction slowing down the game servers.
The troubles do not stop here. A program that is designed to quickly copy characters, objects and buildings are eroding the value of people’s virtual property. A growing numbers of mafias and gangs in the virtual world are also seriously disrupting the law and order in the virtual world.
XBRL or Extensible Business Reporting Language is a member of the family of languages based on XML, which is a standard for the electronic exchange of data between businesses and on the internet. The rich and powerful structure of XBRL allows very efficient handling of business data by computer software as well as human reading (example).
XBRL International, the organization that focuses on the progress of XBRL, has 15 established jurisdictions and 6 provisional jurisdictions across the globe. The organization publishes two documents about XBRL - XBRL Specification and XBRL Taxonomies. Each jurisdiction promotes XBRL and organizes or sponsors the creation of taxonomies, notably for the main accounting standards for business reporting in its area.
The latest Recommended Specification was updated on 7 Nov 2005 with a version number of 2.1. With the support of more about 450 major companies, organizations and government agencies, XBRL is steadily getting its place in the global business community.