PLSQL stored procedure query(toplink) returns bigdecimal fields without fraction

398 Views Asked by At

I call the stored procedure from Java (Toplink) as follows:

 PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
 call.setProcedureName("PACK_PORTAL_VIEW.get_payment_details");
 call.addNamedArgument("p_order_id", JDBCTypes.NUMERIC_TYPE);
 call.addNamedOutputArgument("some_variable", JDBCTypes.NUMERIC_TYPE);

 DataReadQuery drQuery = new DataReadQuery();
 drQuery.setCall(call);
 drQuery.addArgument("p_order_id");

 Query query = ((JpaEntityManager) em.getDelegate()).createQuery(drQuery);
 query.setParameter("p_order_id", orderId);

 DatabaseRecord record = (DatabaseRecord) query.getSingleResult();
 record.get("some_variable");

record.get("some_variable") returns some value that is stored in the DB with a fractional part, but in java it is written without it

record.get("some_variable").getClass() returns BigDecimal.class

How can I get the fractional value stored in the database?

1

There are 1 best solutions below

0
Anton Kai On

It was necessary to use the following method:

    /**
 * PUBLIC: Add a named OUT argument to the stored procedure. The databaseType parameter
 * classifies the parameter (JDBCType vs. OraclePLSQLType, simple vs. complex). The extra scale
 * and precision parameters indicates that this parameter, when used in an Anonymous PL/SQL
 * block, requires scale and precision specification
 */
public void addNamedOutputArgument(String procedureParameterName, DatabaseType databaseType,
    int precision, int scale) {
    DatabaseType dt = databaseType.isComplexDatabaseType() ? 
        ((ComplexDatabaseType)databaseType).clone() : databaseType;
    arguments.add(new PLSQLargument(procedureParameterName, originalIndex++, OUT, dt,
        precision, scale));
}