Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Communication Patterns: A Guide for Developers and Architects
this week in the
Design and Architecture
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Object Relational Mapping
SQLGrammarException: could not get next sequence value
Jian Yi
Ranch Hand
Posts: 127
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi everyone,
I'm new to Hibernate. I tried to use the examples in book 'Hibernate Quickly', but using Oracle instead of MySQL. However I got the error:
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)
Jian Yi
Ranch Hand
Posts: 127
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oops, sent out by mistake.
I mean to add the code and table here:
1. Event.java:
public class Event { private Long id; private String name; private Date startDate; private int duration; private Set speakers; private Set attendees; private Location location; public void setId(Long id) { this.id = id; } public Long getId() { return id; } ...
2. Event mapping file:
<hibernate-mapping package="com.manning.hq.ch03"> <class name="Event" table="events"> <id name="id" column="id" type="long" unsaved-value="null"> <generator class="native"/> </id> <property name="name" type="string" length="100"/> <property name="startDate" column="start_date" type="date"/> <property name="duration" type="integer"/> <many-to-one name="location" column="location_id" class="Location"/> <set name="speakers" cascade="all"> <key column="event_id"/> <one-to-many class="Speaker"/> </set> <set name="attendees" cascade="all"> <key column="event_id"/> <one-to-many class="Attendee"/> </set> </class> </hibernate-mapping>
3. events table:
CREATE TABLE events ( id number(10) default 0 not null primary key, name varchar2(255), start_date date, duration number(10), location_id number(10) references locations ) ; CREATE SEQUENCE yinj.EVENTS_KEY START WITH 1 MAXVALUE 9999 MINVALUE 1 NOCYCLE CACHE 20 NOORDER; CREATE OR REPLACE TRIGGER events_BIU_TRG BEFORE INSERT OR UPDATE ON yinj.events REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLARE W_SEQ NUMBER; BEGIN IF :-o LD.id IS NULL THEN SELECT events_KEY.NEXTVAL INTO W_SEQ FROM DUAL; :NEW.id := W_SEQ; END IF; END; /
Anything else I should post here to be helpful to answer my question?
Thanks!
Jenny
Jian Yi
Ranch Hand
Posts: 127
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is the whole error message:
[junit] Running com.manning.hq.ch03.TestEventManager [junit] ------1------- [junit] ------2------- [junit] ------3------- [junit] org.hibernate.exception.SQLGrammarException: could not get next sequence value [junit] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) [junit] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) [junit] at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96) [junit] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98) [junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) [junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175) [junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98) [junit] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) [junit] at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507) [junit] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499) [junit] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495) [junit] at com.manning.hq.ch03.EventManager.save(Unknown Source) [junit] at com.manning.hq.ch03.TestEventManager.testSave(Unknown Source) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [junit] at java.lang.reflect.Method.invoke(Method.java:324) [junit] at junit.framework.TestCase.runTest(TestCase.java:154) [junit] at junit.framework.TestCase.runBare(TestCase.java:127) [junit] at junit.framework.TestResult$1.protect(TestResult.java:106) [junit] at junit.framework.TestResult.runProtected(TestResult.java:124) [junit] at junit.framework.TestResult.run(TestResult.java:109) [junit] at junit.framework.TestCase.run(TestCase.java:118) [junit] at junit.framework.TestSuite.runTest(TestSuite.java:208) [junit] at junit.framework.TestSuite.run(TestSuite.java:203) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:567) [junit] Caused by: java.sql.SQLException: ORA-02289: sequence does not exist [junit] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) [junit] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305) [junit] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272) [junit] at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:626) [junit] at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:182) [junit] at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:500) [junit] at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:942) [junit] at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:532) [junit] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1037) [junit] at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905) [junit] at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2946) [junit] at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75) [junit] ... 25 more [junit] ------4------- [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 10.547 sec
Jian Yi
Ranch Hand
Posts: 127
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Never mind. I got it working.
Mark Spritzler
ranger
Posts: 17347
11
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And was it because it didn't have the sequence name in your mapping?
Mark
Perfect World Programming, LLC
-
iOS Apps
How to Ask Questions the Smart Way FAQ
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Hibernate: ORM Mapping "Could not get next sequence value" SQLCODE: -142
Use of sequence without creating an entity
[Hibernate] Please explain hilo generator
Hibernate- How get next value from a squence
Hibernate - SQLGrammarException : could not get next sequence value
More...