openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <adam....@cyberspaceroad.org>
Subject Re: Primary key field generation with postgres
Date Thu, 27 Mar 2008 16:34:09 GMT
You might want to make that schema.toLowerCase()

Postgres diverges from the JDBC spec by making everything lower case and it 
won't find an upper case schema.

I raised that as a bug with postgres and their developers told me it was 
unlikely to be changed any time soon.

roger.keays on 27/03/08 12:15, wrote:
> Here is my patch for OpenJPA 1.0.2. You might prefer to move the code to the
> superclass though.
> 
> Index:
> openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
> ===================================================================
> ---
> openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java     
> (revision 641780)
> +++
> openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java     
> (working copy)
> @@ -149,6 +149,21 @@
>              "STORE", "VACUUM", "VERBOSE", "VERSION",
>          }));
>      }
> +    
> +    /**
> +     * Prepend schema names to sequence names if there is one. This 
> +     * method does not escape reserved words in the schema name or 
> +     * sequence name.
> +     */
> +    protected String getGeneratedKeySequenceName(Column col) {
> +        String sequence = super.getGeneratedKeySequenceName(col);
> +        String schema = col.getSchemaName();
> +        if (schema != null && schema.length() > 0) {
> +            return schema + "." + sequence;
> +        } else {
> +            return sequence;
> +        }
> +    }
>  
>      public Date getDate(ResultSet rs, int column)
>          throws SQLException {
> 
> 
> Marc LaPierre wrote:
>> It seems like JPA isn't finding your sequence in the ves schema.
>>
>> Are you sure that your sequence exists in Postgres?
>> Are you able to run "select currval('user_id_seq')" from the sql
>> console?
>>
>>
>> Marc
>>
>>
>> -----Original Message-----
>> From: Baumhof@ggrz-hagen.nrw.de [mailto:Baumhof@ggrz-hagen.nrw.de]
>> Sent: Wednesday, February 13, 2008 8:25 AM
>> To: users@openjpa.apache.org
>> Subject: Primary key field generation with postgres
>>
>> I use Postgres 8.2 with jdbc Type 3 driver.
>>
>> I have got the following table definition:
>>
>>
>>
>> create table ves.user
>>
>> (id                    serial    not null,
>>
>>  user                 varchar(20) not null,
>>
>>  password         varchar(20) not null,
>>
>>  constraint pk_ves_user primary key(id)
>>
>> );
>>
>>
>>
>>
>>
>> My PAO Class looks like:
>>
>>
>>
>> @Entity
>>
>> @Table(schema="ves", name="user")
>>
>> public class UserPAO implements Serializable {
>>
>>             @Id
>>
>>             @GeneratedValue(strategy=IDENTITY)
>>
>>             @Column(insertable=false, updatable = false)
>>
>>             private long id;
>>
>>             ....
>>
>>
>>
>> Trying to insert a new user results in an persistence exception: The
>> invalid statement is reported
>>
>> As: select currval('user_id_seq')
>>
>>
>>
>> But the table is in the schema "ves", so the correct name of the
>> sequence is ves.user_id_seq.
>>
>> If I put the table into the public schema, and omit the schema="ves"
>> statement in the @Table
>>
>> annotation, all works.
>>
>>
>>
>> How can I use automatic key generation with Postgres without putting the
>> table into the public schema??
>>
>> Table generation and all other things did not work.


Mime
View raw message