• 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
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

DB2 + JPA generated value

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Does anyone here have experience with JPA/DB2 mapping?

I have tried many things but I cannot get it work properly. I am working with JPA and DB2 database for AS400.

Below are the 2 my mapping files possibilities I have tried:
- Mapping 1: using sequence


- Error from Mapping 1 :
* org.hibernate.exception.SQLGrammarException: could not get next sequence value
* java.sql.SQLException: [SQL0029] INTO clause missing from embedded statement.

- Mapping 2 : using Identity



- Error from Mapping 2:
* util.JDBCExceptionReporter [SQL0798] Value cannot be specified for GENERATED ALWAYS column ID.
* org.hibernate.util.JDBCExceptionReporter - [SQL0798] Value cannot be specified for GENERATED ALWAYS column ID.

My question is has anyone worked with JPA / DB2? If you do, how did you configure your database table and jpa? Did you use sequence or identity?

Please help.

Thank you in advance.

Cheers,

Bram
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bram,

I've got some experience of using JPA with the AS/400, which I hope will be of some help.

The choice between SEQUENCE and IDENTIFIER comes down to whether you can modify the existing table or not.
If you are in a position where you can alter the table, then you can add an identifier column to it, like so:


then, in your java entity have the following:


If, on the other hand, you're not in a position to alter the table, you can create an SQL sequence to apply an identifier for you.
On the AS/400 you'll need to enter in:



And then in your java entity have the following:


You'll probably want a separate sequence for each table.

Hope this helps.

Nigel.

 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic