File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Using JDO with an existing DB schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Using JDO with an existing DB schema" Watch "Using JDO with an existing DB schema" New topic

Using JDO with an existing DB schema

Edwin Keeton

Joined: Jul 22, 2002
Posts: 18
Generally speaking, how difficult is it with JDO to map to an existing relational schema? How does performance compare to a freshly created schema mapped directly through JDO?
David Jordan
Ranch Hand

Joined: Jun 14, 2003
Posts: 66
JDO has two forms of identity: datastore and application. Application identity is similar to primary keys in a relational database and all the JDO relational implementations support this. With an existing relational schema, you are not likely to have inheritance represented in your tables, so you would typically not have inheritance in your classes. Your foreign keys in the relational schema are mapped to references in your object model. A collection in a class A implies that there are multiple objects associated with it from a class B. At the relational level, this is normally represented by the B table having a foreign key referencing a row in table A (assume a 1-1 between class A/table A, class B/table B). So you can indicate that the foreign key in A serves as the inverse for establishing the collection elements in the collection in B. It is very late and I am tired, so forgive me if I am not making sense. The short answer is that you usually can map existing relational schemas to an object model.
Conversely, if you have an existing object model, it is fairly straightforward to map this to a relational schema. You also have the choice of using either datastore or application identity. With datastore identity, the JDO implementation takes care of generating unique identifiers for you. Also when letting JDO generate the relational schema, it can generate the proper table structures to represent inheritance relationships.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch! We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks pardner. Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Using JDO with an existing DB schema
It's not a secret anymore!