1

I am using hibernate and an oracle DB to try and insert a automated ID into a table using a sequence. The sequence defiantly exists on database but hibernate doesn't seem to be able to find it.

Here is all the relevant information:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.hibernate.exception.SQLGrammarException: could not get next sequence value
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        ....
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
        ....
    ... 12 more

I know it says "Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist" but I can access the sequence on the database:

Table:

CREATE TABLE Property(
  id INT,
  address VARCHAR2(50),
  town VARCHAR2(50),
    postCode VARCHAR2(50),
    purchasePrice INT
);

Sequence:

create sequence property_seq start with 1 increment by 1 nomaxvalue; 

Mapping xml:

<class name="com.rental.model.property.Property" table="PROPERTY">
    <meta attribute="class-description"> This class contains the property detail. </meta>
    <id name="id" type="integer" column="id">
        <generator class="sequence"/>
    </id>
    <property name="address" column="ADDRESS" type="string" />
    <property name="town" column="TOWN" type="string" />
    <property name="postCode" column="POSTCODE" type="string" />
    <property name="purchasePrice" column="PURCHASEPRICE" type="integer" />
</class>

annotation:

@Id
@SequenceGenerator(name="property_seq", sequenceName="property_seq", allocationSize=1, initialValue=1) 
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator="property_seq")
public int getId() {
    return id;
}
3
  • Is the sequence object created in the same schema as that of the user logged-in to the hibernate session? If not, did you create a synonym and grant access to the sequence? Commented Aug 6, 2013 at 13:32
  • maybe try adding a public synonym on property_seq Commented Aug 6, 2013 at 13:32
  • The user used by Hibernate is the same as the user that created the sequence Commented Aug 6, 2013 at 13:35

1 Answer 1

2

Why are you using xml AND @Annotation at the same time? Maybe xml definition wins against annotation and Hibernate is retriving default sequence instead of your property_seq.
Try remove xml mapping and check if it works.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Bellabax. I removed the xml totally and added in all other annotations and then changed my factory to: factory = new AnnotationConfiguration().configure().addAnnotatedClass(Property.class). buildSessionFactory();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.