Skip to content

Container Managed Transaction, EJB 3 and Exceptions

Let‘s face it. Exceptions in Java have always been a nightmare because we‘ve never known how to handle them properly. Hundreads of articles and thousands of blogs have tried to help us on “how to use exceptions in Java“. We went from “all exception should be checked“ to “all shoud be unchecked“ and then to “business exception should be checked and technical exceptions unchecked“, “each layer should wrap the parent exception“, “just throw it to the client”… hummm… I‘m not even sure if I agree with all that. On top of all that, Java EE 5 has arrived with a new annotation that can confuse even more the way exceptions should be handled. You can now annotate an exception with @ApplicationException. It is a nice way to distinguish application exceptions from system exceptions. Before we would assume that checked exception would be application exception and unchecked system exception. It‘s not the case. An application exception can be a subclass of java.lang.Exception (checked exception), or of java.lang.RuntimeException (unchecked exception). The only constraint is that an application exception cannot be a subclass of java.rmi.RemoteException (therefore javax.ejb.EJBException In terms of transactions, how does it work? Let‘s take a simple example that I‘ve used in a previous post with two stateless EJBs. ABean (persists a A object) and BBean (persists a B object). ABean calls BBean both using the default TransactionAttributeType.REQUIRED @Stateless public class ABean implements ARemote { @PersistenceContext private EntityManager em; @EJB private […]

Read More →

Container Managed Transaction – Mind the interface

We‘ve been using EJBs for a long time now and, thanks to Java EE 5, it‘s today even easier to do so. What happens when you are comfortable with something ? You forget the basics. And the basics are, J2EE 1.4 or Java EE 5, an EJB runs inside a container. This container can do a lot for you, transactions for example, but you have to make sure you use the container. Let give me an example of a common mistake. Imagine that you have two Stateless EJBs, each one persisting an object. To make it simple I‘ll call them ABean (persists a A object) and BBean (persists a B object). Here is how it works : 1 – The ABean.createsA() method starts a transaction and calls the BBean.createsB() method (1) 2 – The BBean.createsB() method persists a B object and returns it (2) 3 – The ABean persists a A object using B, commit all changes and end the transaction (3) Everything should be smooth, your data is committed, and you‘ll get an A and a B in your database. What happens if the BBean.createsB() method uses TransactionAttributeType.NEVER ? ABean starts a transactions (_TransactionAttributeType.REQUIRED_ is the default), calls BBean but BBean refuses to be part of the transaction and throws an Exception (_RemoteException: EJB cannot be invoked in global transaction_). The transaction is rolled back, no A or B objects are persisted in your database, great, CMT works fine, […]

Read More →

I am now an Expert Member of the JCP

The Java Community Process or JCP, established in 1998, is a formalized process which allows interested parties to be involved in the definition of future versions and features of the Java platform. For a long time it has been closed to big companies, but now it’s opened to individuals. As I am passionate for the Java EE platform, I’ve applied to be a member of the Java EE 6 (JSR 316), JPA 2.0 (JSR 317) and EJB 3.1 (JSR 318)… and I’ve been accepted. It’s really stimulating to share knowledge and ideas with the main actors. I hope to make a contribution too.

Read More →

Intellij Idea is really Groovy

I‘ve been an Intellij Idea follower for more than 5 years now. I’ve never really made the move to Eclipse, unless I really have to on rare occasions. Here is another example of how good Idea is. I’ve been developing a little bit with Groovy and recently with Grails. I was sad not to see any Groovy features in the […]

Read More →

Signing copies of my book

Saturday the 30th of June I’ll be at the book shop Le Monde en Tique in Paris signing copies of my book from 3:30pm to 6pm. Thanks to Jean Demetreau for organizing this event. So, if you want to have a drink, talk about Java EE 5 and even buy a book and get it signed, it’s the right moment, […]

Read More →

Signing copies of my book

Saturday the 30th of June I‘ll be at the Parisian library Le Monde en Tique signing copies of my book from 3:30pm to 6pm. Thanks to Jean Demetreau for organizing this event. So, if you want to have a drink, talk about Java EE 5 and even buy a book and get it signed, it‘s the right moment, at the right place (the library is really nice and you can even see Notre Dame)

Read More →

Online chat about the book

On Tuesday the 5th of June from 5pm to 6pm French time, the Journal Du Net is organizing a chat (in French) about the Java EE 5 book I wrote. I’ll be on the other side of the computer answering questions about the content of the book but also Java EE 5 in general. You just have to enroll first […]

Read More →

Java EE 5 Book Chat

Next Tuesday from 5pm to 6pm French time, the Journal Du Net is organizing a chat (in French) about the Java EE 5 book I wrote. I’ll be on the other side of the computer answering questions about the content of the book but also Java EE 5 in general. You just have to enroll and be ready on Tuesday afternoon. See you there.

Read More →

Java EE 5 Book

Presentation

Java Enterprise Edition appeared end of the Nineties and brought to the Java language a robust platform for companies' enterprise applications. Put into question on each new version, badly understood or misused, competed by open source frameworks, Java EE knew to use these criticisms to improve and find a balance in its version 5. This book proposes to discover the innovations of this new version, and to examine how to assemble them to develop an e-commerce website.

The objective of this book is to guide you in the development of a complete e-commerce website using Java EE 5, while answering the question "how to assemble these specifications? ". The application, inspired from the Java PetStore of Sun, follows the coding and architecture best practices: layers, loose coupling, and enterprise design patterns.

Read More →

Java EE 5

Présentation

Java Enterprise Edition est apparu fin des années 90 et a apporté au langage Java une plate-forme robuste pour les applications d'entreprise. Remise en cause à chaque nouvelle version, mal comprise ou mal utilisée, concurrencée par les frameworks open source, elle a su utiliser ces critiques pour s'améliorer et trouver un équilibre dans sa version Java EE 5. Ce livre propose de découvrir les nouveautés de cette nouvelle version, et d'examiner comment les assembler pour développer un site de commerce électronique.

L'objectif de cet ouvrage est de vous guider dans le développement d'un site complet de commerce électronique en Java EE 5, tout en répondant à la question « comment faire pour assembler ces spécifications ? ». L'application, inspirée du Java PetStore de Sun, suit les règles de l'art en matière d'architecture : découpage en couches, couplage lâche, et design patterns d'entreprise....

Read More →

Java EE 5 Book is out

Just to let you know that the book I wrote about Java EE 5 is out. I‘ve blogged before about its content and I’ve also written a presentaion on my web site. The book helps expert Java developers to write an e-commerce website with the lastest Java EE 5 specifications (EJB 3, JPA, JSF, JSP, JMS, JavaMail) running on GlassFish and Derby. The book is written in french but english speaker can also download the code of the application and follow the instructions to install and run the application. For french readers (or any person willing to learn Java EE 5 and french at the same time) you can buy it online at Eyrolles or Amazon

Read More →

Java EE version history: Help Needed !!!

I was trying to do a study about the evolution of Java in terms of the langage (how many versions, how many APIs in each version, main features…), its popularity (how many book written in the last 10 years, evolution of the market, job offers in the last 10 years…), its enterprise version (versions of J2EE, how many specifications in each version…)… but I‘m giving up. Too difficult. I will spend the next years trying to read articles, compare figures, sort out dates. Java is evolving fine, full stop. In my research I found a very good article on Wikipedia about Java version history. Because the same information on JEE was missing I’ve created a new article called Java EE version history. It‘s just a start and it needs alot of work still. If anybody is willing to help on that, feel free.

Read More →

Article: Generate an XML Document from an Object Model with JAXB 2

I‘ve just published an article about JAXB 2 on DevX web site. JAXB (Java Architecture for XML Binding) allows you to perform XML-to-Java data binding and generate Java classes from XML schemas and vice-versa. But in this article I mainly focus on marshalling (generate XML from Java objects). You will see how easy it is to generate XML without doing much (thanks to coding by exception). Then, I introduce a set of annotations that enable to customize the XML mapping. At the end of the article I make a reference to two other articles I wrote on JPA. Because I’ve used the same object model on all articles, I give an example of a class that can be persisted in a database using JPA annotations and binds to XML using JAXB annotations. As I’ve blogged before, this over used of annotations can be dangerous because code gets pretty messy. If you have specific needs, it‘s good to know that you can do it (JPA & JAXB in the same class). Otherwise, you should focus on modeling your classes with the right responsabilities.

Read More →

Java EE 5 at the Sun Tech Days in Paris

During the Sun Tech Days2007 in Paris there was a GlassFish user group conference. There I made a presentation about Java EE 5. Based on my book I explained how a JSP could talk to an EJB 3 using JSF and JPA. You will a little more details about the event on my blog.

During this event I met the developpez.com team. For those who don't know it developpez.com is a very famous french website for developpers. Vincent Brabant interviewed me and Emmanuel Puybaret who wrote a couple of good book about Java and Swing.

Read More →

Learn Java EE 5 at Sun Tech Day (Paris)

Just to let you know that I will be presenting my book at the GlassFish Community User Group during the Sun Tech Day in Paris. It will be a quick 15 minutes talk called Learn Java EE 5 on Wednesday the 21th of March around 11 am. I know, 15 minutes is a bit quick to learn Java EE 5, that‘s why you will have to buy my book (if you read French of course). I would like to thank Alexis Moussine-Pouchkine for giving me this opportunity as well as my editor Eyrolles for letting me talk about a book that is not yet published (planed for mid-april). See you at the conference.

Read More →

Java Black Belt will be at university

Few weeks ago I‘ve posted about trying Java Black Belt at the University to test the level of our students. We made 40 students take 3 exams (JSP, Servlet and EJB) and got their feedback. Being French students we had some “I didn‘t understand every questions”. We decided not to take that into account because engineering students should have a good technical English understanding. Some students thought the tests were too difficult, some thought they were easy… but all thought it was a good way to know about certifications (some mentioned Sun certifications). With the teachers involved in this test we decided to use Java Black Belt at the beginning of each semesters to test the knowledge of our students. Clearly, if some student terribly fails we will ask him/her to go back to the library and read a couple more books. I want to thank John Rizzo and Gonzague Lefere who gave us the opportunity to do this test. These guys have had a great idea, Java Black Belt rocks and I hope it will have a certification recognition within the Java world.

Read More →

Why is JavaPolis so cheap (or why are IT conferences so expensive)

I‘ve been playing a bit with Groovy and I‘ve attended a Grails presentation done by Guillaume Laforge back in January. I thought it was really good and when he mentioned the Grails conference in London I thought “Let’s go! The conference is in May, just during my birthday, I love London, I have plenty of friends there, it would be a good oportunity to know a bit more about Grails, meet people at the conference and have some English and Irish beer” . Recently the registration opened and to my surprise I saw that the first International Grails eXchange 2007 conference is at 1000 euros (700£). I compared the price with the conferences in the near future and this is what you can get for a 3 days conference: 1350 euros ($1795) to go to TheServerSide Java Symposium-Europe in Barcelona, 1694 euros to JAOO, 1742 euros to QCon or 1350 euros ($1795) to Java One. Plus travel and hotel costs obviously. I can’t believe JavaPolis was only 200 euros for such a good conference. Is there a reason why JavaPolis, a huge Java conference (2800 participants in December), was at 200 and the first Grails conference is at 1000 ? I know London is an expensive place, the Barbican center must charge quite a bit, but why are IT conferences so expensive in general? Stephan Janssen, can you tell us your secret?

Read More →

Demo of the Petstore application

In the Java EE 5 book, you will have to develop a web and a swing application that talk to an EJB 3 back end. In this Flash animation, you’ll see how to use the Petstore web application. First It browses the catalog of pets, then logs a user on, who buys a few animals, adds them to my shopping cart, changes some quantities of the shopping cart and then checks out. In this animation you can see the administration console. It is developed in Swing and used to create/modify/remove items of the catalog as well as having a view on customer and orders.

Read More →

www.javasoft.com

I was clearing my old bookmarks and adding them to magnolia when I realized that Java Technology was pointing to www.javasoft.com. A long time ago (1998/1999) that was the link to java.sun.com. So now, if you type www.javasoft.com you’ll be automatically redirected to java.sun.com. Even on Wikipedia, if you type JavaSoft you’ll be forwarded to Sun Microsystem. There is just Webopedia that tells you that JavaSoft is the business unit of Sun Microsystems that is responsible for Java technology . Is that true? Am I the only one to still use java.sun.com? Have I been using Java for too long? Time to change? Time to be more Groovy maybe ;o)

Read More →

Installer l’application

Présentation

Le livre Java EE 5 vous permet de développer une application de commerce électronique en utilisant de multiples spécifications Java EE 5. Tout au long des chapitres vous devez développer couche après couche (persistance, session façade, interface web, gestion du panier électronique, services web et traitements asynchrones) pour obtenir le site de vente d'animaux domestiques.

Téléchargez le code

Avant toute chose, il vous faut télécharger le code de l'application pour l'exécuter.

Structure des répertoires

Décompressez le fichier que vous venez de télécharger et vous obtiendrez trois sous-répertoires principaux. Ceux-ci correspondent aux différentes applications :

Read More →

Les critiques du livre Java EE 5

DZone avril 2008

Une fois n'est pas coutume, une revue de presse d'un site anglo-saxon. Un grand emerci à David Sills de l'équipe de JavaLobby qui, connaissant un peu le français, a fait l'effort de livre un ouvrage qui n'est pas écrit dans sa langue de prédilection. De plus, la critique est très bonne.

Un extrait : To be honest, I'd like to have this book in English for newbies in the field! We'd have a lot better applications built, I can say that.

DZone

Read More →

Installer l’application sur MySQL

Présentation

L'application développée pour le livre utilise le serveur GlassFish et la base de données Derby. Pour installer l'application sur la base de données MySQL il faut effectuer quelques changement.

Installez et configurez MySQL

Tout d'abord, il faut installer MySQL 5. Pour cela, rendez-vous sur le site de MySQL et téléchargez la version dédiée à votre plateforme. Démarrez la base de données et connectez vous à celle-ci via l'éditeur (mysql -u root). Il faut ensuite créer la base petstoreDB et la rendre accessible à l'utilisateur dbuser (mot de passe dbpwd).

Read More →