Saturday, June 12, 2010

If Software is pizza, EJB is the House Special

If you can stand terrible food metaphors and have ever been exposed to EJB positively or negatively, keep reading....

I don't know about you, but I love the simplicity of a good pepperoni pizza now and then. Imagine asking for a plain Pepperoni pizza and being told your only option was to get the House Special and to pick off all the onions, black olives, green pepper and whatever else comes on top. Any person with options would simply go to another pizza shop. Well, that's EJB. Something I hope we can change in EJB 4.0.

To setup the metaphor a bit more, let's say the dough and cheese is the component itself and the proxy to the component. The toppings are the various QOSs (qualities of service) such as transaction management, interceptors, concurrency management, cron-like scheduling, asynchronous method calls, and other goodness. Each bean type such as Stateful, Stateless, Singleton and Message Driven are certain styles of pizza with a fixed set of toppings; say Meat Lovers, Vegetarian, or Hawaiian. The toppings of each style of pizza have been selected carefully to compliment each other perfectly and guarantee good results.

Currently though, if you want to start with a plain pizza and add only the toppings you want or need, you cannot do it with EJB. If you want pepperoni, you need to pick a style of pizza that has pepperoni as a topping and deal with the other toppings that come with it, wanted or not. EJB is somewhat flexible and there are usually ways to neutralize some features that amounts to picking off the toppings you don't like, but it's not the same as if they weren't ever there and you are still going to get an odd tasting and odd looking pizza.

Say you don't really want the transaction management topping. You try to pick off the topping by selecting SUPPORTS as your default transaction attribute so if a transaction is there, your bean participates in it, if not, it still does it's work regardless. All is fine until your bean throws a runtime exception and the container decides to rollback the current transaction on your behalf. Say you instead choose to try and pick off the transactional topping by making your bean use bean-managed transactions. Things work fine except now all transactions are suspended by the container so that the bean cannot mess with the state of what was the current transaction. What you really wanted was your bean to not be transactionally aware in the first place.

Unfortunately if you want one of the other toppings like container managed concurrency, cron-like scheduling, or asynchronous method calls, you have to learn to like the transaction management topping, period.

There will always be a need for specific pizza styles with pre-selected toppings -- who doesn't love a good Greek pizza or a Hawaiian now and then. The EJB spec does that well with its perfectly selected bean types, each sprinkled with the select set of QOSs deemed appropriate for that specific bean type. That said, it really should be possible to start with a plain cheese pizza and just add the toppings you want.

Forget the dough and cheese. EJB should be about the toppings.

Ideally, every QOS the EJB spec has to offer would be an option that can be applied to a plain component. Imagine if there was a "plain cheese pizza" bean type that would by default have no QOSs at all and for all intense purposes be a true POJO. There's nothing to learn or study to code it or use it. It's just a POJO created by the container. Then one day you decide you'd like it to be transaction aware. At that point you annotate it with @TransactionManagement and then go read the self contained "transaction management" section of the spec to see what is now expected of you and the users of the bean.

It may be that certain QOSs cannot be combined, which is in fact the case at times. The concept of a container managed persistence context (i.e. a field like "@PersistenceContext EntityManager myEntityManager") cannot be combined with the new @ConcurrencyManagement annotation because EntityManagers themselves are not guaranteed to be capable of concurrency. As a result EJB Singletons are not allowed to use container managed persistence contexts. That may work for some, but maybe you want a Singleton that uses a container managed persistence contexts and do not need concurrency anyway. Such a thing would be possible if you were able to choose the QOSs for your bean regardless of its lifecycle.

It's time to break up the big specs and let people build their own pizzas.

23 comments:

Unknown said...

20170619 junda
rolex watches,rolex watches,swiss watches,watches for men,watches for women,omega watches,replica watches,rolex watches for sale,rolex replica,rolex watch,cartier watches,rolex submariner,fake rolex,rolex replica watches,replica rolex
ray ban sunglasses
ferragamo outlet
ray ban wayfarer
true religion jeans sale
fitflops
christian louboutin sale
ralph lauren outlet
jordan 4
cheap nfl jerseys

Farhan Khan said...

FCI Watchman

Admit Card 2017

CG SET Admit Card

2017

MP Patwari

Admit Card 2017

JEE Main 2018

Application Form

PNRD Assam

REcruitment 2017

Danish Ahmed said...

