0

I have a stored procedure in SQL Server 2017 that returns data as JSON in an nvarchar(max) output parameter.

I have checked to make sure the entire result set is being returned from the stored procedure by running it on the database and everything works there. It returns a JSON string well over 4000 characters.

However, in my spring boot api, using Hibernate 5.3.7, the output is truncated to 4000 characters.

Any ideas on how I can fix this please?

Code where I call the Stored Procedure:

    StoredProcedureQuery query = entityManager
            .createStoredProcedureQuery("usp_my_stored_proc");
    query.registerStoredProcedureParameter("reportOutputData", String.class, ParameterMode.OUT);


    query.execute();


    return String.valueOf(query.getOutputParameterValue("reportOutputData"));

The query.getOutputParameterValue("reportOutputData") has a length of 4000. It should be a lot longer (like 40,000+).

application.properties:

spring.jpa.properties.hibernate.dialect=com.company.package.config.CustomSQLServerDialect

CustomSQLServerDialect:

    public class CustomSQLServerDialect extends SQLServer2012Dialect {

    public CustomSQLServerDialect() {
        super();
        registerColumnType(Types.VARCHAR, "nvarchar(max)");
        registerColumnType(Types.CLOB, "nvarchar(max)");
        registerColumnType(Types.NVARCHAR, "nvarchar(max)");
        registerColumnType(Types.NCLOB, "nvarchar(max)");
        registerHibernateType(Types.NVARCHAR, 
        StandardBasicTypes.STRING.getName());
}

}

mljohns89
  • 887
  • 1
  • 11
  • 16
  • You need to post your HQL/mappings, but this might answer your question https://stackoverflow.com/questions/1099413/how-can-hibernate-map-the-sql-data-type-nvarcharmax – UnhandledExcepSean Apr 11 '19 at 14:39
  • @UnhandledExcepSean I tried something similar to the link you posted, It didn't resolve the issue. Or I didn't setup my application.yml correctly. I edited to include sample code and application.yml – mljohns89 Apr 11 '19 at 14:52

0 Answers0