Some Common Problems
There are two common problems that can cause a lot of frustration and wasted time: cached values and table creation. In a production system these will not be an issue. However when you are learning GLORP you will be making lots of little changes to see how things work. If you find that your changes are not reflected in the behavior of the system come back and read this section again.
Cached Values
The first problem is caused by cached values. When you create a new session, as done below, the descriptor is read and its data is cached. If you then make changes to the descriptor class, those changes will not be reflected in any open session. You need to start a new session for the changes in the descriptor class to take effect. So if you find yourself making changes to the descriptor class but those changes are not reflected in your code, use a new session.
session := GlorpSession new.
session system: (GlorpTutorialDescriptor forPlatform: login database).
session accessor: accessor.
Creating Tables
Once you have created a table you need to delete the table before creating it a second time. When learning GLORP you are likely to change the table structure a lot. If you tell GLORP to create the tables it will appear to do so. The proper SQL is sent to the database and no errors are raised. However the tables are not recreated. There is a very subtle way in which GLORP informs you that the tables were not created. If the tables were created. the GLORP log in the Transcript will include the time it took to create the tables. Here is what you will see in the Transcript if the tables are actually created:
Begin Transaction
CREATE TABLE PEOPLE (ID serial NOT NULL ,FIRST_NAME varchar(50) NULL ,LAST_NAME varchar(50) NULL , CONSTRAINT PEOPLE_PK PRIMARY KEY (id),
CONSTRAINT PEOPLE_UNIQ UNIQUE (id))
(1.116 s)
Commit Transaction
Note the (1.116s) after the SQL.
Now below is the GLORP log when the tables already exist so the CREATE TABLE has no effect. There is no creation time listed.
Begin Transaction
CREATE TABLE PEOPLE (ID serial NOT NULL ,FIRST_NAME varchar(50) NULL ,LAST_NAME varchar(50) NULL , CONSTRAINT PEOPLE_PK PRIMARY KEY (id),
CONSTRAINT PEOPLE_UNIQ UNIQUE (id))
Commit Transaction
While learning GLORP, changing table structure will be common. Here is Smalltalk code which will first drop the tables then create them. Do not put the ‘accessor dropTables: …’ code in the same transaction that creates the tables. If the tables do not exist, the dropTables: method will abort the transaction. The dropTables: method wraps itself in a Transaction so there is no need to explicitly put it in a Transaction.
session := GlorpSession new.
session system: (GlorpTutorialDescriptor forPlatform: login database).
session accessor: accessor.
accessor dropTables: session system allTables.
session inTransactionDo:
[
session system platform areSequencesExplicitlyCreated
ifTrue:
[session system allSequences do:
[:each |
accessor createSequence: each
ifError: [:error | Transcript show: error messageText]]].
session system allTables do:
[:each |
accessor createTable: each
ifError: [:error | Transcript show: error messageText]]]
Last modified date: 01/29/2015