Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can session beans update database?  RSS feed

 
Jean Miles
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't there situations where you would coded persistence in Session beans, instead of having entity beans??? What are drawbacks?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be careful not to put too much responsibility into the EJB (business logic or database access, not both).
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you can use JDBC dirrectly from the session beans and sometimes it's even better to use it instead of entity beans. This is a design pattern called "JDBC for reading". Let me tell you more about this.
When you wanna be able to insert/update/delete data in/from a table inside a database, you should use entity beans(CMPs). But when all you have to do is read data from the database and display it to the user or do some other simple operations that do not require all the advantages CMPs bring, you can use Session Beans with JDBC and it would be faster than using CMPs.
You can find more about EJBs and EJB Design Patterns in these books: "EJB second edition" by Ed Roman and "EJB Design Patterns" by Floyd Marinescu. You can download both books from http://www.middleware-company.com/ in electronic form.
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another case when I use Session Beans with JDBC is with Session Block id generator. Or when creating some views inside a database and you can read data from this views only through dirrect JDBC. Using CMP with views is impossible for the moment and using BMPs is risky.So this is the only solution.
If you want more help you should post the situation you are facing and we all will try to find the best solution for it.
Sergiu.
 
Jean Miles
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyone's input.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!