Hibernate & JDO

I am fairly new to bout these two technologies. I made a research on Hibernate and JDO and what I could come up to is that bout do nearly the same thing. Now I still am not an expert on how to program with them (still waiting for my JDO book to come). However I do have a bunch of questions to ask.

Naturally the first question is why use one technology and not the other? From what I read Hibernate seems to be the most popular technology out of the two, and I understand that when using it with xDoclet it makes life much easier! But then again JDO does just the same thing!

Thanks for any answers :)

[630 byte] By [sim085a] at [2007-10-1 23:31:28]
# 1

> I am fairly new to bout these two technologies. I

> made a research on Hibernate and JDO and what I could

> come up to is that bout do nearly the same thing.

do the same thing - persist objects - but do it in different ways.

> Now I still am not an expert on how to program with

> h them (still waiting for my JDO book to come).

> However I do have a bunch of questions to ask.

>

> Naturally the first question is why use one

> technology and not the other? From what I read

> Hibernate seems to be the most popular technology out

> of the two, and I understand that when using it with

> xDoclet it makes life much easier! But then again JDO

> does just the same thing!

Your exhaustive research must have told you something about how the two are different:

(1) Hibernate doesn't modify source or byte code to persist a Java object; JDO implementations either require a special interface be implemented or do bytecode modifications at runtime.

(2) Hibernate is only for mapping relational databases and objects. JDO is more general - it can work with object databases and other technologies besides just relational databases.

Mostly it's a matter of comfort - use the one you know best and can afford.

%

duffymoa at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Hibernate is ubiquitous, JDO is an open standard. I use JDO. I plan to do a hibernate implementation as well for the heck of it.
_dnoyeBa at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Thanks for the replies :) (I must admit mine was not an exhaustive research, altough I read about were JDO source or byte code implimentations).

I usually like to go with what Sun has to offer and do not usually go with frameworks developed by open source communities. However Hibernate (like Struts I guess) are very popular out there and so I tought of giving it a go as well. However for now I will learn JDO, and then try Hibernate as well :)

Thanks

sim085a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

> I read about were JDO

> source or byte code implimentations).

Actually, byte code enhancement may turn out to be a better method than reflection for implementing persistence.

Sure enough, Hibernate uses CGLib, and the latest versions of CGLib (Code Generation Library) bring JDO-style byte enhancements (CGLib sits on top of ASM, a byte code manipulation lib).

Also, JDO is a specification, Hibernate is a product. If you decide to use JDO, the search is not over, as the next step would be to compare the different JDO implementations available...

karma-9a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 5

Here's something from the Hibernate 3.0 site:

"No build-time bytecode enhancement - there's no extra code generation or bytecode processing steps in your build procedure"

It sounds like Hibernate is using CGLib to generate wrappers and proxies dynamically, but they're not altering your class's bytecode. That might be a fine point, but it is different from what I understand JDO to be doing.

%

duffymoa at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 6

Yes Hibernate does notchange any code from your class. Baically I think it achieves this because it creates like meta data on that class (the xml files). Now I still do not know if JDO uses XML aswell (my believe is not) since I am still waiting for a book to start real on it (hopefully it will come soon), However if JDO changes the byte code of the class does it effect much on the performance of the whole application?

I also read that one of the person who developed Hibernate is now working on JDO2.0. Now I searched and found out that this version isn't relaeased yet! is this right?

sim085a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> That might be a fine

> point, but it is different from what I understand JDO

> to be doing.

It is a fine point, but a valid one.

The difference is between runtime bytecode enhancement (Hibernate's CGLib) and compile-time (as most JDO implementations I've seen do).

As for ObjectWeb's ASM bytecode framework (used by CGLib), it was designed primarily to be used dynamically, although it can also be used statically...

karma-9a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 8

> Yes Hibernate does notchange any code from your

> class.

Not at build time.

> However if JDO changes the byte code of the class

> does it effect much on the performance of the whole

> application?

Not really. And byte-code processing is also used in AOP frameworks.

>

> I also read that one of the person who developed

> Hibernate is now working on JDO2.0. Now I searched

> and found out that this version isn't relaeased yet!

> is this right?

That person would be Gavin King.

You should check jcp.org for any spec release.

karma-9a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 9

Thanks karma-9, I checked the website you mentioned, which I liked most since I have a whole list of all projects being developed by Sun (I think)

Thanks :) I will try to learn JDO for now! Hopefully when the 2.0 will come out, it will not be completly different from the one I learn ;)

Thanks to all again :)

sim085a at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...
# 10

JDO does bytecode enhancement. If you think of the classes enhanced not as <i>your</i> classes then I guess its not so bothersome that they are changed. I created these classes specifically for JDO to manage and they are basically DAOs I guess.

JDO also will replace your Collection classes with their custom colleciton classes, but it works out the same. Once you give over your DAO to JDO you are fine. If you try to use the same DAO in several different projects and implementations then you will have an issue I think. Its not transparent.

the jdo i use is jpox.org so you can get lots of questions answered there and there is a jdo website too, but i stick to jpox because its open, or I think it is. I need to read the jpox license. I am bugged that there is such a thing and its not simply the LGPL or something similar.

_dnoyeBa at 2007-7-15 14:14:16 > top of Java-index,Other Topics,Patterns & OO Design...