Mihail Stoynov's blog!
Surrender your ego
Wednesday, April 30, 2008
EJB Sucks: one more reason why
I'm trying to like the specification, but I just can't.
Here's one more reason why:
I have
SSB
(Stateless Session Beans). The persistence is via JPA (implementation is Hibernate).
All my business method look something like:
...
public Object1 doSomething( Object2 ) throws ApplicationException1;
...
I use
CMT
(Container Managed Transactions) which means that the container calls
begin()
before the method call and
commit()
after the method call is over.
The problem: what happens if the transaction is rolled back?
A
RollbackException
is thrown. It looks common sense to try to rewrite it as
ApplicationException1
. Well.... YOU CAN'T.
No F way (at least not an easy one).
Solution1
:
Make the Beans stateful and use
SessionSynchronization
. UGLY - I don't want to be stateful.
Solution2
:
Implement
TransactionSynchronizationRegistry
- just look at it.
Solution3
:
Make a facade EJB that calls my own EJBs which should use
requiresNew
. One more level of abstraction? I have to change the contract? I don't have just one Bean, so a wrapper for every single one of them?
Solution4
:
Switch back to
BMT
(Bean Managed Transactions) and call
begin()
and
commit()
myself. Well then the container becomes useless. But my business methods are rarely longer than a few lines, so I'm choosing this one.
CMT
without any simple way to plug after
commit()
and this is an enterprise level spec? Really?
I'd be really happy if someone corrects me and shows me a simple way to do what I need.
Sucks
Comments [0]
|
Trackback
OpenID
Please login with either your
OpenID
above, or your details below.
Name
E-mail
(will show your
gravatar
icon)
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, blockquote@cite, strike
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
dasBlog theme by
Mads Kristensen
RSS feed
Search
Archives
November, 2008 (15)
October, 2008 (16)
September, 2008 (30)
August, 2008 (15)
July, 2008 (14)
June, 2008 (26)
May, 2008 (6)
April, 2008 (21)
March, 2008 (14)
February, 2008 (28)
November, 2007 (5)
October, 2007 (7)
September, 2007 (1)
August, 2007 (7)
July, 2007 (3)
June, 2007 (1)
Blog Stats
Total Posts: 203
This Year: 179
This Month: 0
This Week: 0
Comments: 80
Categories
Did you know
Java
rulez
Sucks
БГ
Blogroll
Michael Moore (no rss)
Links
BG-JUG
Copyright policy
No rights reserved.
(You are going to
copy stuff anyway :)
If you mention my
name, thank you.
2008, Mihail Stoynov