Number(3.0) field in Oracle database for Java

Asked

Viewed 111 times

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.

  • Byte the interface declaration and findById in fact it does not fit. With Short should fit.

  • 1

    Ah, the body of your method findById can be replaced for simply return tipoPropriRepository.findById(id).orElse(null);.

1 answer

0

I managed to solve.

In 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 fields of type Short and Byte. I changed EVERYONE to BIGDECIMAL, that worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.