You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by John McNally <jm...@collab.net> on 2001/10/22 18:38:57 UTC

Re: Torque and Postgresql

you need to specify which idMethod you are wanting to use.  If you are
wanting to use sequences then use <table idMethod="sequence"... or
idMethod="native".  native is the preferred way, but not sure that works
in the current released version.

john mcnally

Rolf Woll wrote:
> 
> I am currently experimenting with the Torque part of Turbine. I have
> followed the example written by Steve Davies in an example previously
> posted to this list.
> 
> I have problems with writing objects to the postgres database. It seems
> that the sequence that should create a new database id is not invoked,
> thus causing the id field to be null. Since the id field is defined as
> "not null" this causes an exceptions.
> 
> Details:
> 
> I have made a very simple schema,
> 
> <app-data>
> <database>
>    <table name="DVD">
>      <column name="dvd_oid" required="true" autoIncrement="true"
>              primaryKey="true" type="INTEGER"/>
>      <column name="name" required="true" type="LONGVARCHAR"/>
>    </table>
> </database>
> 
> </app-data>
> 
> This is mapped in postgresql to a database definition like this:
> 
>           List of relations
>        Name       |   Type   | Owner
> -----------------+----------+-------
>   dvd             | table    | rolfw
>   dvd_dvd_oid_seq | sequence | rolfw
> 
>   Attribute |   Type    |                     Modifier
> -----------+-----------+---------------------------------------------------
>   dvd_oid   | integer   | not null default nextval('dvd_dvd_oid_seq'::text)
>   name      | varchar() | not null
> 
> It seems to me as the Peer and Base classes is also build correctly.
> To test the application I have made a simple Test class like this:
> 
> package com.anakon.test.turbine;
> import org.apache.torque.Torque;
> 
> public class Test {
>      public static String cvsid = "$Id$";
>      public static void main(String[] args) {
>         try {
>         Torque.init("test.properties");
>             Dvd dvd = new Dvd();
>             dvd.setName("Flåklypa GP");
>             dvd.save();
>         }
>         catch(Exception e) {
>             e.printStackTrace();
>         }
>      }
> 
> }// Test
> 
> The Test.class should write one record to the database. My
> test.properties is copy of mytest.properties from Steve Davis' example,
> where the database adapter,URL,password and driver are changed. However,
> when running it, I get the following exception:
> 
> bash-2.05$ java com.anakon.test.turbine.Test
> java.sql.SQLException: ERROR:  ExecAppend: Fail to add null value in not
> null attribute dvd_oid
> 
>          at org.postgresql.Connection.ExecSQL(Connection.java:393)
>          at org.postgresql.jdbc2.Statement.execute(Statement.java:273)
>          at org.postgresql.jdbc2.Statement.executeUpdate(Statement.java:73)
>          at
> org.postgresql.jdbc2.PreparedStatement.executeUpdate(PreparedStatement.java:126)
>          at com.workingdogs.village.Record.saveWithInsert(Record.java:328)
>          at com.workingdogs.village.Record.save(Record.java:185)
>          at com.workingdogs.village.Record.save(Record.java:166)
>          at
> org.apache.torque.util.BasePeer.insertOrUpdateRecord(BasePeer.java:927)
>          at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:809)
>          at
> com.anakon.test.turbine.BaseDvdPeer.doInsert(BaseDvdPeer.java:126)
>          at
> com.anakon.test.turbine.BaseDvdPeer.doInsert(BaseDvdPeer.java:366)
>          at com.anakon.test.turbine.BaseDvd.save(BaseDvd.java:245)
>          at com.anakon.test.turbine.BaseDvd.save(BaseDvd.java:214)
> 
> It seems that the sequence is not used to create a new identifier,
> dvd_oid for the column.
> 
> Any ideas would be appreciated.
> 
> --
> Regards
> Rolf Woll
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org