This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using JDO with an existing DB schema" Watch "Using JDO with an existing DB schema" New topic
Author

Using JDO with an existing DB schema

Edwin Keeton
Greenhorn

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
Author
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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
edk,
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]
 
Consider Paul's rocket mass heater.
 
subject: Using JDO with an existing DB schema
 
Similar Threads
JDO vs. TopLink
Does the book cover the Object Oriented design?
The price of JDO
How to add more fields
XML TO XML Schema