Friday, 30 March 2018

JPA Calling a MySQL stored function

I have a stored function called getNextCode() that requires a string parameter and returns a string. I wish to call this from my JPA enabled application. T he following code fragment shows the use of the crateNativeQuery() method to achieve this.

    private String _getNextRollPackageCode()
        String query = String.format(
                "SELECT getNextCode( '%s')",

        return this.ROLL_PACKAGE_CODE_PREFIX + "-" +  (String) _entityManager.createNativeQuery(query)

No comments :