1

Hi i am getting this error while i am trying to use my oracle db sequence in hibernates. i am using this declaration :

@Entity
@Table(name = "T_USER_DETAILS")
public class User {


@GenericGenerator(name = "generator",strategy = "sequence-identity",parameters = { @Parameter(name = "sequence",value = "USER_ID_SEQ")} )
@Id 
@GeneratedValue(generator = "generator")
@Column(name = "USER_ID")
private int userid;

..

and using this to persist my entity instance:

            session = sessionFactory.openSession();

        //creating the new transaction from the above created session that is starting a new unit of work
        transaction = session.beginTransaction();

        session.save(user);
        transaction.commit();
        System.out.println("User saved successfully in the database");
        }
        catch(Exception ex)
        {

but i am getting the error:

Apr 11, 2013 11:10:20 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00917: missing comma

caught : ORA-00917: missing comma

Could anyone assist on this?

Johanna
  • 5,223
  • 1
  • 21
  • 38
shashi
  • 201
  • 2
  • 12
  • Please set the sql trace with `true` in `hibernate.cfg.xml` and post the output. There you (and we) can see which comma Oracle doesn't like. – Johanna Apr 11 '13 at 12:28
  • Here it is :Hibernate: insert into T_USER_DETAILS2 (USER_ID, USER_ADDRESS, USER_AGE, USER_EMAIL, USER_FIRSTNAME, USER_LASTNAME, USER_PASSWORD, USER_PHONE) values (next value for my_sequence, ?, ?, ?, ?, ?, ?, ?) Apr 16, 2013 1:19:37 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 917, SQLState: 42000 Apr 16, 2013 1:19:37 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ORA-00917: missing comma caught : org.hibernate.exception.SQLGrammarException: ORA-00917: missing comma – shashi Apr 15 '13 at 19:52
  • i have just my table name and sequence name everything else is still same and i am stil gettign the same error – shashi Apr 15 '13 at 19:55

1 Answers1

0

In Oracle the correct syntax is USER_ID_SEQ.nextval so that's probably where your syntax error is coming from.

Here's an example thread with some code you can refer to: HIbernate issue with Oracle Trigger for generating id from a sequence

[Edit] From the link try using ...

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="a1")
@SequenceGenerator(name="a1", sequenceName="USER_ID_SEQ")
@Column(name = "USER_ID")
private int userid;

... and upgrade to the latest Hibernate JAR

Community
  • 1
  • 1
Brad
  • 15,186
  • 11
  • 60
  • 74
  • yes i know that...problem here is i am not writing this query its the hibernate which is generating it for me when i calls save(user) method. thoughts??? – shashi Apr 16 '13 at 07:04
  • From the link I posted. I'd recommend using the same annotations as they have described i.e. `GeneratedValue` and `SequenceGenerator` to see if that changes the behaviour. Also upgrade your version of Hibernate in case this is an issue that has been subsequently fixed. – Brad Apr 17 '13 at 14:04