java - ERROR: ORA-02289: sequence does not exist - org.hibernate.exception.SQLGrammarException: could not extract ResultSet -
i creating basic hibernate application employee table in adding, updating, deleting , displaying record of manageemployee class.
actually, manageemployee test class , using employee.java , employee.hbm.xml file above things.
details: database: oracle 11 g hibernate version: hibernate-release-4.3.8.final java version: java 1.8
employee table details:
user_id number(15,0) no 1 1
first_name varchar2(20 byte) yes 2
last_name varchar2(20 byte) yes 3
salary number(10,0) yes 4
error log: can see in log error coming 3 times because adding employee object 3 times in manageemployee.java class addemployee(...) method assuming problem sequence generator column id.
here using naive generator. i.g. integer empid1 = me.addemployee("zara", "ali", 1000);
may 12, 2015 3:34:39 org.hibernate.engine.jdbc.spi.sqlexceptionhelper logexceptions error: ora-02289: sequence not exist org.hibernate.exception.sqlgrammarexception: not extract resultset at org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:80) at org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:126) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:112) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:91) at org.hibernate.id.sequencegenerator.generateholder(sequencegenerator.java:122) at org.hibernate.id.sequencegenerator.generate(sequencegenerator.java:115) at org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:117) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(defaultsaveorupdateeventlistener.java:209) at org.hibernate.event.internal.defaultsaveeventlistener.savewithgeneratedorrequestedid(defaultsaveeventlistener.java:55) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.entityistransient(defaultsaveorupdateeventlistener.java:194) at org.hibernate.event.internal.defaultsaveeventlistener.performsaveorupdate(defaultsaveeventlistener.java:49) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90) at org.hibernate.internal.sessionimpl.firesave(sessionimpl.java:715) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:707) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:702) at manageemployee.addemployee(manageemployee.java:47) at manageemployee.main(manageemployee.java:23) caused by: java.sql.sqlsyntaxerrorexception: ora-02289: sequence not exist at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:450) at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:399) at oracle.jdbc.driver.t4c8oall.processerror(t4c8oall.java:1059) at oracle.jdbc.driver.t4cttifun.receive(t4cttifun.java:522) at oracle.jdbc.driver.t4cttifun.dorpc(t4cttifun.java:257) at oracle.jdbc.driver.t4c8oall.dooall(t4c8oall.java:587) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:225) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:53) at oracle.jdbc.driver.t4cpreparedstatement.executefordescribe(t4cpreparedstatement.java:774) at oracle.jdbc.driver.oraclestatement.executemaybedescribe(oraclestatement.java:925) at oracle.jdbc.driver.oraclestatement.doexecutewithtimeout(oraclestatement.java:1111) at oracle.jdbc.driver.oraclepreparedstatement.executeinternal(oraclepreparedstatement.java:4798) at oracle.jdbc.driver.oraclepreparedstatement.executequery(oraclepreparedstatement.java:4845) at oracle.jdbc.driver.oraclepreparedstatementwrapper.executequery(oraclepreparedstatementwrapper.java:1501) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:82) ... 13 more may 12, 2015 3:34:39 org.hibernate.engine.jdbc.spi.sqlexceptionhelper logexceptions warn: sql error: 2289, sqlstate: 42000 may 12, 2015 3:34:39 org.hibernate.engine.jdbc.spi.sqlexceptionhelper logexceptions error: ora-02289: sequence not exist org.hibernate.exception.sqlgrammarexception: not extract resultset at org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:80) at org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:126) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:112) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:91) at org.hibernate.id.sequencegenerator.generateholder(sequencegenerator.java:122) at org.hibernate.id.sequencegenerator.generate(sequencegenerator.java:115) at org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:117) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(defaultsaveorupdateeventlistener.java:209) at org.hibernate.event.internal.defaultsaveeventlistener.savewithgeneratedorrequestedid(defaultsaveeventlistener.java:55) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.entityistransient(defaultsaveorupdateeventlistener.java:194) at org.hibernate.event.internal.defaultsaveeventlistener.performsaveorupdate(defaultsaveeventlistener.java:49) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90) at org.hibernate.internal.sessionimpl.firesave(sessionimpl.java:715) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:707) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:702) at manageemployee.addemployee(manageemployee.java:47) at manageemployee.main(manageemployee.java:24) caused by: java.sql.sqlsyntaxerrorexception: ora-02289: sequence not exist at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:450) at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:399) at oracle.jdbc.driver.t4c8oall.processerror(t4c8oall.java:1059) at oracle.jdbc.driver.t4cttifun.receive(t4cttifun.java:522) at oracle.jdbc.driver.t4cttifun.dorpc(t4cttifun.java:257) at oracle.jdbc.driver.t4c8oall.dooall(t4c8oall.java:587) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:225) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:53) at oracle.jdbc.driver.t4cpreparedstatement.executefordescribe(t4cpreparedstatement.java:774) at oracle.jdbc.driver.oraclestatement.executemaybedescribe(oraclestatement.java:925) at oracle.jdbc.driver.oraclestatement.doexecutewithtimeout(oraclestatement.java:1111) at oracle.jdbc.driver.oraclepreparedstatement.executeinternal(oraclepreparedstatement.java:4798) at oracle.jdbc.driver.oraclepreparedstatement.executequery(oraclepreparedstatement.java:4845) at oracle.jdbc.driver.oraclepreparedstatementwrapper.executequery(oraclepreparedstatementwrapper.java:1501) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:82) ... 13 more may 12, 2015 3:34:39 org.hibernate.engine.jdbc.spi.sqlexceptionhelper logexceptions warn: sql error: 2289, sqlstate: 42000 may 12, 2015 3:34:39 org.hibernate.engine.jdbc.spi.sqlexceptionhelper logexceptions error: ora-02289: sequence not exist org.hibernate.exception.sqlgrammarexception: not extract resultset at org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:80) at org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:126) at org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:112) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:91) at org.hibernate.id.sequencegenerator.generateholder(sequencegenerator.java:122) at org.hibernate.id.sequencegenerator.generate(sequencegenerator.java:115) at org.hibernate.event.internal.abstractsaveeventlistener.savewithgeneratedid(abstractsaveeventlistener.java:117) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.savewithgeneratedorrequestedid(defaultsaveorupdateeventlistener.java:209) at org.hibernate.event.internal.defaultsaveeventlistener.savewithgeneratedorrequestedid(defaultsaveeventlistener.java:55) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.entityistransient(defaultsaveorupdateeventlistener.java:194) at org.hibernate.event.internal.defaultsaveeventlistener.performsaveorupdate(defaultsaveeventlistener.java:49) at org.hibernate.event.internal.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:90) at org.hibernate.internal.sessionimpl.firesave(sessionimpl.java:715) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:707) at org.hibernate.internal.sessionimpl.save(sessionimpl.java:702) at manageemployee.addemployee(manageemployee.java:47) at manageemployee.main(manageemployee.java:25) caused by: java.sql.sqlsyntaxerrorexception: ora-02289: sequence not exist at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:450) at oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:399) at oracle.jdbc.driver.t4c8oall.processerror(t4c8oall.java:1059) at oracle.jdbc.driver.t4cttifun.receive(t4cttifun.java:522) at oracle.jdbc.driver.t4cttifun.dorpc(t4cttifun.java:257) at oracle.jdbc.driver.t4c8oall.dooall(t4c8oall.java:587) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:225) at oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:53) at oracle.jdbc.driver.t4cpreparedstatement.executefordescribe(t4cpreparedstatement.java:774) at oracle.jdbc.driver.oraclestatement.executemaybedescribe(oraclestatement.java:925) at oracle.jdbc.driver.oraclestatement.doexecutewithtimeout(oraclestatement.java:1111) at oracle.jdbc.driver.oraclepreparedstatement.executeinternal(oraclepreparedstatement.java:4798) at oracle.jdbc.driver.oraclepreparedstatement.executequery(oraclepreparedstatement.java:4845) at oracle.jdbc.driver.oraclepreparedstatementwrapper.executequery(oraclepreparedstatementwrapper.java:1501) at org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:82) ... 13 more first name: last name: b salary: 2000
manageemployee.java file code:
import java.util.list; import java.util.date; import java.util.iterator; import org.hibernate.hibernateexception; import org.hibernate.session; import org.hibernate.transaction; import org.hibernate.sessionfactory; import org.hibernate.cfg.configuration; public class manageemployee { private static sessionfactory factory; public static void main(string[] args) { try{ factory = new configuration().configure().buildsessionfactory(); }catch (throwable ex) { system.err.println("failed create sessionfactory object." + ex); throw new exceptionininitializererror(ex); } manageemployee me = new manageemployee(); /* add few employee records in database */ integer empid1 = me.addemployee("zara", "ali", 1000); integer empid2 = me.addemployee("daisy", "das", 5000); integer empid3 = me.addemployee("john", "paul", 10000); /* list down employees */ me.listemployees(); /* update employee's records */ // me.updateemployee(empid1, 5000); /* delete employee database */ // me.deleteemployee(empid2); /* list down new list of employees */ // me.listemployees(); } /* method create employee in database */ public integer addemployee(string fname, string lname, int salary){ session session = factory.opensession(); transaction tx = null; integer employeeid = null; try{ tx = session.begintransaction(); employee employee = new employee(fname, lname, salary); employeeid = (integer) session.save(employee); tx.commit(); }catch (hibernateexception e) { if (tx!=null) tx.rollback(); e.printstacktrace(); }finally { session.close(); } return employeeid; } /* method read employees */ public void listemployees( ){ session session = factory.opensession(); transaction tx = null; try{ tx = session.begintransaction(); list employees = session.createquery("from employee").list(); (iterator iterator = employees.iterator(); iterator.hasnext();){ employee employee = (employee) iterator.next(); system.out.print("first name: " + employee.getfirstname()); system.out.print(" last name: " + employee.getlastname()); system.out.println(" salary: " + employee.getsalary()); } tx.commit(); }catch (hibernateexception e) { if (tx!=null) tx.rollback(); e.printstacktrace(); }finally { session.close(); } } /* method update salary employee */ public void updateemployee(integer employeeid, int salary ){ session session = factory.opensession(); transaction tx = null; try{ tx = session.begintransaction(); employee employee = (employee)session.get(employee.class, employeeid); employee.setsalary( salary ); session.update(employee); tx.commit(); }catch (hibernateexception e) { if (tx!=null) tx.rollback(); e.printstacktrace(); }finally { session.close(); } } /* method delete employee records */ public void deleteemployee(integer employeeid){ session session = factory.opensession(); transaction tx = null; try{ tx = session.begintransaction(); employee employee = (employee)session.get(employee.class, employeeid); session.delete(employee); tx.commit(); }catch (hibernateexception e) { if (tx!=null) tx.rollback(); e.printstacktrace(); }finally { session.close(); } } }
mapping file:
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd//en" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="employee" table="employee"> <meta attribute="class-description"> class contains employee detail. </meta> <id name="user_id" type="int" column="user_id"> <generator class="native"/> </id> <property name="firstname" column="first_name" type="string"/> <property name="lastname" column="last_name" type="string"/> <property name="salary" column="salary" type="int"/> </class> </hibernate-mapping>
public class employee { private int user_id; private string firstname; private string lastname; private int salary; public employee() {} public employee(string fname, string lname, int salary) { this.firstname = fname; this.lastname = lname; this.salary = salary; } public string getfirstname() { return firstname; } public void setfirstname( string first_name ) { this.firstname = first_name; } public string getlastname() { return lastname; } public void setlastname( string last_name ) { this.lastname = last_name; } public int getsalary() { return salary; } public void setsalary( int salary ) { this.salary = salary; } public int getuser_id() { return user_id; } public void setuser_id(int user_id) { this.user_id = user_id; } }
employee class missing sequence generator hibernate cannot insert row. should increase id count column 1:
@id @generatedvalue(strategy=generationtype.sequence, generator="sequence1") @sequencegenerator(name="sequence1", sequencename="sequence1", allocationsize=1) private int user_id;
Comments
Post a Comment