Thanks for sharing this article, now you can also check your Recuritment & Notification 2017-2018 by following below given links...

fci andhra pradesh watchman recuritment 2017

fci tamilnadu watchman recuritment 2017

xat notification 2018

jkbote polytechnic result 2017

Habib Malik said...

Kalyani University Routine 2018
Tripura Board Madhyamim Date Sheet 2018
Tripura Board HS Date Sheet 2018
Telangana SSC Date Sheet 2018
Telanagana Intermediate Date Sheet 2018

Habib Malik said...

GSAT Application Form 2018
HP Application Form 2018
Karnataka DCET Application Form 2018
RIE EEE Application Form 2018
SSC CGL Application Form 2018

Unknown said...

tory burch bags
fitflops outlet
wholesale snapback hats
adidas flip flops
beats by dre
hermes
clarisonic
manchester united jersey
longchamp outlet
isabel marant
20185.24chenjinbei

Unknown said...

jordans
air max
kenzo clothing
mac cosmetics
true religion outlet
wedding dresses
furla handbags
air max 95
pandora
clarks shoes
2018.6.6chenlixiang

chenlina said...

parajumpers jackets
calvin klein
curry 2
jimmy choo
g-star jeans
fendi sunglasses
curry jersey
teva sandals
james harden jersey
insanity
chenlina20180620

rithiaanandh said...

That was a great message in my carrier, and It's wonderful commands like mind relaxes with understanding words of knowledge by information. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
Sql server dba online training

jothikumar said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
Selenium training in Chennai |
Devops online training

Darren Demers said...

Say you don't really want the transaction management topping. You try to pick off the topping by selecting SUPPORTS as your default transaction attribute so if a transaction is there, your bean participates in it, if not, it still does it's work regardless. shawls online , pashmina shawls online , silk shawls online , shawls online , black shawl , white shawl , shawl , silver shawl , gold shawl , navy shawl All is fine until your bean throws a runtime exception and the container decides to rollback the current transaction on your behalf. Say you instead choose to try and pick off the transactional topping by making your bean use bean-managed transactions. Things work fine except now all transactions are suspended by the container so that the bean cannot mess with the state of what was the current transaction. What you really wanted was your bean to not be transactionally aware in the first place.

priya said...


The hectic world, a usual silhouette of wrinkled-faces and lack of time & good people make absolute absence of Love in our lives. Only a smile means to exist in the whole world bringing itself a Comet of Love. So it takes you believe onRussian Escorts in Gurgaon liable to fulfill your lives with real sense of love. Check our other Services...
Escorts Service in Gurgaon
Female Escorts in Gurgaon
Russian Escorts in Gurgaon
Russian Escorts in Gurgaon
Escorts Service in Gurgaon


abid said...


Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.
data science course in guwahati

Prwatech said...

Excellent content! Thanks for sharing such a useful information.

Best AWS Training Institute in Pune

Priya Rathod said...

Thank you for this list, I found a lot of interesting things.
AWS Training in Hyderabad
AWS Course in Hyderabad

Escorts Service Kolkata said...

escorts service in kolkata |
escorts service in kolkata |
escorts service in kolkata |
escorts service in kolkata |
escorts service in kolkata |

Escorts Service Kolkata said...

Kolkata Call girls |

Call girls in Kolkata |
Call girls in Kolkata |

escorts |
escorts |

Call girls in Kolkata |
escorts in kolkata |

http://gg.gg/v5eov |
https://cutt.ly/hjmTXaa |

https://www.escortkolkata.com/Kolkata-hotel-escorts.html

Dettifoss IT Solutions said...

Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.
servicenow training in Bangalore

Dettifoss IT Solutions said...


I would like to thank you for the efforts you had made for writing this information. This article inspired me to read more. keep it up
servicenow training and placement in hyderabad

Dettifoss IT Solutions said...

Good Post! it was so good to read and useful to improve my knowledge as an updated one, keep blogging.
ServiceNow Training in Pune

Dettifoss IT Solutions said...

Great post i must say and thanks for the information.
ServiceNow Training in Pune

Dettifoss IT Solutions said...

The information you have posted is very useful. The sites you have referred was good. Thanks for sharing.
servicenow training in Bangalore

Dettifoss IT Solutions said...

A splendid job! Thank you for blog. you write very nice articles, I visit your website for regular updates.
Mulesoft training in hyderabad