aspose file tools*
The moose likes Object Relational Mapping and the fly likes all this O/R stuff...my questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "all this O/R stuff...my questions" Watch "all this O/R stuff...my questions" New topic
Author

all this O/R stuff...my questions

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I'm coming from the .NET world where the closest thing there is to O/R mapping is a big fat XML-based DataSet...which is unique in and of itself...but not quite as cool as what I've been reading about real O/R mapping technologies for Java.

First off, the vast array of choices is staggering and I'm completely unsure where to go from here. I have been using JDBC and "mapping" my own objects manually but we all know how un-maintainable that is.

Anyhow, here are my questions and assumptions, please answer/correct me where necessary? I'm not looking for a flame-war and a bunch of sales pitches based on everyone's favorite technologies. What I really need is a seriously objective look at what I'm asking, please!

1. Hibernate looks cool, can it completely abstract anything I could normally do w/ the SQL languages itself?

2. Can hibernate handle table-joins? It's rather difficult to conceive this, how would it be done if it *is* possible? Can you point me to a *SIMPLE* working code example?

3. How efficient is Hibernate vs. using, say, stored procedures and a DAO/JDBC framework? I know many programmers answer questions like this emotionally and entirely based on preference, damn the consequences. Again, objectivity please. I'm actually quite skilled with RDBMS (sql server, firebird, others...) and am a fan of stored procedures, used apprpriately and if there is a benefit to using them.

4. Do Hibernate and JDO overlap entirely or are there differences? Which is better? Ahem, by better I mean, which is the most proven and highly-used, highly-acclaimed of the two? Which is the most *simple* to work with?

6. Is there a way to auto-generate the descriptor files for my objects based on my database schema w/ either JDO or Hibernate? Can this be done within NetBeans? (Open Source or Freeware only!)

7. Does Hibernate/JDO integrate with NetBeans at all? (OSS or Freeware only!)

8. Doesn't having to update descriptor xml files and business objects *sort of* cancel out many of the benefits of O/R mapping?

9. Will EJB 3.0 blow the competition out of the water? I have read only small bits about it but it looks promising. I haven't bothered to learn much about EJB in its current state as I am advised not to around every turn!

10. Does Spring overlap with JDO and Hibernate? Spring seems like a jack-of-all-trades and I'm unsure how it would be useful to me, exactly.

I know I may be asking some fairly simple questions but believe me, I've been researching the topic for a few weeks now and am ready to being using one of these technologies in future projects, some small business open source apps I'd like to release next year, if possible.

If anyone can show me some SIMPLE code examples of Hibernate performing some of the common tasks you would normally use SQL for, I'd REALLY appreciate it. I found their documentation to be rather complicated, at first glance, and haven't had much luck finding straight-up, simple code to demonstrate.

I don't want "real-world" code from applications, I know how to write applications, I just need to know the basics to get started. Wimpy, useless code snippets are most appreciated and welcome!

Thanks all, VERY much!

-v
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

1. Yes, up to a point. HQL is fairly rich, but the Hibernate developers have taken the decision (probably just out of pragmatism) not to support every conceivable vendor specific dillution of the SQL standard, probably for pragmatic reasons. Of course Hibernate also support the calling of "native" SQL.
2. Yes. If by "table joins" I assume you mean one Object to two tables, Hibernate3 offers this (Caveat: Hibernate3 is still beta, but close to getting a release I understand). If you mean mapping associations between tables, Hibernate has a variety of way of doing this - I'd direct you to the docs to see this, since its not really a small topic.
3. Doing DB work in Stored Procedures tends to imply business logic in the database, and certainly implies a one platform solution. To this end it has negative implications beyond performance. However, the few times I have had to work on applciaitons where performance was paramount, Stored Procedures are really the only option. But those were special cases. I can say that the performance of Hibernate is good enough for the applications I've used it on.
4. No. Which is bettr? Its up to your preference really. I'd guess Hibernmate is more widely used, but that just a stab in the dark.
6. (What happened to 5 BTW?)Yes. Hibernate has a set of tools to do this.
7. No idea. There is an Eclipse plugin though.
8. No. Think of descriptor files as a necessarly evil to ghet round a bigger problem. IMHO they are not perfect, but they are the best solution so far t othis problem. Its only really an issue when using an ER model which is still not complete. I'm currently using Hibernate with a legacy applciation, so the model is fixed. Give or take a few minor tweaks, we hardly ever touch the mapping files after generating them.
9. Hard to say. It is supposed to be very simmilar to Hibernate's design, but then nothing has yet been seen so who knows. By the time it comes out, and is incorporated into then major App Servers, Hiberate will be pretty well established I'd imagine.
10. No Spring is a different technology all together.

I'd recommend you read "Hibernate In Action", the Hibernate team's own pay-for docs. This gives a pretty full overview, and includes some sample code.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Thomas Whitmore
Ranch Hand

Joined: Aug 05, 2004
Posts: 33
Hi Vinnie,

Congratulations and you're probably having a fair bit of fun coming over. Spring is great fun if you're building web apps; the first and best point of it is, a convenient and maintainable way to hook up and configure all the different parts of your app.

Business services, http request controllers, db access, mail senders, product catalogs, app data... all the config can be done bean-style and easily maintained... all the inter-object references can be set by Spring...

Thus eliminating the need for setup constructors, passing refs from here to there, push- and pull- updating, order-of-init problems, a whole couple of categories of code whose only logical function was to be a place bugs could exist, gone in one fell swoop.

First off, the vast array of choices is staggering and I'm completely unsure where to go from here. I have been using JDBC and "mapping" my own objects manually but we all know how un-maintainable that is.

