0

I used the annotation suggestion from this article:

How to use existing Oracle sequence to generate id in hibernate?

@GenericGenerator(name = "announcementGenerator", strategy = "sequence-identity", 
                    parameters = @org.hibernate.annotations.Parameter(name = "sequence", value = "ANNOUNCEMENT_ID_SEQ"))
@Id
@GeneratedValue(generator = "announcementGenerator")
@Column(name="ANNOUNCEMENT_ID")

But I still get the error in the title. The generated sql from hibernate seems to include

next value for ANNOUNCEMENT_ID_SEQ

Instead of the traditional

ANNOUNCEMENT_ID_SEQ.nextval

I've also used the suggestion in this article: ORA-00917: missing comma error while using custom oracle sequence in hiberanate

And it put a null in the place of the primary key... which makes sense with the annotation given in that article.

Am I missing something? Any assistance would be appreciated. Thanks in advance!

Community
  • 1
  • 1
Shino
  • 99
  • 12

1 Answers1

0

From Hibernate doc about sequence-identity

This strategy is only supported on Oracle 10g drivers targeted for JDK 1.4.

If you aren't using 10g set strategy = "sequence" or "native" can solve the problem.

Else use

@GeneratedValue(strategy=GenerationType.AUTO, generator="announcementGenerator")
@SequenceGenerator(name="announcementGenerator", sequenceName="ANNOUNCEMENT_ID_SEQ")

Hope can help.

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • Thanks for your quick response. Using what your "else" is what I mentioned I tried from the second article. I did get this to work, but only with a String type as the id field. It should not be a string type, it should be of type Long. But no matter what type I make the id, it gives me `"ERROR: Invalid column type: get[TypeUsed] not implemented for class oracle.jdbc.driver.T4CRowidAccessor"` I've tried long, Long, Integer, BigInteger and BigDecimal. They all do the same thing. When using String, it inserts the column using the seq but the id I get back is like 'AAAQIkAAGAAAEI2AAB.' Thoughts? – Shino Aug 25 '13 at 18:51
  • Also with GenerationType.SEQUENCE? – Luca Basso Ricci Aug 25 '13 at 19:01
  • Doing that tries to grab the sequence incorrectly as so (from logs): `Hibernate: call next value for ANNOUNCEMENT_ID_SEQ` and it gives me `ERROR: ORA-06576: not a valid function or procedure name` ... This kinda baffles me b/c I've done this with DB2 and had no issues. Move to using oracle and it blows up in my face. :( Shouldn't hibernate know to use SEQ.nextval ... I'm not sure why it's trying to do it that way. – Shino Aug 25 '13 at 19:26
  • 1
    Is the dialect correctly setted? Or maybe a driver issue. I can't help more, I'm sorry :| – Luca Basso Ricci Aug 25 '13 at 19:49
  • 1
    Checking into the dialect. We're on 11g (11.2.0.3) and are using the correct driver for that version of oracle and the version of java we are developing against. Thank you for your input up to this point. I appreciate it. – Shino Aug 26 '13 at 13:25
  • 1
    It was the dialect. I was using org.hibernate.dialect.HSQLDialect and switched to org.hibernate.dialect.Oracle10gDialect. THANKS A LOT! – Shino Aug 26 '13 at 14:51