★ wanayoo — archive 1999 http://javaboutique.internet.com/Map_Java_Objects/Nouvelle recherche | Portail wanayoo
Attend Be an Exhibitor Be a Sponsor

Internet Trade Show List


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Find a Web HostFind a Web Host
Build Flash Online
Find a Consultant
Register Domains
MLM Training
Find Romance
Digital Camera Reviews
Promote Your Website
Business Search
Free Barter Account
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:



Reviews :

Mapping Java Objects to a Database with Castor-JDO:

by Keld H. Hansen

Preface

As a Java-programmer you'll probably find it easy to work with objects. To create an instance of a class one can simply use "new" and maybe a couple of setter-methods. To save your instances, so you can continue working with them tomorrow might be trickier. One solution would be to serialize your objects and store them in XML format in a flat file. If you've got many objects with complex relations then you'll soon find out that this is not the way to go. If you've got a database system and you know your SQL, then you have a solution that works. On the other hand: what if you could simply say "save my objects", and they'd be in your data base? That'd be nice, right?

If you continue reading I'll disrobe the tool that will enable the "save my objects" slight of hand. To save an instance of class "Media" to a database you'd have to code:

      db.begin();
      Media m = new Media(1,"DVD");
      db.create(m);
      db.commit();
      db.close();

Harry Potter would love this spell and the tool that can make this come true is Castor-JDO. 

JDO - the history

JDO spelled out means Java Data Objects, and Sun has an API and a specification (JSR12) with this name. This API addresses how to persist (store permanently) Java objects on a back-end, which could be a mainframe, a database or something else. Castor-JDO, which was released in December 1999, before Sun's API, has a more focused approach. Its purpose is to automate binding Java objects to a relational database. Since Castor and Sun use the same name, JDO, for their APIs, there have been some misunderstandings and discussions about who has the rights to the name, and what comprises "true JDO". The resources section of the article has some links where you can follow some of the arguments.

This article will focus only on Castor-JDO, which in my opinion is the simplest API to learn, and therefore a good way to be introduced to the object-relational mapping world. By the way: Castor-JDO has a twin brother, Castor-XML, which can serialize a Java bean object into XML, and back again. See the resources section for more on this useful feature. When I use "Castor" in this article I refer to Castor-JDO.   

So this is about how you automate the persistence of Java objects into a relational database. What we'd really like is to let someone else write the SQL and setup the JDBC API to manage the database, thereby allowing us to focus on handling the Java objects and the business logic.

If you're like me, you're excited about this possibility, then I think it's fair to stress the following. You will need to know about database tables, columns, foreign keys etc. in order to set up Castor properly. The more you know about the good, the bad and the ugly of database design and SQL coding the better you will be able to take benefit from what Castor offers. Don't be scared, in this article I'll go step-by-step through the basics of setting up your application for Castor, and when it's done and the train is on the rails, you'll be halfway to Hogwart's School of Wizardry before you know it!

Introduction
Installation of MySQL
Installation of Castor-JDO
Transient and Persistent Objects,The database configuration file,The mapping file
Handling one-to-many relations
Handling many-to-many relations
Reading from the database
The Source of Magic
Conclusion


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
Java Development Tools You Never Knew Existed
The world of software is ever-growing, and though we all like to stay on top of all the tools available to us, who has the time? Well Drew Falkman took the time to bring you his five favorite tools you didn't know existed.
... [more articles]

New Tutorial:
Mapping Java Objects to a Database with Castor-JDO
Looking to be more productive? Who isn't? Keld introduces us to Castor-JDO, a tool that will enthrall you with its simplicity. If you have a simple data model, and are fonder of Java coding than SQL coding, then Castor can help you to be more productive.
... [more Tutorials]

Year in Review:
The Best of 2002
The year 2002 saw 201 new applets posted to JavaBoutique. Check out the 2 most popular apps from each month of 2002!
... [popular applets]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo


WebDev News

Sun Spells P2P: JXTA

Now Complete, Grid Computing Spec is Proposed

Sendmail, Beware



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



Jftp v1.0 (Java Upload Applet)
Jftp provides you with the ease of uploading files over the internet via FTP from within your very own web enabled applications.
Download of the Week
bdLCD
bdLCD is a Java applet that looks like a realistic LCD panel using a typical 5x7 character set.

JB User Poll
How do you get the majority of your programming questions answered?
The JavaBoutique Top 15:
1. NavBar
2. ChompText
3. DJPopMenu
4. PingPong
5. Distorter
6. RushHour
7. 3DMaze
8. Encyclo
9. AnimLetters_anim
10. Viewer
11. BMMenu
12. AScroll2
13. Nibbly
14. BMI
15. PulseText
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Intel Kicks Off Big Wi-Fi Ad Push
The chipmaker plans to spend up to $300 million for the launch of its Centrino wireless Internet technology.

Cyber-warfare: Latest Weapon in Military Arsenal
The U.S. government is reportedly developing plans for making cyberspace the next battlefield, with cyber attacks the latest weapon in the military's arsenal. But how to keep an attack from washing back onto U.S. shores?

Why You Should Worry About State Spam Laws
Who manages your e-mail program -- you... or your lawyer?


Reports on security issues of ecommerce environments

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/