Well, we all know that it's a fair bit more maintainable than scattering JDBC code everywhere. But a proper O/R engine will give you field mapping performance *and* enable you to run different access patterns/ queries etc across these, to fetch your app data.

Anyhow, here are my questions and assumptions, please answer/correct me where necessary? I'm not looking for a flame-war and a bunch of sales pitches based on everyone's favorite technologies. What I really need is a seriously objective look at what I'm asking, please!

JDO is cool, Hibernate is cool, which one you might use depends on what level of project you're doing and whether you want to go standard or not.

Personally I like proper support for JOINs and UNIONs -- and I've been suprised to find the number of different impls which will map a union but execute it is as repeated non-unioned queries. ?

Proper support for unions, and certain column/ data types, needs control down to individual column specs. Most data of course is happy with default, but I like tools which can actually deal properly with the database structures that are out there.

How efficient is Hibernate vs. using, say, stored procedures and a DAO/JDBC framework? I know many programmers answer questions like this emotionally and entirely based on preference, damn the consequences. Again, objectivity please. I'm actually quite skilled with RDBMS (sql server, firebird, others...) and am a fan of stored procedures, used apprpriately and if there is a benefit to using them.

One of the advantages of JDO is that it uses compiled data access and keeps 'pure' object identities. HB uses reflection and proxies quite a lot and these impose some amount of overhead. Probably ok for smaller apps though.

Do Hibernate and JDO overlap entirely or are there differences? Which is better? Ahem, by better I mean, which is the most proven and highly-used, highly-acclaimed of the two? Which is the most *simple* to work with?

JDO is a Java standard and gives you some degree of pluggability between vendors. New JDO2 query technology can also bring some advanced performance capabilities. HB is obviously free and has a loyal fan base.

6. Is there a way to auto-generate the descriptor files for my objects based on my database schema w/ either JDO or Hibernate? Can this be done within NetBeans? (Open Source or Freeware only!)

Commercial impls have Reverse Engineering and UI tools with various degrees of sophistication. Freeware typically doesn't get to that standard.

As for IDEs, I mainly do Java and web coding, but damn if Eclipse ain't it. Perceptually about 3x faster and a whole lot slicker. IBM engineers nailed this one, hard.

You'll also want to check out Ant. At some stage you'll want to start building/ deploying libraries, apps or other production artifacts. After you've jarred or copied filesets manually a few times, you can setup Ant to do this for you. Not just the convenience, but it will do it reliably.

Ant tip: clean by moving files to a 'deleted' bin, rather than deleting directly. Your buildfile will likely have errors until you've tested it, and I've had deletes go off in my project root folders... :-( :-( :-(

Doesn't having to update descriptor xml files and business objects *sort of* cancel out many of the benefits of O/R mapping?

Well, except I can template up a getter/ setter class, add it as JDO, Forward Engineer it to a table, clean up a few fields/ mappings and add a row to the key allocator table -- in about 8 minutes.

Versus 2 or more hours.

Will EJB 3.0 blow the competition out of the water? I have read only small bits about it but it looks promising. I haven't bothered to learn much about EJB in its current state as I am advised not to around every turn!

Well, forgive my cynicism but it would *have* to look promising at this point. But the success stories I'm hearing these days are multi-headed Tomcat with JDO or HB for storage.

EJB3 of course is being hyped and that's not just J2EE but a 'new' persistence spec, the big box vendors were probably starting to feel left behind, this persistence spec will also be usable outside J2EE so that's what most of the hype is about.

Does Spring overlap with JDO and Hibernate? Spring seems like a jack-of-all-trades and I'm unsure how it would be useful to me, exactly.

You won't even have to code constructors since Java defaults a no-arg one if no others are specd. Nor init code. All your init becomes XML and you can see and edit it in the one place.

I know I may be asking some fairly simple questions but believe me, I've been researching the topic for a few weeks now and am ready to being using one of these technologies in future projects, some small business open source apps I'd like to release next year, if possible.

Interesting. Web interface or client/ server? Half of Spring's usefulness is the Web MVC stuff. Solving the config- and init-code problem is a pretty good bonus for any app, though. I think Spring can be be used in many parts, and would entirely be usable for this - but to be honest web is what I'm using it for.

If anyone can show me some SIMPLE code examples of Hibernate performing some of the common tasks you would normally use SQL for, I'd REALLY appreciate it. I found their documentation to be rather complicated, at first glance, and haven't had much luck finding straight-up, simple code to demonstrate.

:-)

Certain people have been prone to spitting the dummy at other apis, despite nothing being perfect and hb having some distinct technical tripups.

But what you might be seeing that could confuse you, are chained invocations -- these are quite a useful feature where methods that could have been declared to return void, actually return the object you called them on. This allows you to conveniently call several modifiers or methods in a chain.


Cheers,
Thomas Whitmore
www.powermapjdo.com
Pj Murray
Ranch Hand

Joined: Sep 24, 2004
Posts: 194
A good place to start looking at the data persistence in Java is the Core J2EE Design Patterns.


http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html

http://www.corej2eepatterns.com/Patterns2ndEd/DataAccessObject.htm


The most important issue is to get the architecture right. The choice of persistence strategy (JDO, Hibernate, JDBC DAOs, EJB CMP, etc) is of secondary importance and can change from project to project.


PJ Murray
CodeFutures Software - Java Code Generation
http://www.codefutures.com
[ December 09, 2004: Message edited by: PJ Murray ]

PJ Murray -
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: all this O/R stuff...my questions