Field Number (3.0) in Oracle database for Java

0

I have a table in an Oracle 11g database with a field of type NUMBER(3,0)

In a Spring project, I have the following repository:

@Repository
public interface TipoPropriRepository extends JpaRepository<TipoPropri, Byte> {
}

That belongs to this class that was self-generated by IntelliJ:

@Entity
@Table(name = "TIPOPROPRI")
public class TipoPropri {

    private byte cdTpPropr;

    @Id
    @Basic
    @Column(name = "CD_TP_PROPR")
    public byte getCdTpPropr() {
        return cdTpPropr;
    }

    public void setCdTpPropr(byte cdTpPropr) {
        this.cdTpPropr = cdTpPropr;
    }
}

In my class @Service I have the following code:

@Service
 public class TipoProprService {

            @Autowired
            TipoPropriRepository tipoPropriRepository;

            public TipoPropri findById(byte id){
                Optional<TipoPropri> tipoPropri = tipoPropriRepository.findById(id);
                if (tipoPropri.isPresent()){
                    return tipoPropri.get();
                } else {
                    return null;
                }
            }
    }

But when I call the findById method of my Service with the following code:

 tipoProprService.findById( (byte) Integer.parseInt("6") )

(The number 6 is a number example string that will come from a part of the front end as a variable)

It gives the following exception:

java.sql.SQLException: Overflow Numérico
at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4170) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.NumberCommonAccessor.getShort(NumberCommonAccessor.java:311) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.GeneratedStatement.getShort(GeneratedStatement.java:305) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.GeneratedScrollableResultSet.getShort(GeneratedScrollableResultSet.java:879) ~[ojdbc7-12.1.0.jar:12.1.0.2.0]

I have tried several types of variables in java, such as Short, Long, Integer and always gives the same exception. I do not know what else to do.

    
asked by anonymous 23.08.2018 / 22:08

1 answer

0

I was able to resolve it.

In the question I did not put the other fields you have in the class so the question does not get too long.

But this class had other Short and Byte fields. I've changed ALL to BIGDECIMAL , it worked there.

    
23.08.2018 / 22:42