Why EJB 3.1 And CDI Are Good Java EE 6 Friends

Are EJB 3.1 still needed, when we already have CDI? I tried to answer this question in an article with the short and concise title :-): Enterprise JavaBeans 3.1 with Contexts and Dependency Injection: The Perfect Synergy. Feedback is, as always, very welcome!

Comments:

Thank you for the article. Finally I learned how CDI and EJB work together.

Posted by Stan Svec on October 06, 2010 at 03:25 PM CEST #

Hi Adam,

I think when building "simple" JSF applications, without having the need for EJB 3.1, then CDI is sufficient.

But I would not consider them as "good friends". There are more like mates or pals :-) They just don't get along in some cases (e.g. scopes).

Or maybe they are lovers? The great EJB guy meets the sensitive CDI lady?

Anyway... gluing them together and working with the result in Java EE 6 is fun :-)

Posted by Sascha on October 07, 2010 at 04:58 PM CEST #

@Sascha,

"I think when building "simple" JSF applications, without having the need for EJB 3.1, then CDI is sufficient."

If simple == no database and no transactions, than you are right. In other cases a "simple" EJB 3.1 as a boundary is the KISSiest solution...

Agreed?

thanks for your comment!,
[I have to think now about the lover thing :-)]

adam

Posted by adam-bien.com on October 07, 2010 at 10:09 PM CEST #

I have to disagree here Adam. EJB is not needed for just transactions and persistence. It's more out of the box yes, but if you're coming from a more spring-minded culture like I do you didn't use EJBs anyway. Instead I recreated the @Transactional annotation with an interceptor. It obtains the UserTransaction from the container and uses that add transactionality. JPA works regardless of EJBs.

Posted by Stephan van Hugten on October 18, 2010 at 04:14 PM CEST #

@Stephan,

we have just different approaches - I evaluate the existing stuff first. If it doesn't work, I search for alternatives. As long as EJB 3.1 are lean, fast and maintainable I will use them. If case Java EE 7 will come with built-in aspects, I will get rid off EJBs entirely.

Was your decision based on Java EE 6 experiences, or you are just a bit "Spring biased" :-)?

thanks!,

adam

Posted by adam-bien.com on October 18, 2010 at 04:28 PM CEST #

Adam,
Thank you for your quick reply. I think it was a "spring-biased" decision haha. I only needed to have transactions and although I have seen that EJB 3.x is much easier to use I don't think it was right to use EJBs just to add transaction.begin/transaction.commit.

Posted by Stephan van Hugten on October 19, 2010 at 12:21 PM CEST #

@Stephan,

you should at least try EJB. The overhead is negligible (not measurable) and the result simpler.

A custom "aspect" works well for a single transaction participant. If you get more, than one, you should know what your are doing.

In most cases I'm just lazy and go with EJB 3.1.

adam

Posted by adam-bien.com on October 19, 2010 at 01:10 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License