• Post Reply Bookmark Topic Watch Topic
  • New Topic

can we insert datas in to the database using stateless bean??

 
senthil sen
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we insert datas in to the database using stateless bean??
Usually we just use stateless bean for reporting structure from the database.?
If we can insert any info to the database using stateless bean how can it be done??
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not really good design practice but I don't think any container will prevent you from looking up a data source with JNDI and executing SQL statements from an SLSB.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it will work. And it's not a bad practice at all IF you consider your stateless session bean to be a Session Facade on top of a Data Access Object. See Core J2EE Patterns for more details.
Kyle
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it really a good practice if you are already using entity beans? I know SBs can be used to read data, but what are the consequences of bypassing the entity beans to write data directly to the db?
And how would this work if you are using CMP and don't have DAOs?
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajith, I look at it from a different perspective. Instead of asking why I would not use Entity Beans, I ask myself why I WOULD use them. What benefit do Entity Beans themselves bring?
Transactioning? No. That can be done in the Session Facade layer.
Remoteability? No. That can be done in the Session Facade layer.
Security? No. That can be done in the Session Facade layer.
Persistance? Yes, using CMP prevents me from having to write JDBC code.
Therefore, the only benefit that I truly see with Entity Beans is when I use CMP. Therefore, if I plan on not using CMP and instead writing my own Data Access logic (let's face it, CMP is not the most flexible thing when it comes to O/R mapping) then I would go with Session Facade + DAO.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
I am not contesting your opinion( or Kyle's ) that session beans can be used to write data.
My point is, if you already have a system written using entity beans, is it wise to bypass the entity bean layer to write data to the tables and what are the costs of doing so.
 
Ram
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two benefits of using Entity Bean
1) They are portable, to some extent
2) Writing a JDBC code is prevented
But I feel using SQLJ to code data access portion is much more benefical than using entity Ejb. As the SQLJ precompiles produces a jdbc prepared statement with a precompiled and optimized sql.
Am I missing some thing ...
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually some CMP implementations (like WebSphere's) will use SQLJ if you choose. But the biggest advantage you get out of CMPs that hasn't been mentioned is caching. Most CMP implementations have some fairly sophisticated caching mechanisms built into them to reuse instances, and even avoid making SQL calls if the results have already been brought into memory within the transaction.
Kyle
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!