Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×
User Journal

Journal FortKnox's Journal: Java Users: Hibernate - A -must- see 10

Everything I've always wanted out of JDBC has been done with the open source project, hibernate. What is it? Simply an object relation mapper. Basically, you feed it an object (and the object has an xml that maps the object to a table and stuff[1]) and it will map it to a database and do all the jdbc to get the info and update/insert the data. Other nice things include one-to-many, many-to-many, and many-to-one mappings. You don't have to worry about foreign keys or anything (except in the xml mapping files) because it will automatically get your object instead of just the foreign key (even lazy loading is available).

It -really- makes JDBC simple in java. You just make normal java objects, and feed it into hibernate to do your persisting. It all happens in real time (using reflexion and other fancy things) so it isn't a code generator, but an api. I really suggest taking a look at the project. Really does some amazing things.

[1] - of course, if you are into the 'XDoclet' scene, you can have xdoclet write all the xml for you with its javadoc hibernate tags. And ant has hibernate tasks, including creating the tables and stuff...
This discussion has been archived. No new comments can be posted.

Java Users: Hibernate - A -must- see

Comments Filter:
  • We implemented a system like this in Perl, and it ended up working great unless we were doing mass object searching/sorting. Then it started sucking, and I mean hard.

    Do you know how it handles that aspect of things?
    • Yeah, it has its own version of SQL (so it keeps the 'object' paradigm rolling) that does the finds and such. Very effective and quick.
      • One solution we were thinking of is using BerkeleyDB to manage the object keying, and handle the serialization of objects from a more 'standalone' DB.

        Do you know what version of SQL it's using?
  • Where does this fit in relation to, say, container managed persistence in EJBs, or Java Data Objects (JDO) via something like Castor? If the answer is "it runs without needing a J2EE container", so does Castor.
    • never used castor, but I know it uses session beans for transactions if you want (that's what we are doing), and I've heard of projects that use entity beans before. But I'm no expert so you'd have to look at the doc, or ask questions.
  • Gotta love dropping in a new class and letting it rip. I currently have a project where I'm reflecting in an object (that must extend a certain class) and I want it to process a DOM document but I don't care how many methods it wants to run. So what did I do? Just look for all methods ending in Processing and running them all in alphabetical order. So I can write one that only has one method or a class that has 100. Any errors I handle with a plain set of exception handlers and *blamo* done.

    It's great
  • Have you seen OQL [exolab.org]? Looks like a similar idea.
  • For a while, they had a contest that whoever could prove that JDBC was faster than Hibernate would win. I don't believe that anyone ever collected.
  • Sounds a lot like Torque [apache.org] to me ... there are a bunch of object-relational mappers floating around. I've used Torque in several projects and found the same glee in time saving you voice above.

    Technology is cool.
  • ... to think my first attempt to do this sort of thing in college was to serialize objects using xml and put them into a mysql database. Technology IS cool :).

(1) Never draw what you can copy. (2) Never copy what you can trace. (3) Never trace what you can cut out and paste down.