This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes ORM as compared to JDBC 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 » Object Relational Mapping
Bookmark "ORM as compared to JDBC" Watch "ORM as compared to JDBC" New topic

ORM as compared to JDBC

satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
I am relatively new to ORM and am trying out JPA.

Trying to work on Many to Many and am confused.
I agree I dont as yet understand the details but after trying out the various mappings - my initial take is ..........
( Used to working on JDBC )

1 >
Using configurable XML / annotations is supposed to make persisting data to DB easy

Working with the relations I feel JDBC works well
I do need to write plumbing code - but its out in a jiffy

2 >
JPA in EJB3 consists of using any suitable provider
( Hibernate / Toplink etc )
Does JPA take care of distributed Tx or is that something that is provided by the EJB container ?

I know these are basic questions but wanted to vent my immature thoughts .

Thanks ,
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Originally posted by satish bodas:

Using configurable XML / annotations is supposed to make persisting data to DB easy

Hmmmmm. Is that what it's for? My Powerbuilder/Sybase developers would disagree. They'd rather just write SQL and plug it into Powerbuilder. Now they need to learn Java, and objects, and all that other stuff. Does it make persisting data easy? Maybe, if you're a Java developer.

I'd say that it allows Java developers who understand objects to approach their database in a more object-oriented way - a way that is much more natural for them. Furthermore, there is a great buffer between the database code and the Java code, so that changes in the data layer only require a small change in the mappings, not changes in the SQL that was embedded in the code.

Here's a thread you might find interesting. It's all about why we need a framework like JPA or Hibernate or EJB3 or whatever...

JavaRanch Thread on Why Do We Need a Framework Like Hibernate or JPA

As far as distributed transactions go, you can allow the EJB container to manage the transactions. As such, so long as you are using XA drivers that can participate in two-phase commit semantics, the container will take care of the distributed transactions.

These are good questions. I wouldn't characterize them as "immature thoughts ."

Kindest regards,

-Cameron McKenzie
satish bodas
Ranch Hand

Joined: Jun 19, 2008
Posts: 116
Thanks Cameron - I did go through the link .

Still working on the mapping examples and thanks for all the examples you have posted .

I still have a couple of questions ::

1 >
Looks like JPA does not support One to Many Unidirection Mapping .

Let me explain ::

From the DB model ::
Have a Master table and a child table
Foreign key resides in child table

There will be multiple children belonging to the same parent .

From the OO model ::
Parent class and Child class
Parent class contains a "Set" attribute which will contain the "Child" Objects

This is unidirection ( from Parent >> Child )

Now I want to ensure that when I save the parent the child gets saved too

From one of the earlier posts ::
( )
It looks like to make this possible there are two options ::

a >Compose the child with parent and then save the child

b >Make it a bidirectional mapping :: i.e make the child aware of the parent by providing a parent attribute in child object .

Here are my questions / doubts ::

1 >To me option A is not intuitive / doesnt flow with the way I think !

To me ( I am used to working in JDBC ) ::
" I would compose the parent with children and pass the parent to whoever takes care of the persistence - who then does the necessary insert "

Am I incorrect in my thinking ?
To me the child to contain the Parent doesnt "flow"

2 >Option B seems unnecessary increased work if I want to drive the inserts using "Parent"

3 >Assuming I go ahead with unidirection mapping ( Child containing parent object - Many to One ) ::
I have a parent and three children :; " A , B , C "

If I use this technique - then I can only save one child at a time
Other wise I will have to make a call to persist each child

Is there a way ( using unidirection mapping from child to parent )
that I can take the collection of children and in only one call ensure all children get saved along with parent .

Thanks ,

[ June 25, 2008: Message edited by: satish bodas ]
[ June 25, 2008: Message edited by: satish bodas ]
I agree. Here's the link:
subject: ORM as compared to JDBC
It's not a secret anymore!