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.