aspose file tools*
The moose likes Java in General and the fly likes Java Objects -> Database Tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Objects -> Database Tables" Watch "Java Objects -> Database Tables" New topic
Author

Java Objects -> Database Tables

Danny Krinkle
Greenhorn

Joined: Mar 17, 2008
Posts: 18
Hi Everyone - hope your all well.

Ive been working on the classes for an asset/license tracking application. Keeping it quite simple, an asset object can have references to three license objects.

I fancied getting this information into a database so looked into JDBC etc. Ive got to the stage where I can connect to the DB, enter the asset details into a form and store a new asset record into a database.

What im looking for is advice on how to reflect the relationship the objects have in a database. For example, my licenses will have to be stored in a LICENSE table with a reference to the unique id of its related record in the ASSET table.

Should I have to add variables such as assetKey to the license class? Are there existing technologies I should be investigating to make my life easier?

I just cannot find any good examples of how to do this or where to start looking.

Cheers

Danny
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Hi Danny,

I'd really recommend you not to use plain JDBC statements for your mapping between Java and a relational database. You should try the Java persistence API (JPA) instead. With EJB 3.0 and JPA it's really easy to do the mapping just with simple annotations - and for enterprise or standalone applications as well.

Just have a look at these examples!

Marco
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
. . . and welcome to the Ranch, Danny
Danny Krinkle
Greenhorn

Joined: Mar 17, 2008
Posts: 18
Thanks - a nice warm welcome.

The examples definitely look like what Im after so i'll look into this in a bit more detail.

Cheers

Danny
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Actually, it's good to know how to use JDBC - it's the "assembly language" for standard Java database connectivity. However, for industrial-grade applications, an ORM technology such as JPA in invaluable.

1. ORM gets you out of the SQL business and lets you manipulate data in Java terms, so it's one less "language" to have to master.

2. Some benchmarks I've seen indicate that for non-trivial apps, you'll actually get better performance. You'll almost certainly get better reliability and maintainability.

It might not seem possible that the high-level approach is more efficient than low-level direct control, but the truth is that high-level architectures are able to dynamically balance things that would require labor-intensive rewrites if done manually. Also, low-level languages are efficient only at the micro level - they require so much work in bulk that no one can afford to truly optimize each and every item - I've seen this over and over when I did mainframe assembler for a living. A framework, on the other hand will cheerfully globally re-optimize things over and over forever without getting tired.


Customer surveys are for companies who didn't pay proper attention to begin with.
Danny Krinkle
Greenhorn

Joined: Mar 17, 2008
Posts: 18
Thanks Tim.

You raise a good point re learning JDBC. (Or any 'low level' part of the language)

I looked over quite a few posts in quite a few forums before posting my question and i see so many posts where people are trying to dive straight in without a real understanding of what they want to achieve or the technologies they need to use.

I think the examples Marco kindly pointed me to would have made much less sense had I not spent a bit of time with JDBC/SQL first of all.

Cheers

Danny
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

It wasn't my intention to advice you to completely ignore the underlying details of a persistence framework. Of course you're both right. It's my opinion, too, that you shouldn't blindly use a high-level framework without knowing at least the basics of the technology.

And in this case it's surely essential to know the basics of JDBC and relational databases in general. Anyway I can't imagine that it's really possible to effectively use a persistence framework and O/R mapper without knowing anything about databases and persistence...

Marco
Danny Krinkle
Greenhorn

Joined: Mar 17, 2008
Posts: 18
Hi Marco,

The examples you sent me were spot on and exactly what I needed, for that I am grateful.

I was just trying to highlight the point for anybody else who may stumble upon this post, that its important to make the effort in the low level concepts before attempting to move on.

Cheers

Danny
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3216
It wasn't my intention to advice you to completely ignore the underlying details of a persistence framework. Of course you're both right. It's my opinion, too, that you shouldn't blindly use a high-level framework without knowing at least the basics of the technology.

And in this case it's surely essential to know the basics of JDBC and relational databases in general. Anyway I can't imagine that it's really possible to effectively use a persistence framework and O/R mapper without knowing anything about databases and persistence...



Good point. Similarly it is worth learning JSP & Servlet fundamentals before diving into Struts, JSF etc.


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278


Good point. Similarly it is worth learning JSP & Servlet fundamentals before diving into Struts, JSF etc.


Exactly! I can't understand many people who think they can use even the most complex framework or technology without knowing anything about it and of course without reading at least a few lines of documentation.
Binod Suman
Greenhorn

Joined: May 07, 2008
Posts: 17
Insted of use JDBD, nowadays Hibernate is best option for database stuff. It provides a lot of benefits over simple JDBC like caching, session, work on object directly instead of column and much more.

Get more on Hibernate @ Hibernatehttp://www.hibernate.org/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Objects -> Database Tables
 
Similar Threads
Object responsibility with persistence
Record-level locking question
SQLException. Generel Error
Java Objects -> Database Tables
binding two JTables to each other