-->
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: Mon Jun 16, 2008 12:09 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 3:18 am
Posts: 32
Hello,
I'm using hibernate 2 with Spring 2 and Oracle 9i to create a web application.
I'm getting the following error when trying to save an object.

Quote:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not save object; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-02289: sequence does not exist


Although I created a sequence.

Please, find below my class and hibernate mapping file.

Class:

Code:
public class User {
   private Long id;
   private String firstName;
   private String lastName;
   private String email;
   private String password;
   private String organization;
   private String streetAddress;
   private String city;
   private String country;
   private String state;
   private String telephone;
   private Date registrationTimestamp;
   private Boolean isActive;
   
   
   /**
    * @return Returns the isActive.
    */
   public Boolean getIsActive() {
      return isActive;
   }
   /**
    * @param isActive The isActive to set.
    */
   public void setIsActive(Boolean isActive) {
      this.isActive = isActive;
   }
   /**
    * @return Returns the city.
    */
   public String getCity() {
      return city;
   }
   /**
    * @param city The city to set.
    */
   public void setCity(String city) {
      this.city = city;
   }
   /**
    * @return Returns the country.
    */
   public String getCountry() {
      return country;
   }
   /**
    * @param country The country to set.
    */
   public void setCountry(String country) {
      this.country = country;
   }
   /**
    * @return Returns the email.
    */
   public String getEmail() {
      return email;
   }
   /**
    * @param email The email to set.
    */
   public void setEmail(String email) {
      this.email = email;
   }
   /**
    * @return Returns the firstName.
    */
   public String getFirstName() {
      return firstName;
   }
   /**
    * @param firstName The firstName to set.
    */
   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   /**
    * @return Returns the id.
    */
   public Long getId() {
      return id;
   }
   /**
    * @param id The id to set.
    */
   public void setId(Long id) {
      this.id = id;
   }
   /**
    * @return Returns the lastName.
    */
   public String getLastName() {
      return lastName;
   }
   /**
    * @param lastName The lastName to set.
    */
   public void setLastName(String lastName) {
      this.lastName = lastName;
   }
   /**
    * @return Returns the organization.
    */
   public String getOrganization() {
      return organization;
   }
   /**
    * @param organization The organization to set.
    */
   public void setOrganization(String organization) {
      this.organization = organization;
   }
   /**
    * @return Returns the password.
    */
   public String getPassword() {
      return password;
   }
   /**
    * @param password The password to set.
    */
   public void setPassword(String password) {
      this.password = password;
   }
   /**
    * @return Returns the registrationTimestamp.
    */
   public Date getRegistrationTimestamp() {
      return registrationTimestamp;
   }
   /**
    * @param registrationTimestamp The registrationTimestamp to set.
    */
   public void setRegistrationTimestamp(Date registrationTimestamp) {
      this.registrationTimestamp = registrationTimestamp;
   }
   /**
    * @return Returns the state.
    */
   public String getState() {
      return state;
   }
   /**
    * @param state The state to set.
    */
   public void setState(String state) {
      this.state = state;
   }
   /**
    * @return Returns the streetAddress.
    */
   public String getStreetAddress() {
      return streetAddress;
   }
   /**
    * @param streetAddress The streetAddress to set.
    */
   public void setStreetAddress(String streetAddress) {
      this.streetAddress = streetAddress;
   }
   /**
    * @return Returns the telephone.
    */
   public String getTelephone() {
      return telephone;
   }
   /**
    * @param telephone The telephone to set.
    */
   public void setTelephone(String telephone) {
      this.telephone = telephone;
   }
   
   public String toString() {
      return new ToStringBuilder(this)
      .append("firstName", this.firstName)
      .append("lastName", this.lastName)
      .append("email", this.email)
      .toString();
   }

   public boolean equals(Object o) {
      if (o == this) {
         return true;
      }
      if (!(o instanceof User)) {
         return false;
      }
      User rhs = (User) o;
      return new EqualsBuilder()
      .append("firstName", this.firstName)
      .append("lastName", this.lastName)
      .append("email", this.email)
      .isEquals();
   }

   public int hashCode() {
      return new HashCodeBuilder(2090939697, 874530185)
      .append( this.firstName)
      .append(this.lastName)
      .append(this.email)
      .toHashCode();
   }
}



Hibernate hbm:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping
>
    <class
        name="com.userManagement.model.User"
        table="SIK_IMAGE_FF_ACCOUNT"
    >

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


        </id>
       
        <property
            name="firstName"
            type="java.lang.String"
            update="true"
            insert="true"
            column="FIRST_NAME"
        />
       
        <property
            name="lastName"
            type="java.lang.String"
            update="true"
            insert="true"
            column="LAST_NAME"
        />
       
      <property
            name="email"
            type="java.lang.String"
            update="true"
            insert="true"
            column="EMAIL"
        />
       
        <property
            name="password"
            type="java.lang.String"
            update="true"
            insert="true"
            column="PASSWORD"
        />
       
        <property
            name="organization"
            type="java.lang.String"
            update="true"
            insert="true"
            column="ORGANIZATION"
        />
       
        <property
            name="streetAddress"
            type="java.lang.String"
            update="true"
            insert="true"
            column="STREET_ADDRESS"
        />
       
        <property
            name="city"
            type="java.lang.String"
            update="true"
            insert="true"
            column="CITY"
        />
       
        <property
            name="country"
            type="java.lang.String"
            update="true"
            insert="true"
            column="COUNTRY"
        />
       
        <property
            name="state"
            type="java.lang.String"
            update="true"
            insert="true"
            column="STATE"
        />
       
        <property
            name="telephone"
            type="java.lang.String"
            update="true"
            insert="true"
            column="TELEPHONE"
        />
       
        <property
            name="registrationTimestamp"
            type="java.util.Date"
            update="true"
            insert="true"
            column="REGISTRATION_TIMESTAMP"
        />
       
        <property
            name="isActive"
            type="java.lang.Boolean"
            update="true"
            insert="true"
            column="ACTIVATED"
        />
       
    </class>

</hibernate-mapping>


The sequence USER_SEQUENCE is already created but I still get the same error.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 12:32 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Hi,
Just some thoughts
check the following:

is the sequence type same as id ( try with id type="integer")

I guess you hibernate configuration dialect is set correctly ( Oracle)


what about the sequence permission who owns the sequence and does the databae user ( hibernate configuration database user setting) has access to the sequence ( permission)

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:59 am 
Beginner
Beginner

Joined: Tue Dec 21, 2004 3:18 am
Posts: 32
Hi,
Thanks alanmehio for your reply.
I checked hibernate logs and I found that Hibernate ignores the sequence I used in the hbm file and uses another sequence named hibernate_sequence.
When I created this sequence on my database everything went fine.

I can't understand why hibernate ignores the sequence I created.
What if I want to use any sequence other tha hibernate's default?

Thanks.


Top
 Profile  
 
 Post subject: Re: java.sql.SQLException: ORA-02289: sequence does not exist
PostPosted: Tue Dec 21, 2010 4:11 pm 
Newbie

Joined: Fri Feb 23, 2007 4:37 pm
Posts: 4
Check out this link http://www.orafaq.com/forum/t/61725/2/
I know this is old, but going to be helpful for people searching for this solution later
When Hibernate didn't have permission to access your named sequence, it uses default hibernate_sequence to generate id. If it's not there also, you got the error.

If you added the sequence yourself, but don't have enough permission. Oracle won't do it, but won't show any error.
Check permission on your sequence with
select * from dba_sequences where sequence_name='YOUR_SEQ';

_________________
Tim


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.