java - Exception in thread "main" org.hibernate.exception.SQLGrammarException: ORA-02289: sequence does not exist -
i trying execute basic hibernate application.however,i consistently getting error posted in question.
below posted project structure
code:
below code present in app.java
public class app {
/** * @param args */ public static void main(string[] args) { // todo auto-generated method stub session session =hibernate_utils.getsessionfactory().opensession(); session.begintransaction(); contact contact=new contact(); contact.setfirstname("xxx"); contact.setlastname("xxx"); contact.setemail("xxxxxxx@gmail.com"); contact.settelephone("xxxxxxxxxx"); session.save(contact); session.gettransaction().commit(); system.out.println("saved"); } } below posted code present in contact.java file
package net.rishanth.contact.form; 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 javax.persistence.column; import static javax.persistence.generationtype.sequence; @entity @table(name = "contacts") public class contact { @id @generatedvalue(strategy=sequence) @column(name = "id", unique = true, nullable = false) public integer getid() { return id; } public void setid(integer id) { this.id = id; } @column(name = "firstname", nullable = false) public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; } @column(name = "lastname", nullable = false) public string getlastname() { return lastname; } public void setlastname(string lastname) { this.lastname = lastname; } @column(name = "email", nullable = false) public string getemail() { return email; } public void setemail(string email) { this.email = email; } @column(name = "telephone", nullable = false) public string gettelephone() { return telephone; } public void settelephone(string telephone) { this.telephone = telephone; } private string firstname; private string lastname; private string email; private string telephone; private integer id; } below posted code hiber_utils class present in service package.
package net.rishanth.contact.service; import org.hibernate.sessionfactory; import org.hibernate.cfg.configuration; public class hibernate_utils { private static final sessionfactory sessionfactory= buildsessionfatory(); @suppresswarnings("deprecation") private static sessionfactory buildsessionfatory(){ // todo auto-generated method stub return new configuration().configure().buildsessionfactory(); } public static sessionfactory getsessionfactory() { return sessionfactory; } public static void shutdown() { getsessionfactory().close(); } } below present hibernate.cnfg.xml file
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.oracledriver </property> <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:xe </property> <property name="hibernate.dialect">org.hibernate.dialect.oracle10gdialect </property> <property name="hibernate.connection.username">system</property> <property name="hibernate.connection.password">xxxxx</property> <mapping class="net.rishanth.contact.form.contact"></mapping> </session-factory> </hibernate-configuration> below attached oracle screenshot
any highly appreciated. thanks!
you have annotated contact entity use sequence strategy. have not specified sequence should used. (i believe error might getting. if not, posting exception stack trace help.)
in case, default hibernate looks sequence named hibernate_sequence , creating sequence name should help.
or, in case want hibernate use sequence (say, your_sequence_name) have created further qualifying @id attribute below should help:
@generatedvalue(strategy=generationtype.sequence, generator="myseq") @genericgenerator(name="myseq", strategy="sequence", parameters={ @parameter(name="sequence_name", value="your_sequence_name") })
Comments
Post a Comment