aspose file tools
The moose likes Object Relational Mapping and the fly likes DB2 + JPA generated value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "DB2 + JPA generated value" Watch "DB2 + JPA generated value" New topic
Author

DB2 + JPA generated value

Bram Pramono
Greenhorn

Joined: Feb 19, 2009
Posts: 6
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


SCJP 5
Nigel Kibble
Greenhorn

Joined: May 26, 2005
Posts: 1
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.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: DB2 + JPA generated value
 
Similar Threads
The chosen transaction strategy requires access to the JTA TransactionManager
Id problem in annotation based mapping when using xml based id.
JPA Mapping Exception
Error installing to Start: name=persistence.unit:
EJB 3.0 - Mapping relationship between entity beans.