File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes help needed with calling a stored procedure from CMP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "help needed with calling a stored procedure from CMP " Watch "help needed with calling a stored procedure from CMP " New topic
Author

help needed with calling a stored procedure from CMP

Raju Cherukuri
Greenhorn

Joined: May 20, 2005
Posts: 1
Hello Everybody,

I have two concerns to put forward.

1) We are working on a project in which we need to use Entity beans (CMP). There is no problem with sending & getting data.

But we have a stored procedure to be called in the mean while in the business logic of the CMP:

For achieving this do we need to acquire a new database connection other than which the existing entity is using?

Is this a good practice to do this way?

Also writing a BMP here increases the code complexity & makes our application tightly coupled with the database. Which we don�t want.

2) Can we achieve the same functionality of BMP with a CMP?

I invite any suggestions or advices, as I�m new to enterprise Java. Please give a response as soon as possible because we are on the nick of the moment to deliver a solution.

Any help in this regard would be greatly appreciated.



regards,

Raju Cherukuri.
Ranga Kalidindi
Greenhorn

Joined: Mar 04, 2005
Posts: 17
Raju, I may not be able to give an exact answer (never faced this exact situation) but thought would express my opinion/understanding of the situation.

A single entity bean (either BMP or CMP) instance essentially represents one single row (may be that of a single table incase of a CMP or of a join of multiple tables incase of a BMP) w.r.to the database.

When you are saying "we have a stored procedure to be called in the mean while in the business logic of the CMP", I am slightly confused. What we essentially do on a CMP entity bean is that we get and set values after obtaining a remote interface bandle of it. Is it that - in one of the setter method, you are required to call a stored procedure ?

If you donot want to disturb your existing CMP, my suggession would be that you define a database trigger on that table for BEFORE/AFTER UPDATE and 'call' that stored procedure. So when you 'set' a value on that CMP bean, that correspondig 'update' would trigger/call that stored procedure. For the transaction mgmt, if the stored procedure fails it throws an exception (assuming it would) and sure the trigger would fail and therefore the 'update' should fail and throw an database trigger failure exception. Not sure if the remote interface would throw us that exception (I assume it would).

I am not sure how to achieve this with a BMP but without acquiring a seperate database connection.
Can we define a new Entity Bean to represent a 'call to store procedure' ? And then obtain its remote interface which can call the stored procedure in our entity bean setter method ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: help needed with calling a stored procedure from CMP