I have a stored procedure which prints messages. I am using JPA named query to execute the same. However, I could not find a construct within JPA that will allow me to capture the messages from the stored procedure.
Here is my sample procedure:
********************************
create proc test
@text varchar(255)
AS
declare
@col int
SELECT @col=col
FROM table
WHERE text=@text
IF @@error != 0 BEGIN
print 'Invalid text'
return -100
END
return 1
go
********************************
How do I get the message 'Invalid text' using JPA?
What database are you using? I don't thin print is in any way returned, it just prints something on the server. You need to either throw an error, or return an error message using an output parameter.
We use Sybase, SQLServer and Oracle. We have the same stored procedure on all these db vendors printing messages based on various action codes. In our legacy application, we were able to get these messages using the appropriate db calls like ct_diag() for Sybase using CtLib or SQLGetDiagRec for MSSQL using ODBC.
We need a similar mechanism for JPA to retrieve the messages from the DB Server. As you may have noticed, printing messages within sotred procedures is supported in most DB vendors. On Oracle, it is via dbms_output.put_line and on MSSQL/Sybase, it is via the print statement.
If you have database functions that you can call to return the output, then you can call these from EclipseLink. This will be a separate call, as it is a separate function.
If you have database functions that you can call to return the output, then you can call these from EclipseLink. This will be a separate call, as it is a separate function.
I think in JDBC these may be accessible from statement.getWarnings().
EclipseLink will log these warnings to the SessionLog if logging is on finest, so you can check this.
If you need access to these other than through logging, then you should probably use JDBC directly.
It may be possible for EclipseLink to provide access to them through some sort of event, if you log an enhancement for it.
I think in JDBC these may be accessible from statement.getWarnings().
EclipseLink will log these warnings to the SessionLog if logging is on finest, so you can check this.
If you need access to these other than through logging, then you should probably use JDBC directly.
It may be possible for EclipseLink to provide access to them through some sort of event, if you log an enhancement for it.