facebook

NOOB: spring/hibernate/postgres …generator ID’s

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #254162 Reply

    Dan
    Member

    Ok I’ve seen various posts indicating that myeclipse generates the .. id generator incorectly, and it seams the defacto solution is to simply change:

    <generator class=”sequence”>

    with

    <generator class=”sequence”>
    <param name=”sequence”>account_id_seq</param>
    </generator>

    I still get the now get the error:
    nested exception is org.postgresql.util.PSQLException: ERROR: relation “account_id_seq” does not exist

    now..I my tables in defined within a schema I’m guessing that may be part of the problem..but not sure..anyways here some more info below..
    any help will be greatly appreciated.

    some more info:
    xml snippit from the ‘account xml file’
    ———–
    <class name=”com.bn.dao.Account” table=”account” schema=”foobar”>
    <id name=”idaccount” type=”long”>
    <column name=”idaccount” />
    <generator class=”sequence”>
    <param name=”sequence”>account_id_seq</param>
    </generator>
    </id>

    SQL Generation script:
    ————-
    CREATE TABLE foobar.Account (
    idAccount BIGINT NOT NULL CONSTRAINT UQ_Account_idaccount UNIQUE
    , date_created TIMESTAMP NOT NULL
    , date_lastLogin TIMESTAMP
    , firstname VARCHAR(20) NOT NULL
    , lastname VARCHAR(20) NOT NULL
    , displayname VARCHAR(20) NOT NULL CONSTRAINT UQ_Account_DisplayName UNIQUE
    , password VARCHAR(32)
    , zip INT8
    , email VARCHAR(200) NOT NULL CONSTRAINT UQ_Account_email UNIQUE
    , idStatus INT4 NOT NULL
    , idsession VARCHAR(128)
    , PRIMARY KEY (idAccount)
    , CONSTRAINT FK_Account_1 FOREIGN KEY (idStatus)
    REFERENCES foobar.statuscode (idstatus)
    );

    #254176 Reply

    Haris Peco
    Member

    dshopkins ,

    You have to generate sequence account_id_seq

    Best ragards

    #254182 Reply

    Dan
    Member

    Sure Enough, that appears to work..

    ps. (doing this on mysql I never had to generate the sequence, is there a particular reason why hybernate/mysql would not require this step vs hybernate/postgres?)

    thanx

    #254184 Reply

    Haris Peco
    Member

    dshopkins,

    I don’t sure if mysql have sequence at all – you have used ‘auto increment’ feature or some other hibernate generator. This isn’t problem because you can use ‘auto increment’ easier
    Postgresql have auto increment feature , too – you define column with serial or bigserial (or check ‘auto increment’ in MyEclipse M1/M2 table wizard and postgresql will automatic increment values.In hibernate you have to choose identity generator for this feature in postgresql.
    Postgresql server make internal sequence for every ‘auto increment’ columns, because haven’t ordinal ‘auto increment’ like mysql, but for user it’s same
    This isn’t related with MyEclipse at all – MyEclipse use what database servers offer

    Best regards

    #254187 Reply

    Dan
    Member

    Excelent, I see now, I simply did not define table with the correct data type.

    So to double check:
    Your saying if I simply define the column of idAccount to be of type serial, or bigserial, that the value will auto-increment automagically. (I suspect postgres will just under the hood create the sequence and and differ to values in their).

    If i do this then what type of generate do I select when generating the hibernate objects? (native?)

    thank you again for your quick responses 🙂

    #254203 Reply

    Haris Peco
    Member

    I suspect postgres will just under the hood create the sequence and and differ to values in their).

    you can check postgres catalog – when you make table t with column c type serial postgres will create sequence t_c_seq or better, check manual

    If i do this then what type of generate do I select when generating the hibernate objects? (native?)

    I told you in previous message : identity

    best regards

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: NOOB: spring/hibernate/postgres …generator ID’s

You must be logged in to post in the forum log in