java - Spring/Hibernate/Oracle: ORA-02289 Sequence Does Not Exist? -


getting java.sql.sqlsyntaxerrorexception: ora-02289: sequence not exist when trying insert new object oracle table. table have sequence automatically increments upon each entry.

i've been stuck on few hours , after following similar answers question , other articles, i'm still stuck.

my class:

import java.sql.timestamp;  import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.sequencegenerator; import javax.persistence.table;  import org.springframework.stereotype.component;  @entity @table(name = "my_schema.my_table") @component public class someclass {     @id     @sequencegenerator(name = "my_seq", sequencename = "my_seq", allocationsize = 1)     @generatedvalue(strategy = generationtype.sequence, generator = "my_seq")     @column(name = "my_id")     private integer myid;      @column(name = "my_ts")     private timestamp ts;      @column(name = "my_param")     private string myparameters;      @column(name = "another_ts")     private timestamp anothertimestamp;      // empty constructor , getters/setters  } 

dao class:

import java.io.serializable; import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; import java.util.properties;  import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; import org.hibernate.boot.registry.standardserviceregistrybuilder; import org.hibernate.cfg.configuration; import org.springframework.stereotype.component;  import mypackage.mysubpackage.someclass;  @component public class someclassdao {      private session currentsession;     private transaction currenttransaction;      private static sessionfactory getsessionfactory() {         configuration configuration = new configuration().configure();         configuration.addannotatedclass(someclass.class);         standardserviceregistrybuilder builder = new standardserviceregistrybuilder()                 .applysettings(configuration.getproperties());         sessionfactory factory = configuration.buildsessionfactory(builder.build());         return factory;     }      public session opencurrentsession() {         currentsession = getsessionfactory().opensession();         return currentsession;     }      public session opencurrentsessionwithtransaction() {         currentsession = getsessionfactory().opensession();         currenttransaction = currentsession.begintransaction();         return currentsession;     }      public void closecurrentsession() {         currentsession.close();     }      public void closecurrentsessionwithtransaction() {         currenttransaction.commit();         currentsession.close();     }      public session getcurrentsession() {         return currentsession;     }      public void setcurrentsession(session currentsession) {         this.currentsession = currentsession;     }      // post     public void insertnew() {         someclass obj = new someclass();         obj.setparameters("abc");         getcurrentsession().save(obj);     }  } 

ddl snippet sequence:

begin    if inserting       if :new."my_id" null          select my_seq.nextval :new."my_id" dual;       end if;    end if; end; 

hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public         "-//hibernate/hibernate configuration dtd//en"         "http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd"> <hibernate-configuration>     <session-factory>         <property name="connection.url">jdbc:oracle:thin:@servername.company.net:123:abc</property>         <property name="connection.driver_class">oracle.jdbc.oracledriver</property>         <property name="dialect">org.hibernate.dialect.oracle10gdialect</property>         <property name="connection.username">user</property>         <property name="connection.password">pass</property>         <property name="show_sql">true</property>       </session-factory>  </hibernate-configuration> 

mvc-dispatchet-servlet.xml snippet:

<context:component-scan base-package="mypackage.mysubpackage"></context:component-scan> <mvc:annotation-driven/> <context:annotation-config/>  <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource">     <property name="driverclassname" value="oracle.jdbc.oracledriver"/>     <property name="url" value="jdbc:oracle:thin:@servername.company.net:123:abc"/>     <property name="username" value="user"/>     <property name="password" value="pass"/> </bean>  <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"       p:packagestoscan="mypackage.mysubpackage"       p:datasource-ref="datasource">     <property name="jpavendoradapter">         <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter">             <property name="generateddl" value="true"/>             <property name="showsql" value="true"/>         </bean>     </property> </bean>  <bean id="transactionmanger" class="org.springframework.orm.jpa.jpatransactionmanager">     <property name="entitymanagerfactory" ref="entitymanagerfactory"/> </bean>  <tx:annotation-driven transaction-manager="transactionmanger"/> 

begin    if inserting       if :new."my_id" null          select my_seq.nextval :new."my_id" dual;       end if;    end if; end; 

this looks me part of oracle trigger rather actual oracle sequence. check if sequence present name "my_seq" in schema.

if have sequence in place current jpa annotations on id column, not require trigger. jpa can sequence next value without trigger.

if still want continue using trigger read here.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -