2

In NamedStoredProcedureQuery want to set SQLServerDataTable

using NamedStoredProcedureQuery in spring boot and not able to set TT object as a parameter and getting type cannot be null exception

@StoredProcedureParameter(mode = ParameterMode.IN, name = "TT_UserHierarchyList", type = SQLServerDataTable.class)

It is working for the Wrapper class like Integer,Double,String...etc.

Have tired to set an entity and SQLServerDataTable.

while creating
Query query = entityManager.createNamedStoredProcedureQuery("getChangedFarmers");

It is throwing Type cannot be null it is throwing.

Is it possible to set type=SQLServerDataTable?

1 Answers1

1

It turns out that Spring doesn't yet support SQLServerDataTable as a type, so code like this:

parameters = {
    @StoredProcedureParameter(mode = ParameterMode.IN, name = "ParameterName", type = SQLServerDataTable.class)
}

Will throw an exception like:

Caused by: java.lang.IllegalArgumentException: Type cannot be null

So the solution is to implement your call to the stored procedure at the JDBC level.

There's some nice code for a JDBC implementation here

And if you'd like to inject a Spring datasource bean you can read how to configure it here

Which will provide easy access to your datasource, like so:

@Autowired
DataSource dataSource;

SQLServerPreparedStatement statement = (SQLServerPreparedStatement) dataSource.getConnection().prepareStatement(ececStoredProc)
Continuity8
  • 2,403
  • 4
  • 19
  • 34