Cayenne
  1. Cayenne
  2. CAY-421

DbGenerator and generated column

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2 branch
    • Fix Version/s: Undefined future
    • Component/s: Core Library
    • Labels:
      None
    • Environment:
      PostgreSQL

      Description

      I am trying to generate the database from my model, but some things are missing.

      cayenne currently does create sequence for all tables.
      CREATE SEQUENCE pk_person INCREMENT 20 START 200;

      for tables with db-generated primary key cayenne should do something like:
      create sequence pk_person;
      alter table person alter person_id set default nextval('pk_person');

        Activity

        Hide
        Andrus Adamchik added a comment -

        Tore, were you able to actually use this mechanism? And if so, what version of PostgreSQL and JDBC driver? I am asking cause the last time I tried (PG 8.0), the driver did not support JDBC3 mechanism for returning the generated PK back from insert statement to the Java layer. So setting up autoincrement was a moot point.

        In other words, is there a version of PG JDBC driver that has a working implementation of "java.sql.Statement.getGeneratedKeys()"?

        Show
        Andrus Adamchik added a comment - Tore, were you able to actually use this mechanism? And if so, what version of PostgreSQL and JDBC driver? I am asking cause the last time I tried (PG 8.0), the driver did not support JDBC3 mechanism for returning the generated PK back from insert statement to the Java layer. So setting up autoincrement was a moot point. In other words, is there a version of PG JDBC driver that has a working implementation of "java.sql.Statement.getGeneratedKeys()"?
        Hide
        Tore Halset added a comment -

        Hmm, good point. I have not tried. My application has some old plain jdbc code and some new cayenne code. All the generated columns are for tables that I have not done cayenne-inserts into.

        Perhaps this issue could be solved for psql and other bases now or in the future? It would be realy nice to be able to create the complete db schema from the cayenne model.

        Show
        Tore Halset added a comment - Hmm, good point. I have not tried. My application has some old plain jdbc code and some new cayenne code. All the generated columns are for tables that I have not done cayenne-inserts into. Perhaps this issue could be solved for psql and other bases now or in the future? It would be realy nice to be able to create the complete db schema from the cayenne model.
        Hide
        Andrus Adamchik added a comment -

        Hmm... I guess if we go with your solution, we'll still be able to provide an id value from Cayenne, ignoring th default. One thing we will loose is the PK cache. I am undecided on that, but I guess if you send a patch that works, I'll apply it.

        Show
        Andrus Adamchik added a comment - Hmm... I guess if we go with your solution, we'll still be able to provide an id value from Cayenne, ignoring th default. One thing we will loose is the PK cache. I am undecided on that, but I guess if you send a patch that works, I'll apply it.

          People

          • Assignee:
            Andrus Adamchik
            Reporter:
            Tore Halset
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development