Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call database stored procedures using EJB ??

 
Rashmi Banthia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another novice question. How to call database stored procedures in EJB? Can I use CMP and also call stored procedures ?? Any articles or books which explains this.
Thank you for your responses.
Regards,
Rashmi
 
Jason Stull
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the catch with CMP Entity Beans. The container will write the SQL for you. Most container vendors, I would imagine, will not let you hack the logic that generates the SQL statements (Although you should check the docs for your container). The db relationships in our shop are complex so we use BMP Entity Beans with Data Access Objects (DAOs) which use stored procedures.
 
Edy Yu
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can still use stored procedure in CMP entity beans. CMP will take care of the persistence for your fields. But I think it's ok to have a few concrete methods in your beans class which has some calls to the stored procedure.
 
Rashmi Banthia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this mean I have to use JDBC calls to execute a stored procedure ?
Does EJB-QL support exec procedure statement ??
Regards,
Rashmi
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As of I know EJB-QL doesn't support direct call to store procedure. If you look at theory how EJB-QL know about Oracle or any other db provider function? It's up to container to provide such access method. But again I am not completely sure with CMP.
You can do that BMP because container will tell when to sync with db & bean provider will write all SQL related code. In that case you will use java.sql.* (or other) API to make db connection & call to store procedure. I mean it becomes JDBC programming from that point.
Hope this help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic