Torque7 and postgresql autoincrementing primary keys not working

"Graham Leggett via torque-dev" <[email protected]> Mon, 15 Jun 2026 22:54:08 +0100
Newsgroups gmane.comp.jakarta.turbine.torque.devel
Message-ID <[email protected]>
--Apple-Mail=_9C999E88-860F-48D6-8786-D54C64D35EEF
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Hi all,

After upgrading from torque3.3 to torque7 (big jump), I have everything =
compiling, but what has suddenly vanished are autoincrementing database =
primary keys for postgres.

The generated code looks like this:

    public ColumnValues buildColumnValues(Type type)
            throws TorqueException
    {
        ColumnValues columnValues =3D new ColumnValues();
        if (!type.isNew()=20
            || type.getTypeId() !=3D 0)
        {
            columnValues.put(
                    TypePeer.TYPE_ID,
                    new JdbcTypedValue(
                        type.getTypeId(),
                        4));
        }
        columnValues.put(
                TypePeer.SERIAL,
                new JdbcTypedValue(
                    type.getSerial(),
                    12));
        columnValues.put(
                TypePeer.NAME,
                new JdbcTypedValue(
                    type.getName(),
                    12));
        columnValues.put(
                TypePeer.DESCRIPTION,
                new JdbcTypedValue(
                    type.getDescription(),
                    12));
        columnValues.put(
                TypePeer.SIGNATURE_ID,
                new JdbcTypedValue(
                    type.getSignatureId(),
                    4));
        return columnValues;
    }

When the object isNew(), and the type_id is the default value of 0, it =
is expected that the sequence mechanism kicks in and uses the postgresql =
sequence to populate the field.

This is missing from the above code, type_id isn't set at all, and so =
the insert fails as expected with a NOT NULL constraint.

This corresponds to this template, which doesn't show anything related =
to auto increment:

=
http://svn.apache.org/repos/asf/db/torque/trunk/torque-templates/src/main/=
resources/org/apache/torque/templates/om/templates/peer/impl/base/buildCol=
umnValues.vm

I am assuming there is a step before that calls this:

=
https://svn.apache.org/repos/asf/db/torque/trunk/torque-runtime/src/main/j=
ava/org/apache/torque/adapter/PostgresAdapter.java

    /**
     * @param name The name of the field (should be of type
     *      <code>String</code>).
     * @return SQL to retreive the next database key.
     * @see org.apache.torque.adapter.Adapter#getIDMethodSQL(Object)
     */
    @Override
    public String getIDMethodSQL(Object name)
    {
        return ("select nextval('" + name + "')");
    }

But stepping through in the debugger doesn't take me anywhere near the =
code.

The table is defined like this:

  <table name=3D"type"
         description=3D"Company Types"
         idMethod=3D"native"
         interface=3D"com.example.Type">
    <column
      name=3D"type_id"
      required=3D"true"
      primaryKey=3D"true"
      autoIncrement=3D"true"
      type=3D"INTEGER"
      javaType=3D"primitive"
      description=3D"Type Id"/>
    <column
      name=3D"serial"
      required=3D"true"
      type=3D"VARCHAR"
      description=3D"Serial Number"/>
    <column
      name=3D"name"
      required=3D"true"
      type=3D"VARCHAR"
      description=3D"Name of the type"/>
    <column
      name=3D"description"
      required=3D"true"
      type=3D"VARCHAR"
      description=3D"Friendly description of the type"/>
    <column
      name=3D"signature_id"
      required=3D"true"
      type=3D"INTEGER"
      description=3D"Digital signature locking this row"/>
    <foreign-key foreignTable=3D"signature" onUpdate=3D"cascade" =
onDelete=3D"cascade">
      <reference
        local=3D"signature_id"
        foreign=3D"signature_id"/>
    </foreign-key>
    <unique name=3D"type_unique">
      <unique-column name=3D"serial"/>
    </unique>
    <index name=3D"type_index">
      <index-column name=3D"serial"/>
    </index>
  </table>

Is idMethod=3D"native" correct or should this be something else?

Regards,
Graham
--






--Apple-Mail=_9C999E88-860F-48D6-8786-D54C64D35EEF--