-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.sql.SQLException: ORA-02289: sequence does not exist
PostPosted: Fri Oct 13, 2006 6:38 pm 
Newbie

Joined: Fri Oct 13, 2006 6:25 pm
Posts: 3
Hello!

Sorry, I'm an absolute beginner and so I'm really desperate...

i hope that anybody can help me!Please!

i have 3 java.classes

Code:
public class Person {

      Integer personid;
      String firstname;
      String lastname;
      String phone;

      public Person() {

      }
      public String getFirstname() {
            return firstname;
      }
      public void setFirstname(String firstname) {
            this.firstname = firstname;
      }
      public String getLastname() {
            return lastname;
      }
      public void setLastname(String lastname) {
            this.lastname = lastname;
      }
      public Integer getPersonid() {
            return personid;
      }
      public void setPersonid(Integer personid) {
            this.personid = personid;
      }
      public String getPhone() {
            return phone;
      }
     public void setPhone(String phone) {
            this.phone = phone;
      }
   }


Code:
public class Project {

      Integer projectid;
      String projectname;
      Person projectowner;

      public Project() {
      }
      public Integer getProjectid() {
            return projectid;
      }
      public void setProjectid(Integer projectid) {
            this.projectid = projectid;
      }
      public String getProjectname() {
            return projectname;
      }
      public void setProjectname(String projectname) {
            this.projectname = projectname;
      }
      public Person getProjectowner() {
            return projectowner;
      }
      public void setProjectowner(Person projectowner) {
            this.projectowner = projectowner;
      }
   }



Code:
public class MainClass {
    private static final SessionFactory sessionFactory =
    new Configuration().configure().buildSessionFactory();

    public static void main (String[] args) {
        Session session = sessionFactory.openSession();

        Transaction trans = session.beginTransaction();

        Person myOwner = new Person();
        myOwner.setFirstname("Lars");
        myOwner.setLastname("Korte");
        myOwner.setPhone("1063-0");
       
        Person hisOwner=new Person();
        hisOwner.setFirstname("Tom");
        hisOwner.setLastname("Sylvester");
        hisOwner.setPhone("078565-333");

        Project prj = new Project();
        prj.setProjectname("Testproject");
        prj.setProjectowner(myOwner);
       
        Project prj2 =new Project();
        prj2.setProjectname("Testproject2");
        prj2.setProjectowner(hisOwner);

        session.save(myOwner);
        session.save(prj);
       
        session.save(hisOwner);
        session.save(prj2);

        trans.commit();
        session.close();
        }
}


everything seems to be ok!

then the mapping files:
one for Person:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate">
      <class name="Person" table="person">
            <id name="personid" column="id" type="java.lang.Integer">
                <generator class="sequence">
                  <param name="sequence">person_seq</param>
                </generator>
            </id>
            <property name="firstname" />
            <property name="lastname" column="last_name_of_person" />
            <property name="phone" />
      </class>
</hibernate-mapping>


one for Project


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate">
      <class name="Project" table="project">
        <id name="projectid" column="id" type="java.lang.Integer">
            <generator class="sequence">
                  <param name="sequence">project_seq</param>
            </generator>
        </id>
        <property name="projectname" column="name" />
        <many-to-one name="projectowner" class="Person" column="owner" />
      </class>
</hibernate-mapping>



and last but not least the config-file

Code:
<?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.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">;-)</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:lehre</property>
        <property name="hibernate.connection.username">pk10</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
         <!-- For each class(es) the corresponding hbm.xml files must be specified -->
        <mapping resource="hibernate/Person.hbm.xml"/>
        <mapping resource="hibernate/Project.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


everything is ok!! eclipse works without any error messages.

but then, it is necessary to build the tables for the oralcle database:

Code:
create table Person(
id integer primary key,
firstname varchar2(30) NOT NULL,
lastname varchar2(30) NOT NULL,
phone varchar2(30) NOT NULL

);



create table Project(

id integer NOT NULL,
name varchar2(50) NOT NULL,
owner integer,
primary key (id),
FOREIGN KEY (owner) REFERENCES Person (id) ON DELETE CASCADE

);



and here i think is the main problem

eclipse tell me the following problem:

SQL Error: 2289, SQLState: 42000
ORA-02289: sequence does not exist

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at hibernate.MainClass.main(MainClass.java:37)
Caused by: java.sql.SQLException: ORA-02289: sequence does not exist

can anybody help me please? its really important...
what does this oracle exception mean? how can i solve it?

thanks!
best greets


Top
 Profile  
 
 Post subject: Simple: No Sequence
PostPosted: Fri Oct 13, 2006 6:49 pm 
Beginner
Beginner

Joined: Thu Jul 06, 2006 11:09 pm
Posts: 25
It seems to me that you haven't created yet the sequence generators (person_seq, project_seq) from the oracle database.

_________________
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 14, 2006 4:13 am 
Newbie

Joined: Fri Oct 13, 2006 6:25 pm
Posts: 3
hm, can you help me please... i don't really understand!

do you mean that?

Code:
create table Person(
id integer primary key,
firstname varchar2(30) NOT NULL,
lastname varchar2(30) NOT NULL,
phone varchar2(30) NOT NULL

);

create sequence person_seq start 1;


create table Project(

id integer NOT NULL,
name varchar2(50) NOT NULL,
owner integer,
primary key (id),
FOREIGN KEY (owner) REFERENCES Person (id) ON DELETE CASCADE

);

create sequence project_seq start 1;


If I understand that correctly, the sequence will increase the value of the ID (always + 1)

is that correct?
can you please give me an example, if it's wrong!!??

thank you very much!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 14, 2006 8:29 am 
Newbie

Joined: Fri Oct 13, 2006 6:25 pm
Posts: 3
yeeeeeeaaaaaaaaahhhhhhhhhhhhhhhh!!!!


it works!

thank you very very much!!!!!

thats the correct solution:

Code:
create table Person(
id integer primary key,
firstname varchar2(30) NOT NULL,
lastname varchar2(30) NOT NULL,
phone varchar2(30) NOT NULL
);

create sequence person_seq;

 
create table Project(
id integer NOT NULL,
name varchar2(50) NOT NULL,
owner integer,
primary key (id),
FOREIGN KEY (owner) REFERENCES Person (id) ON DELETE CASCADE
);

create sequence project_seq;



10000 thanks!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.