Here I am, replying to myself... Well, did a little research on the
subject, and `[tablename]_[columnname]_sec' really is the default
sequence name for SERIAL columns on PostgreSQL. Quoting from the
PostgreSQL Users Guide:
---8<---------------------------------------------------------------------
The Serial Type
The serial type is a special-case type constructed by Postgres from
other existing components. It is typically used to create unique
identifiers for table entries. In the current implementation, specifying
CREATE TABLE tablename (colname SERIAL);
is equivalent to specifying:
CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename
(colname INT4 DEFAULT nextval('tablename_colname_seq');
CREATE UNIQUE INDEX tablename_colname_key on tablename (colname);
---8<---------------------------------------------------------------------
I modified SequenceKeyGenerator.java (in
org.exolab.castor.jdo.drivers), and now `{1}' expands to the columns'
name. If you don't use `{1}' in your sequence, you won't notice any
changes, so I'm pretty positive I didn't break anything.
Attached is the patch against Castor 0.9.3, please comment on it. I'm
using the patched Castor right now, I'll report anything strange.
On Tue, 2001-12-11 at 14:38, Daniel Serodio wrote:
> I'm learning to use Castor JDO, and I have run into the following
> problem:
>
> I use `<tablename>_<columnname>_seq' for naming my PostgreSQL
> sequences. I the docs, I can see that `{0}' expands to the table name.
> Is there some way to make `{1}' expand to the column name? I tried:
>
> <key-generator name="SEQUENCE">
> <param name="sequence" value="{0}_{1}_seq"/>
> </key-generator>
>
> But got ``java.sql.SQLException: ERROR: pg_aclcheck: class
> "product_{1}_seq" not found''.
--
[]'s
Daniel Serodio <[EMAIL PROTECTED]>
--- SequenceKeyGenerator.java Tue Dec 11 18:35:48 2001
+++ SequenceKeyGenerator.java.dist Tue Dec 11 18:35:46 2001
@@ -170,7 +170,7 @@
} else {
if ( _style == BEFORE_INSERT ) {
stmt = conn.prepareStatement("SELECT nextval('" +
- MessageFormat.format( _seqName, new String[] {tableName,
primKeyName}) + "')" );
+ MessageFormat.format( _seqName, new String[] {tableName})
++ "')" );
rs = stmt.executeQuery();
} else if (_triggerPresent && _factoryName.equals( "postgresql" )) {
Object insStmt = props.get("insertStatement");
@@ -185,7 +185,7 @@
} else {
stmt = conn.prepareStatement("SELECT " + _factory.quoteName(
- MessageFormat.format( _seqName, new String[] {tableName,
primKeyName} ) +
+ MessageFormat.format( _seqName, new String[] {tableName}
+) +
".currval") + " FROM " + _factory.quoteName( tableName )
);
rs = stmt.executeQuery();
}