openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick" <mik...@apache.org>
Subject Re: Incorrect IDENTITY sequence name in PostgreSQL
Date Wed, 24 Oct 2007 05:11:56 GMT
Hi Ryosuke,

Which version of OpenJPA are you using? Unless you're using a very recent
snapshot you should see something like this (unless you've changed the
logging level) :

12  test  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "
org.apache.openjpa.jdbc.sql.DerbyDictionary" (Apache Derby 10.2.2.0 -
(485682) ,Apache Derby Embedded JDBC Driver 10.2.2.0 - (485682)).

In your case it should say . . . Using dictionary class "
org.apache.openjpa.jdbc.sql.PostgresDictionary" . . .

I'm guessing that it doesn't. The PostgresDictionary sets the max constraint
length to 63, the default value for "generic" databases is 18.

If you're getting something different then there's a bug in the code that
detects which database to use. You can probably work around it by adding
this property to your persistence.xml file :
<property name="openjpa.jdbc.DBDictionary" value="
org.apache.openjpa.jdbc.sql.PostgresDictionary.java"/>

Hope this helps,
-Mike

On 10/23/07, Ryosuke IWATA (DM) <dm-r.iwata@blanche-conseiller.co.jp> wrote:
>
> Hello,
>
> I am having a problem that I cannot persist entities with IDENTITY primary
> key generation into PostgreSQL databases because OpenJPA does not recognize
> correct names of sequences for database IDENTITY columns.
>
> Let me describe details.
>
>
> Suppose that there is an entity like the following:
>         @Entity
>         @Table(name="X_SCHOOL_TRANSFER_EVENT")
>         public class SchoolTransferEvent {
>                 ...
>                 @Id
>                 @GeneratedValue(strategy = GenerationType.IDENTITY)
>                 private Long entityId;
>                 ...
>         }
>
> OpenJPA generates a table for this class in PostgreSQL 8.1.x like this:
>         CREATE TABLE X_SCHOOL_TRANSFER_EVENT
>         (ENTITYID BIGSERIAL ..., PRIMARY KEY(ENTITYID))
>
> PostgreSQL names sequences for the BIGSERIAL columns in the following
> manner:
>         "TABLE_NAME"_"COLUMN_NAME"_SEQ
> So, in the example above, te sequence for the column ENTITYID is named :
>         X_SCHOOL_TRANSFER_EVENT_ENTITY_ID_SEQ
>
>
> When you EntityManager#persist() a new instance of SchoolTransferEvent,
> you will get an exception as follows:
>         org.apache.openjpa.lib.jdbc.ReportingSQLException:
>         ERROR: relation "x_school_membershi_entityid_seq"
>         does not exist {prepstmnt 2398193 SELECT
>         CURRVAL(X_SCHOOL_TRANSFER_entityId_SEQ')}
>         [code=0, state=42P01]
>
> OpenJPA uses an incorrect name for the IDENTITY column sequence.
>         OK : X_SCHOOL_TRANSFER_EVENT_ENTITY_ID_SEQ
>         NG : 'X_SCHOOL_TRANSFER__ENTITYID_SEQ
>
>
> This problem occurs anytime when your database tables have names longer
> than 18 characters. OpenJPA ommits table names, while PostgreSQL uses
> non-omitted names. I will show another example.
>         Table : X_SCHOOL_MEMBERSHIP
>         OK : X_SCHOOL_MEMBERSHIP_ENTITYID_SEQ
>         NG : X_SCHOOL_MEMBERSHI_ENTITYID_SEQ
>
>
> With this problem, we have to abandon using IDENTITY sequence generation
> now.
>
> Does anyone know workarouds for this problem? We need IDENTITY generation
> to make it easier to apply OpenJPA with an existing database.
>
>
> Best regards,
> - Ryosuke Iwata
>   blanche conseiller d'essence, inc.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message