Shruti sharma
Shruti sharma

Reputation: 211

Numeric overflow exception in spring boot JPA

I am using spring data jpa with Oracle database. I am getting error even when I was not creating any data but when I was just testing the application. so error is same.

Error is

ERROR 22488 --- [ task-1] o.h.e.j.e.internal.JdbcEnvironmentImpl : Could not fetch the SequenceInformation from the database

java.sql.SQLException: Numeric Overflow at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4139

Below are the details.

DB table:-

create table product(
id int PRIMARY KEY,
name varchar2(20),
description varchar2(100),
price Number(8,3) 
);

Entity class:-

@Data
@NoArgsConstructor
@Entity
public class Product {
        @Id
    private int id;
    private String name;
    @Column(name="description")
    private String desc;
    private Double price;
}

Repository class:-

public interface ProductRepository extends CrudRepository<Product, Integer>  {
}

Runner class to run the application.

public class TestRunner implements CommandLineRunner {
    
    @Autowired
    private ProductRepository repo;
    
    @Override
    public void run(String... args) throws Exception {
        
        System.out.println("Inside Runner class");
        Product product= new Product();
        product.setId(101);
        product.setName("IPhone");
        product.setDesc("Its Awesome");
        product.setPrice(123.45d);
        repo.save(product);
    }    
}

properties file:-

spring.datasource.url=jdbc:oracle:thin:@sca00tof.us.dell.com:1521:mfg1229
spring.datasource.username=apps
spring.datasource.password=apps
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect

I am getting the below error.

2020-11-29 01:31:19.408  INFO 22488 --- [           main] c.l.s.product.ProductdataApplication     : Starting ProductdataApplication using Java 14.0.2 on mahima-IN with PID 22488 (D:\Learning\spring\NewLearning\productdata\target\classes started by mahima-orcl in D:\Learning\spring\NewLearning\productdata)
2020-11-29 01:31:19.411  INFO 22488 --- [           main] c.l.s.product.ProductdataApplication     : No active profile set, falling back to default profiles: default
2020-11-29 01:31:19.880  INFO 22488 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-29 01:31:19.930  INFO 22488 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 42 ms. Found 1 JPA repository interfaces.
2020-11-29 01:31:20.320  INFO 22488 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-11-29 01:31:20.365  INFO 22488 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-11-29 01:31:20.433  INFO 22488 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.24.Final
2020-11-29 01:31:20.455  INFO 22488 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-11-29 01:31:20.594  INFO 22488 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2020-11-29 01:31:20.722  INFO 22488 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-11-29 01:31:23.745  INFO 22488 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-11-29 01:31:23.765  INFO 22488 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
2020-11-29 01:31:45.561 ERROR 22488 --- [         task-1] o.h.e.j.e.internal.JdbcEnvironmentImpl   : Could not fetch the SequenceInformation from the database

java.sql.SQLException: Numeric Overflow
    at oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4139) ~[ojdbc8-19.8.0.0.jar:19.8.0.0.0]
    at oracle.jdbc.driver.NumberCommonAccessor.getLong(NumberCommonAccessor.java:636) ~[ojdbc8-19.8.0.0.jar:19.8.0.0.0]
    at oracle.jdbc.driver.GeneratedStatement.getLong(GeneratedStatement.java:208) ~[ojdbc8-19.8.0.0.jar:19.8.0.0.0]
    at oracle.jdbc.driver.GeneratedScrollableResultSet.getLong(GeneratedScrollableResultSet.java:261) ~[ojdbc8-19.8.0.0.jar:19.8.0.0.0]
    at oracle.jdbc.driver.GeneratedResultSet.getLong(GeneratedResultSet.java:560) ~[ojdbc8-19.8.0.0.jar:19.8.0.0.0]
    at com.zaxxer.hikari.pool.HikariProxyResultSet.getLong(HikariProxyResultSet.java) ~[HikariCP-3.4.5.jar:na]
    at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.resultSetMinValue(SequenceInformationExtractorLegacyImpl.java:134) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:60) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.sequenceInformationList(JdbcEnvironmentImpl.java:403) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:268) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.24.Final.jar:5.4.24.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.1.jar:5.3.1]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.1.jar:5.3.1]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.1.jar:5.3.1]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

Upvotes: 2

Views: 4622

Answers (1)

priyranjan
priyranjan

Reputation: 704

your code is looking for GeneratedValue on id column since you are setting manually id value then you can create one more filed for primary key (jpa will take care of this field you need not to insert manually) like below:---

@NoArgsConstructor
@Entity
@Data
public class Product {
      @Id
      @GeneratedValue( strategy=GenerationType.SEQUENCE)
      private int primaryId;

    private int id;
    private String name;
    @Column(name="description")
    private String desc;
    private Double price;
}

Upvotes: 1

Related Questions