Postgresql identity field

Posts   
 
    
hankddog
User
Posts: 52
Joined: 08-Apr-2005
# Posted on: 21-May-2018 20:51:05   

What is the best way to handle a Postgresql entity insert? We are using V5.3 LLBLGen Pro Runtime Framework, Adapter.

It doesn't pick up the next ID number from the hilo table.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2018 08:42:57   

Support for PostgreSQL 10.x and its identity fields is now supported in v5.4. Ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=24753

Otherwise, use sequences as usual.

David Elizondo | LLBLGen Support Team
hankddog
User
Posts: 52
Joined: 08-Apr-2005
# Posted on: 22-May-2018 17:56:03   

But how do I get it to work? I updated to LLBLGEn V4.5.1 and I get

'An exception was caught during the execution of an action query: 23502: null value in column "id" violates not-null constraint. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. '

When I try to insert a new record.

the ID field shows 0

Is there a setting I need to do? Do I need to add the hilo table associated with it?

DB currently uses PostgreSQL 9.6.

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 22-May-2018 23:12:39   

Are you using LLBLGen Pro v.5.3 or v.4.5.1?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 23-May-2018 09:18:38   

as 4.5.1 is likely the .net version (as 4.2 was the highest v4 version). You have to assign sequences to field mappings. The designer can help with that though. Do you use database first or model first? In the case of database first: you have sequences defined in the database?

Frans Bouma | Lead developer LLBLGen Pro
hankddog
User
Posts: 52
Joined: 08-Apr-2005
# Posted on: 06-Jun-2018 16:54:11   

Walaa wrote:

Are you using LLBLGen Pro v.5.3 or v.4.5.1?

v.4.5.1

hankddog
User
Posts: 52
Joined: 08-Apr-2005
# Posted on: 06-Jun-2018 16:54:50   

Otis wrote:

as 4.5.1 is likely the .net version (as 4.2 was the highest v4 version). You have to assign sequences to field mappings. The designer can help with that though. Do you use database first or model first? In the case of database first: you have sequences defined in the database?

Database first. In the database, there are _hilo tables associated with each main table.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 07-Jun-2018 10:44:06   

A hilo table is something that's used by e.g. nhibernate and ef. Our runtime supports sequences and Postgresql v10.x identity fields. So to get identity inserts, you have to create a sequence for the table (e.g. seq__tablename_), in the designer in project settings -> entity model -> Database First Development -> Sequence name matching pattern, make sure it matches the pattern used for your sequences in the DB, and make sure (it's true by default, but just to make sure) that the project setting 'Auto assign sequences to integer Pks' is checked (under Entity Model -> General)

Frans Bouma | Lead developer LLBLGen Pro
hankddog
User
Posts: 52
Joined: 08-Apr-2005
# Posted on: 12-Jun-2018 18:17:26   

Otis wrote:

A hilo table is something that's used by e.g. nhibernate and ef. Our runtime supports sequences and Postgresql v10.x identity fields. So to get identity inserts, you have to create a sequence for the table (e.g. seq__tablename_), in the designer in project settings -> entity model -> Database First Development -> Sequence name matching pattern, make sure it matches the pattern used for your sequences in the DB, and make sure (it's true by default, but just to make sure) that the project setting 'Auto assign sequences to integer Pks' is checked (under Entity Model -> General)

For example, we have a table called UserRole it has another table called UserRole_Hilo with a column called NextHi only. That column handles the next number in the sequence. In the settings I add {$TableName}_Hilo. Now what?

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 12-Jun-2018 19:51:09   

If you create the Sequence as defined here: https://www.postgresql.org/docs/9.5/static/sql-createsequence.html

Then, please follow Otis steps..

in the designer in project settings -> entity model -> Database First Development -> Sequence name matching pattern, make sure it matches the pattern used for your sequences in the DB, and make sure (it's true by default, but just to make sure) that the project setting 'Auto assign sequences to integer Pks' is checked (under Entity Model -> General)

This should automatically assign sequences to integer PKs.