I am currently developing an application based on the Spring Boot framework that is employing a JPA inbound channel adapter to retrieve data from a relational database. I have a stored procedure named GetEmployee which needs to accept a value that varies based on the server instance on which the application is running.
I've looked at the Spring documentation on adapters, and it makes mention of a tag named int-jpa:parameter but that appears to only be utilized when the named-query attribute is utilized instead of the native-query attribute.
There is also a parameter-source attribute on the int-jpa:inbound-channel-adapter tag, but I haven't found any good documentation on how to utilize it.
Is there a way to pass a parameter from a Spring bean to the native query? Or is the better approach to use the named-query attribute?
Configuration XML:
<int-jpa:inbound-channel-adapter
id="employeeAdapter"
channel="employeeChannel"
entity-manager-factory="entityManagerFactory"
entity-class="com.example.entities.Employee"
native-query="EXEC emp.dbo.GetEmployee"
expect-single-result="false"
delete-after-poll="false">
<int:poller fixed-rate="10000">
<int:transactional propagation="REQUIRED" isolation="DEFAULT"
transaction-manager="transactionManager" />
</int:poller>
</int-jpa:inbound-channel-adapter>
Well, that really work only if your query declare some parameters:
/**
* Given a JPQL query, this method gets all parameters defined in this query and
* use the {@link ParameterSource} to find their values and set them.
*
*/
private void setParametersIfRequired(String queryString, ParameterSource source, Query query) {
Set<Parameter<?>> parameters = query.getParameters();
Since your EXEC doesn't have any parameters in the procedure call, there is nothing to extract and apply for the supplied int-jpa:parameters.
Consider to use CALL emp.dbo.GetEmployee(?) or BEGIN emp.dbo.GetEmployee(?); END;. Not sure which syntax will work for your RDBMS.
On the other hand, I'd take a look into Spring Integration Stored Procedure support instead.