-->
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: ORA-02289: sequence does not exist
PostPosted: Tue Apr 07, 2009 6:52 am 
Newbie

Joined: Thu Mar 19, 2009 6:28 am
Posts: 3
Hi,

I have written a sample hibernate program.

Hibernate version: 3.3.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com">
<class
name="Test"
table="TEST"
>
<meta attribute="sync-DAO">false</meta>

<id name="id" column="ID" type="java.lang.Long">
<generator class="native"/>
</id>

<property
name="name"
column="NAME"
type="string"
not-null="false"
length="20"
/>
<property
name="mdt"
column="MDT"
type="java.lang.String"
not-null="false"
length="11"
/>
</class>
</hibernate-mapping>



mapping class file:

package com.base;

import java.io.Serializable;


/**
* This is an object that contains data related to the TEST table.
* Do not modify this class because it will be overwritten if the configuration file
* related to this class is modified.
*
* @hibernate.class
* table="TEST"
*/

public abstract class BaseTest implements Serializable {

public static String REF = "Test";
public static String PROP_NAME = "name";
public static String PROP_ID = "id";
public static String PROP_MDT = "mdt";


// constructors
public BaseTest () {
initialize();
}

/**
* Constructor for primary key
*/
public BaseTest (java.lang.Long id) {
this.setId(id);
initialize();
}

protected void initialize () {}



private int hashCode = Integer.MIN_VALUE;

// primary key
private java.lang.Long id;

// fields
private java.lang.String name;
private java.lang.String mdt;



/**
* Return the unique identifier of this class
* @hibernate.id
* generator-class="native"
* column="ID"
*/
public java.lang.Long getId () {
return id;
}

/**
* Set the unique identifier of this class
* @param id the new ID
*/
public void setId (java.lang.Long id) {
this.id = id;
this.hashCode = Integer.MIN_VALUE;
}




/**
* Return the value associated with the column: NAME
*/
public java.lang.String getName () {
return name;
}

/**
* Set the value related to the column: NAME
* @param name the NAME value
*/
public void setName (java.lang.String name) {
this.name = name;
}



/**
* Return the value associated with the column: MDT
*/
public java.lang.String getMdt () {
return mdt;
}

/**
* Set the value related to the column: MDT
* @param mdt the MDT value
*/
public void setMdt (java.lang.String mdt) {
this.mdt = mdt;
}




public boolean equals (Object obj) {
if (null == obj) return false;
if (!(obj instanceof com.Test)) return false;
else {
com.Test test = (com.Test) obj;
if (null == this.getId() || null == test.getId()) return false;
else return (this.getId().equals(test.getId()));
}
}

public int hashCode () {
if (Integer.MIN_VALUE == this.hashCode) {
if (null == this.getId()) return super.hashCode();
else {
String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
this.hashCode = hashStr.hashCode();
}
}
return this.hashCode;
}


public String toString () {
return super.toString();
}


}


Code between sessionFactory.openSession() and session.close():
Test t = new Test();
sess.save(t);




hibernate config xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">portal</property>
<property name="hibernate.connection.password">portal</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="Test.hbm.xml"/>

</session-factory>
</hibernate-configuration>



Full stack trace of any exception that occurs:
Hibernate: select hibernate_sequence.nextval from dual
helloorg.hibernate.exception.SQLGrammarException: could not get next sequence value
5256 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 2289, SQLState: 42000
5256 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-02289: sequence does not exist


Name and version of the database you are using: Oracle 10g

Please help me in resolving this issue.

Thanks,
Sri


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 9:32 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 2:46 pm
Posts: 45
Location: Saskatoon SK Canada
Did you read the error message and check the Oracle documentation?

Try this: Using SQL*Plus, login into the account PORTAL on the database XE and enter the following command:

CREATE SEQUENCE HIBERNATE_SEQUENCE;

_________________
Maury


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 11:02 am 
Newbie

Joined: Thu Mar 19, 2009 6:28 am
Posts: 3
MjH wrote:
Did you read the error message and check the Oracle documentation?

Try this: Using SQL*Plus, login into the account PORTAL on the database XE and enter the following command:

CREATE SEQUENCE HIBERNATE_SEQUENCE;


Thanks.

I can create a sequence in the database, but I have given the id generator as native, so that I can decouple my code from db specific.

So I am wondering, what would be the solution for this problem?

Thanks,
Sri


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 11:51 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 2:46 pm
Posts: 45
Location: Saskatoon SK Canada
mango wrote:
I can create a sequence in the database, but I have given the id generator as native, so that I can decouple my code from db specific.

So I am wondering, what would be the solution for this problem?

Thanks,
Sri


What makes you think there is a problem? If you check the Hibernate reference document, section 5.1.4.1, it states:

Code:
native

    picks identity, sequence or hilo depending upon the capabilities of the underlying database.


Since Oracle doesn't have identity columns (at least, it didn't the last time I looked), then Hibernate must choose one of the latter two options. Looking at the source code, it appears that the Dialect code checks the options in the same order as the documentation -- identity, sequence, and then hilo. So, when using Oracle, Hibernate is going to use a sequence.

If you move your code to another database engine that does support identity columns, it will use those.

_________________
Maury


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.