hibernate to legacy DB with no ID columns

Discussion in 'Java' started by willirl, Jan 14, 2005.

  1. willirl

    willirl Guest

    I want to use hibernate to get into a legacy database in Oracle 9i
    however most of the tables do not have an "id" field, i.e. a row id
    field of some type.

    Is there a technique that will allow access?
     
    willirl, Jan 14, 2005
    #1
    1. Advertising

  2. willirl wrote:
    > I want to use hibernate to get into a legacy database in Oracle 9i
    > however most of the tables do not have an "id" field, i.e. a row id
    > field of some type.


    Well, what DO they have? You need some way to uniquely identify a row,
    otherwise you cannot use Hibernate (and just generally not do most
    things with the data that you normally use a database for). Hibernate
    *does* support composite IDs:
    http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-compositeid
    http://www.hibernate.org/hib_docs/reference/en/html/components.html#components-compositeid
     
    Michael Borgwardt, Jan 14, 2005
    #2
    1. Advertising

  3. willirl

    willirl Guest

    It looks like I should use the "assigned" generator. I think that's
    going to work.

    Thanks
     
    willirl, Jan 14, 2005
    #3
  4. willirl wrote:

    > It looks like I should use the "assigned" generator. I think that's
    > going to work.


    I don't think that's a solution - it still means there must be an ID column in the
    database, and that you application bears the responsibility of creating IDs for
    new rows.
     
    Michael Borgwardt, Jan 14, 2005
    #4
  5. willirl

    willirl Guest

    Doesn't it mean the the ID column can be the existing primary key for
    the row? And that it will use the primary key value assigned by me in
    the application when creating rows? That's the functionality I need.
     
    willirl, Jan 14, 2005
    #5
  6. willirl

    Guest

    Hibernate supports custom types which are intended to be used in
    situations
    like this one.

    Incidentally, you might try using middlegen - to generate the tables
    tables.
    middlegen will look at the unique columns and primary keys from the
    table's underlying DDL.
     
    , Jan 15, 2005
    #6
  7. willirl wrote:
    > Doesn't it mean the the ID column can be the existing primary key for
    > the row?


    In your first posting, you said that there was no id field - a primary
    key is exactly that, an ID field.

    > And that it will use the primary key value assigned by me in
    > the application when creating rows? That's the functionality I need.


    If the table has a primary key, that's how you can do it, but putting
    this functionality into the application is not a good idea in most
    cases. The generator mechanism of Hibernate also gives you the full
    flexibility but reduces the probability of errors.
     
    Michael Borgwardt, Jan 15, 2005
    #7
  8. willirl

    willirl Guest

    Michael, I'm not sure what Hibernate means by "id" but in my
    experience, an "id" field usually means a primary key that contains a
    unique identifier not related to the purpose of the table. E.g. a
    sequential number assigned to the row when the row is created.

    A primary key on the other hand _can_ be related to the table contents
    for example an employee number or even an employee name.
    Just nit-picking.
     
    willirl, Jan 17, 2005
    #8
  9. willirl wrote:

    > Michael, I'm not sure what Hibernate means by "id" but in my
    > experience, an "id" field usually means a primary key that contains a
    > unique identifier not related to the purpose of the table. E.g. a
    > sequential number assigned to the row when the row is created.
    >
    > A primary key on the other hand _can_ be related to the table contents
    > for example an employee number or even an employee name.
    > Just nit-picking.


    Ah, now I see what you mean.

    Well, the only requirement that Hibernate has for an "id field" is
    that it must uniquely identify the row - whether it also has some other
    meaning is not technically relevant.

    And of course if in your case the id/primary key is derived from some
    external source then using the "assigned" generator might be the only
    solution (on the other hand, you might also be able to use a custom
    generator class).
     
    Michael Borgwardt, Jan 19, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilias Lazaridis
    Replies:
    0
    Views:
    1,758
    Ilias Lazaridis
    Dec 27, 2004
  2. Replies:
    0
    Views:
    3,772
  3. ducnbyu
    Replies:
    2
    Views:
    6,201
    ducnbyu
    Sep 8, 2006
  4. jstorta
    Replies:
    1
    Views:
    11,833
  5. Eleanna Skouta
    Replies:
    2
    Views:
    8,489
    Arne Vajhøj
    Dec 9, 2008
Loading...

Share This Page