hibernate to legacy DB with no ID columns

W

willirl

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?
 
M

Michael Borgwardt

willirl said:
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
 
W

willirl

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

Thanks
 
M

Michael Borgwardt

willirl said:
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.
 
W

willirl

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.
 
G

gimme_this_gimme_that

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.
 
M

Michael Borgwardt

willirl said:
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.
 
W

willirl

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.
 
M

Michael Borgwardt

willirl said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top