Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying EJB 3 Developer Guide
  • Table Of Contents Toc
EJB 3 Developer Guide

EJB 3 Developer Guide

By : Michael Sikora
4.2 (6)
close
close
EJB 3 Developer Guide

EJB 3 Developer Guide

4.2 (6)
By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
close
close
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
chevron up
1
Annotations and Their Corresponding Packages

Preface

Enterprise JavaBeans (EJB) technology is a core part of the Java EE 5 specification. EJB is a framework for building enterprise-scale object-oriented, distributed, component-based business applications. EJB business applications are written in Java, are scalable and can be deployed on any platform that supports the EJB specification.

EJB applications are deployed to and execute under the control of an EJB container. The EJB container provides services typically required by enterprise applications such as security, transaction management, resource pooling, and systems management.

The EJB 3 specification, released in May 2006, is a radical change from previous versions of the technology. Developing business applications is considerably easier with EJB 3. The handling of persistence in particular has radically changed in EJB 3. Persistence is no longer a service provided by an EJB container but rather by a persistence provider conforming to the Java Persistence API (JPA) specification. Java applications which need to be persisted but which do not require the services provided by an EJB container can be persisted outside an EJB container by a JPA persistence provider. In this book we cover JPA as well as the core EJB 3 services.

This book is a concise, example-driven introduction to EJB 3. The best way to learn a new software technology is by studying and trying out programming examples. In this book you will see a lot of code and one example after another. We do not assume any prior knowledge of EJB. However this book does assume at least a couple of years’ experience of Java and some knowledge of relational database technology. The examples in this book have been deployed on the GlassFish application server. GlassFish was chosen primarily because this is the Java EE 5 reference implementation.

What This Book Covers

Chapter 1 Introduction to EJB 3—A general overview of the Java EE architecture including EJB container services, the JPA persistence engine, and initial installation of the GlassFish application server.

Chapter 2 Session Beans—Creation of a session bean and its client and examples of running it from the application client container. Exploring the program directory structure. Packaging and deploying a session bean. A look at the stateless and stateful session beans lifecycle.

Chapter 3 Entities—Exploring EJB 3 entities. How to package and deploy entities and map an entity to a database table. Metadata defaults and how to override them. Generating primary keys.

Chapter 4 Object/Relational Mapping—One-to-one, one-to-many and many-to-many associations. Default object/relational mapping values and how to override them. Object/relational inheritance mapping and additional annotations.

Chapter 5 JPQL (Java Persistence Query Language)—Looking at different groups of queries including aggregate functions, queries with relationships, subqueries, queries with parameters and named queries. JPQL joins and functions are also explained.

Chapter 6 Entity Manager—Looks in detail at the entity manager. Covers both the EJB 3 container-managed and application-managed entity managers.

Chapter 7 Transactions—ACID properties and isolation levels. Container-managed transactions. Bean-managed transactions.

Chapter 8 Messaging—Looks at the JMS (Java Messaging Service) API. Examples of queue producer and queue consumers. Topic producer and consumers. Message driven beans: their activation configuration properties, lifecycles and transactions.

Chapter 9 EJB Timer Service—Examples of single and interval events. Timer interface methods. Timers and transactions.

Chapter 10 Interceptors—Covers interceptor methods, classes and interceptor communication as well as default interceptors.

Chapter 11 Implementing EJB 3 Web Services—An overview of web service concepts and the web service definition language (WSDL). Creating and deploying a Java application as a web service. Creating and deploying an EJB session bean as a web service. Creating a web service client.

Chapter 12 EJB 3 Security—A look at security, GlassFish authentication, declarative and programmatic EJB authorization and Web Tier authentication and authorization.

The Appendix shows EJB 3 annotations described in this book with their corresponding packages.

What You Need for This Book

First you must have version 5 or higher of the Java Development Kit (JDK). This can be downloaded from http://java.sun.com/javase/downloads/index.jsp.

You also need a version of Ant equal to or higher than 1.6.5. Ant is a tool for building Java programs, similar in concept to the Unix Make tool, except that it is platform independent. Ant is part of Apache’s Jakarta project. If you are unfamiliar with Ant you should look at the Ant web site (http://ant.apache.org/). If you do not have Ant there is no need to download it as the GlassFish application server includes a copy of Ant.

Finally you need a version of GlassFish equal to or higher than V2b41d. This can be downloaded from https://glassfish.dev.java.net//.

Instructions on setting up environment variables and installing GlassFish are given in the "Getting Started" section in Chapter 1.

Who Is This Book For

Previous experience of working with Java is essential and knowledge of relational databases is desirable.

This book is primarily aimed at professional developers who already have a working knowledge of Java. Enterprise architects and designers with a background in Java would also find this book of use.

As this book is an introduction to EJB 3, it is aimed at those who are new to EJB 3. However, as the new version of EJB is so radically different from the previous version (EJB 2.x), the book would also be suitable and of interest to those who have had experience working with EJB 2.x. The text makes it clear where the differences between the versions of EJB lie, although it is not explored in detail.

Approach of this Book

This book has been written for developers new to EJB 3 who want to use the technology. Such readers usually want to see examples and program code. In this book we work through one example after another and we show lots of program code. If you are new to a technology and have looked at your first HelloWorld example, the next thing you want to do is to code and run the program yourself. In the case of EJBs this also means packaging and deploying the EJB to a container. Although we promise no HelloWorld examples in this book, we look at packaging and deployment straight after coding our first EJB, rather than ignoring these topics or leaving them to the end of the book.

All the source code together with packaging and deployment scripts is available from the book's web site.

This book is not a reference book, so we don't attempt to cover all EJB 3 features. We've kept this book concise to help you quickly get up and running with EJB 3.

Although an EJB will run in any EJB container, the deployment process is container-dependent. This means that we need to pick a specific container for our examples. Sun's open-source, free GlassFish container was chosen primarily because this was the Java EE reference container implementation and also because GlassFish has Toplink embedded. Toplink in turn is the reference JPA persistence engine.

We also chose not to use an IDE (Integrated Development Environment) partly because they are all quite different. A book based on IDE A would be of little use to a reader using IDE B. As IDEs are screen-based navigational tools, any resulting book would contain a large number of screenshots and would be at least double in length. More importantly is the author's view that an IDE is not an ideal learning tool. Apart from having to learn to navigate through a large number of screens, often an IDE will hide the underlying EJB technology. Of course once you have learnt EJB an IDE will make you much more productive in your work.

Instead we use the Ant build tool for compiling, packaging, deploying, and running our EJBs.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We name our interface TimeService.java, which contains a single method definition getTime() ."

A block of code will be set as follows:

@Stateless
public class TimeServiceBean implements TimeService {
public String getTime() {
Formatter fmt = new Formatter();
Calendar cal = Calendar.getInstance();
fmt.format("%tr", cal);
return fmt.toString();
}
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

@Stateless
public class TimeServiceBean implements TimeService {
private @EJB NiceDayService niceDay;
public String getTime() {
Formatter fmt = new Formatter();
Calendar cal = Calendar.getInstance();
fmt.format("%tr", cal);
return fmt.toString() +
niceDay.getMessage();
}
}

Any command-line input and output is written as follows:

C:\EJB3Chapter02\glassfish\lab1\build>jar -tvf TimeService.jar

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: " Under the Web Services heading in the Common Tasks pane on the left of the screen, click on Arithmetic ."

Note

Important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit http://www.packtpub.com/files/code/5609_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Questions

You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
EJB 3 Developer Guide
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon