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