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 = new ColumnValues();
        if (!type.isNew() 
            || type.getTypeId() != 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/buildColumnValues.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/java/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="type"
         description="Company Types"
         idMethod="native"
         interface="com.example.Type">
    <column
      name="type_id"
      required="true"
      primaryKey="true"
      autoIncrement="true"
      type="INTEGER"
      javaType="primitive"
      description="Type Id"/>
    <column
      name="serial"
      required="true"
      type="VARCHAR"
      description="Serial Number"/>
    <column
      name="name"
      required="true"
      type="VARCHAR"
      description="Name of the type"/>
    <column
      name="description"
      required="true"
      type="VARCHAR"
      description="Friendly description of the type"/>
    <column
      name="signature_id"
      required="true"
      type="INTEGER"
      description="Digital signature locking this row"/>
    <foreign-key foreignTable="signature" onUpdate="cascade" onDelete="cascade">
      <reference
        local="signature_id"
        foreign="signature_id"/>
    </foreign-key>
    <unique name="type_unique">
      <unique-column name="serial"/>
    </unique>
    <index name="type_index">
      <index-column name="serial"/>
    </index>
  </table>

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

Regards,
Graham
--





Reply via email to