0
I have a table in an Oracle 11g database with a field of type NUMBER(3,0)
In a Spring project, I own the following:
@Repository
public interface TipoPropriRepository extends JpaRepository<TipoPropri, Byte> {
}
That belongs to this class that was self-generated by the 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 an example number string that will come from a part of the front end as a variable)
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 tried several types of variavies in java, like Short, Long, Integer and always gives the same exception. I don’t know what else to do.
Bytethe interface declaration andfindByIdin fact it does not fit. WithShortshould fit.– Victor Stafusa
Ah, the body of your method
findByIdcan be replaced for simplyreturn tipoPropriRepository.findById(id).orElse(null);.– Victor Stafusa