newbie question on platform sequence

11 views
Skip to first unread message

Frank Lynch

unread,
Nov 14, 2011, 6:05:30 PM11/14/11
to glorp-group
Hi All,

Just started using GLORP and experimenting with it to learn how to use
it. I have a table called "PORTFOLIOS" that holds objects of type
PortfolioEntry. aPortfolioEntry has three fields: id, stockSymbol and
portfolioName. Here is the descriptor code that I have:

tableForPORTFOLIOS: aTable

(aTable createFieldNamed: 'id' type: platform sequence) bePrimaryKey.
aTable createFieldNamed: 'stockSymbol' type: (platform varChar: 50).
aTable createFieldNamed: 'portfolioName' type: (platform varChar: 50)


descriptorForPortfolioEntry: aDescriptor

| table |
table := self tableNamed: 'PORTFOLIOS'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #portfolioName
to: (table fieldNamed: 'portfolioName').
(aDescriptor newMapping: DirectMapping) from: #stockSymbol
to: (table fieldNamed: 'stockSymbol').
(aDescriptor newMapping: DirectMapping) from: #id
to: (table fieldNamed: 'id')


I can create the table but when I attempt to add a record I get an
exception:
'ERROR: relation "portfolios_id_seq" does not exist at character
16'. I am not sure what it is complaining about and looking at the
stack backtrace does not help me.

My objective was to have the system generate the "id" automatically.
What am I doing wrong?

Thanks,
Frank

------------
I am using VisualWorks and Postgresql

Alan Knight

unread,
Nov 15, 2011, 9:41:42 AM11/15/11
to glorp...@googlegroups.com
What it's complaining about is that the database sequence portfolios_id_seq doesn't exist. That's what it wants to use in order to generate the primary key.

When you say that you create the table, how did you create it? If you create it manually, does the "id" column have a sequence associated with it? This is easy to see in pgadmin3. You can also ask Glorp to create the tables using something like
  
  MyDescriptorSystem createTablesFor: aLogin




Frank Lynch
14 November, 2011 6:05 PM

Frank Lynch

unread,
Nov 15, 2011, 2:18:24 PM11/15/11
to glorp-group
Here is how I was creating the table (I got the code from the
tutorial):
| login accessor session  |login := Login new database:
PostgreSQLPlatform new;username: 'Frank';password:
'xxxxxx';connectString: 'localhost:5432_postgres'.accessor :=
DatabaseAccessor forLogin: login.accessor login.session :=
GlorpSession new.session system: (PortfolioDescriptor forPlatform:
login database).session accessor: accessor.accessor dropTables:
session system allTables.
session inTransactionDo: [session system allTables do: [:each |
accessor createTable: each ifError: [:error |Transcript show: error
messageText]]].
This code did create the PORTFOLIO table but caused the problem I
originally reported.
As you suggested, I used
                PortfolioDescriptor createTablesFor: login
to create the table and that worked.  I was able to add records with
no trouble.
In an attempt to determine what I was doing wrong I deleted the table
and went back to the code that I originally used to create the table.
The code that was failing now works!  I am not sure what was wrong but
at least I have something working.  I suspect (and I am only guessing)
that this was some type of caching related problem.
Thanks for you help,Frank
Reply all
Reply to author
Forward
0 new messages