newbie question on platform sequence

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

newbie question on platform sequence

Frank Lynch
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

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: newbie question on platform sequence

Alan Knight-2
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




[hidden email]
14 November, 2011 6:05 PM


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

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: newbie question on platform sequence

Frank Lynch
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

On Nov 15, 9:41 am, Alan Knight <[hidden email]> wrote:
>
> 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
>

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.