• Post Reply Bookmark Topic Watch Topic
  • New Topic

Transaction management in EJB?

 
scott miles
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My question is that whole transaction management by ejb framework comes in to picture when we use session bean with entity beans. If we dont use entity beans (instead use jdbc)then we must dealt it in programme. Right?
 
Jayr Motta
Ranch Hand
Posts: 110
Google App Engine Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent question,

I'm not sure about the original implementation of the JDBC classes, but I bet they're not transactional. The implementation of entity manager in application servers compliance with JEE are required to make them transactional, I'm not sure if this is the same while using JPA in desktop clients.

However, what you need to keep in mind is that being transactional or not is about the component. Maybe if you're using some DI framework as Google Guice or Spring you may get this behavior while injecting the agent responsible to execute the queries or something like this, but I would say that's not possible.

Moreover, I bet that one of the motivations behind JPA (that uses JDBC under the hood) could be this and other features as ORM through annotation and pojo programming.

I hope this helps! Let us know!
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayr Motta wrote:

I'm not sure about the original implementation of the JDBC classes, but I bet they're not transactional.


It depends on how you do the JDBC operations. If you use plain connections via the Drivermanager, then they aren't JTA (transaction) aware resources. So they won't participate in the transaction. But if you use a transaction aware DataSource (usually available in the JNDI of the server environment) to get the database connection and do the operations, then it'll be enrolled in the transaction and you'll get the benefits of the usual container managed transaction semantics.
 
Jayr Motta
Ranch Hand
Posts: 110
Google App Engine Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't knew it, that's cool! Thanks for the answer, hope we've helped our bar colleague :P
 
scott miles
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran Pai

Could you elaborate how Datasource helps in making the JDBC trasaction transactional? Because whenever we used datasource
it was only keeping in mind its utilities for connection pooling.


Another asked in the initial post is that whole transaction management by ejb framework comes in to picture when we use session bean with entity beans. Is that correct?
 
Jayr Motta
Ranch Hand
Posts: 110
Google App Engine Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Another asked in the initial post is that whole transaction management by ejb framework comes in to picture when we use session bean with entity beans. Is that correct?


No, it's not. If you're sending a message the JMS producer will also be transactional while sending and if you're receiving (maybe inside a MDB) if your method doesn't apply any annotation related to transaction attributes, it will acknowledge the message as received just if the transaction commits.

Another example is while creating timers through the TimeService, if you create a timer during a transaction and the transaction rollback, then the timer is "de-created". But anything can be transactional, you just have to make them compliance with JTA interface and lifecycle.

That's it! Let us know if this help you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!