Discussions

News: The Scope of Hibernate 3

  1. The Scope of Hibernate 3 (49 messages)

    Gavin King has written about the future of Hibernate, as he discusses thoughts for Hibernate 3. In this entry he mentions enhanced mapping flexibility, representation independance, JSR 175 metadata support, stored procedure support, event driven design, declarative session management, and more.
    After more than a year of activity, development of the Hibernate2 branch has finally been wound up; Hibernate 2.1.3 will be one of the last releases and represents a rock-solid POJO persistence solution with essentially all the functionality needed by a typical Java application. Any future release of Hibernate 2.1 will contain only bugfixes. The branch that we have been calling 2.2, will actually be released as version 3.

    The Hibernate project has previously had quite circumscribed goals - we have limited ourselves to thinking about just the very next release, and just what our users are asking for right now. That approach has finally reached the end of its usefulness. Hibernate3 is conceived in hubris, with the goal of innovating beyond what our users are asking for, or have even thought of. Certainly we will be adding features that go well beyond the functionality of the best commercial ORM solutions such as TopLink. (Some of these features will be most interesting to people working with certain specialized kinds of problems.)
    Read Gavin in The Scope of Hibernate Three

    Threaded Messages (49)

  2. This is awesome...[ Go to top ]

    Hibernate is the bomb! If every open source toolset were done like this, java would be a blast.

    Hats off to Gavin on the Hibernate end user interface design. Just awesome... (and easy to use)
  3. More Mapping Flexibility[ Go to top ]

    In addition to the inheritance mapping that Gavin describes in the blog, I would like to put my vote in for instance-based mapping as well.

    I have encountered a number of enterprise environments with Real Big Databases, where the data is split into different tables based on a field value, such as customer ID or date. It is not elegant or even feasible to define an arbitrary subclass for each of these divisions (sometimes I will see monthly tables going back decades).

    I would like the ability to embed this sort of logic that identifies which table an object should be persisted to, based one the value of one of the object's primary keys.
  4. Some Databases Do That[ Go to top ]

    Hey, Corby.

    It sounds like you're asking for something that some databases might do for you. For example, this sounds a lot like Oracle's partitioning feature.

    Not that this wouldn't be useful in other environments, but if you use a database-embedded feature like this, it'll probably be a lot faster, and work transparently with other tools.

    Cheers,
    --Kevin
  5. Some Databases Do That[ Go to top ]

    Not that this wouldn't be useful in other environments, but if you use a database-embedded feature like this, it'll probably be a lot faster, and work transparently with other tools.
    Thanks, Kevin. In situations where I have that much control over the database environment, I agree this is a very easy problem to solve. When I am working with large enterprise legacy databases, I basically need to solve the problem by using a non-Hibernate persistence solution.
  6. We encounter a similar problem using Hibernate 1.2 for a smaller database.

    We needed to create a new record in a table B1 or B2 depending of the data contained in A1. A1 was logically linked "one-to-zero" and "one-to-one" to B1 and B2 depending of the data in A1. The only way to do this was to linked B1 and B2 to A1 by a artificial "one-to-many" relationship and to decided on the business side (or layer) which table B1 or B2 to add the new record.
  7. More Mapping Flexibility[ Go to top ]

     I have encountered a number of enterprise environments with Real Big Databases, where the data is split into different tables based on a field value, such as customer ID or date.
    I have used this workaround to split "big" tables too,
     but this is a very "evil" way, it even decreases performance for some queries ( unions ). I found it is better to create index and to filter results by indexed values ( helps for subqueries in most of cases ) , It is possible to optimize queries without split of "large" tables, query plan trace helps to tune query in most of cases (split makes tuning very hard).
  8. Already there[ Go to top ]

    In addition to the inheritance mapping that Gavin describes in the blog, I would like to put my vote in for instance-based mapping as well.I have encountered a number of enterprise environments with Real Big Databases, where the data is split into different tables based on a field value, such as customer ID or date. It is not elegant or even feasible to define an arbitrary subclass for each of these divisions (sometimes I will see monthly tables going back decades). I would like the ability to embed this sort of logic that identifies which table an object should be persisted to, based one the value of one of the object's primary keys.
    Actually, I didn't mention this, but it is already possible. Hibernate3 has a notion of "named" entities, where the O/R mapping is decoupled from the actual class and instead attached to a String-based name.
  9. Already there[ Go to top ]

    Hibernate3 has a notion of "named" entities, where the O/R mapping is decoupled from the actual class and instead attached to a String-based name.
    Perfect! Thanks for the heads-up!
  10. The Scope of Hibernate 3[ Go to top ]

    From the link:
    The Hibernate project has previously had quite circumscribed goals - we have limited ourselves to thinking about just the very next release, and just what our users are asking for right now. That approach has finally reached the end of its usefulness. Hibernate3 is concieved in hubris, with the goal of innovating beyond what our users are asking for, or have even thought of. Certainly we will be adding features that go well beyond the functionality of the best commercial ORM solutions such as TopLink. (Some of these features will be most interesting to people working with certain specialized kinds of problems.)
    I look forward to seeing what they come up with next.

    However, if I had to vote on this, I would vote not to do anything - just keep maintaining Hibernate 2, keep it bug-free and stable (as it already is ..) and if you are bored, then start a totally different project.

    The reason is that there's no demand for new features, so now they have approaching the problem bottom-up instead of top-down, with the result that version 3 will not be as good as version 2.

    Just my 2 cents.
  11. Great news![ Go to top ]

    Gavin, you and your developers are doing an outstanding service to the Java community. I've been using Hibernate successfully for 6 months and love it, and I'm impressed that JBoss is investing in it as well. Thanks again!
    Scott
  12. Hibernate versus Torque[ Go to top ]

    We are comparing Torque versus Hibernate.

    Does Hibernate have the feature where one can just point it at a database schema and voila, out come a bunch of classes ready to use without the need to muck with a mapping XML?

    Thanks..
  13. Hibernate versus Torque[ Go to top ]

    http://www.hibernate.org/Documentation/HibernateRoundtripTools
  14. Torque vs Hibernate[ Go to top ]

    Thanks for the links, but how mature are those tools?

    The Torque tools are incredibly mature. I literally only need to change the database name in the config file, 2-3 mouse clicks later (to run ant targets) and I have a full tree of source code ready to use WITHOUT having to do anything else -- zero editing anywhere. That's NICE!

    Also, I spent some time going over Torque and found the generated code really nice and the fact that I can modify the velocity templates to change the generated code is a great bonus.

    I would greatly appreciate a discussion from people who have substantial experience with Hibernate and/or Torque on Hibernate and its and its tools' code-gen features.

    Thanks...
  15. go to forum.hibernate.org[ Go to top ]

    just go to the hibernate tools forum at forum.hibernate.org (or maybe even try to read the docs about our roundtrip tools)

    And yes hibernate has very mature "db2hbm" and hbm2java codegenerators.

    hbm2java also has velocity support - but since velocity is a weak language in the sense of nice and powerfull code generation (and i mean it ;) then i propose to look into using the "native" code generation .... but it's your call - if you want velocity you can use the velocity way too....(you'll just loose some of the really nice possibilities ;)
  16. Hibernate Tools[ Go to top ]

    Well, I have gone over the hibernate docs multiple times, incl. the tool section and most tools were marked more or less as not fully mature...

    http://www.hibernate.org/Documentation/HibernateRoundtripTools

    Check it yourself...the tools are either depcrecated or not mature.

    So, has anyone managed to, from scratch, generate a useable JAVA OM layer from a db schema using hibernate tools WITHOUT having to modify any mapping file our source file?

    And with a DB schema, I am talking about a real-world schema not a toy petstore schema.
  17. Hibernate Tools[ Go to top ]

    Come on !
    Did you try those tools for real ?
    Have a look at user experiences on http://forum.hibernate.org/
    They are for sure widely use in real projects, just check it out.
  18. Hibernate Tools[ Go to top ]

    Yes, I did try out the latest middlen stuff. Middlegen-Hibernate-R4 and the latest Hibernate 2.1.2 or something like that.

    Middlegen generated a number of .hbm.xml files.
    Hibernate h2bmblablaba generated .java files...

    BUT the generated files are simple java beans...where are all the DB persistence code? In Torque, they are in the base and peer classes and I can modify the bean classes without having to worry that the next codegen pass will overwrite my changes...

    Also, why the are my Java class names not capitalized according to the schema table names? Middlegen does pick up the table names with the proper capitalization..ie..exact..., but the java code does not turn out that way...

    Like, my table is called XYZUser and the Java class name is Xyxuser, what the hell? Who asked for a renaming? :-)

    Baah...this tool is bloody too complicated compared to Torque.
  19. Hibernate[ Go to top ]

    Correction: about the java code does not have DB code...well, I think I am wrong here since, if I understood it right, that is done inside Hibernate via reflection???

    But what about the bloody renaming of my table and column names?
  20. Hibernate[ Go to top ]

    This is the wrong place to ask, use the Hibernate forum. And give it a chance, many people use it with great success. Keep in mind that the Hibernate stuff is much more flexible than Torque, this comes at a price. If Torque works for you, why change?
  21. Torque vs hibernate[ Go to top ]

    BUT the generated files are simple java beans...where are all the DB persistence code? In Torque, they are in the base and peer classes and I can modify the bean classes without having to worry that the next codegen pass will overwrite my changes...

    All the persistence code is transparent - unlike torque which generates classes with built-in persistence code for every single class and table(the brute-force way), hibernate generates no extra code - it uses runtime reflection or CGLib to populate or persist your beans-that's it. If you don't like the names, you can write your own beans, and map them to the tables, which you have to do with Torque anyway.

    You can also look at the naming strategy feature to modify the naming convention.
  22. Torque vs hibernate[ Go to top ]

    I've used both Torque and Hibernate extensively. Although Torque was easier to get started, by now I much prefer Hibernate.

    Torque forces you to inherit a set of base classes, which severely limits your flexibility. With Hibernate you can use any classes. Persistence is done via a "Session" object. If you're familiar with the Enterprise Architecture Patterns (Fowler) this is a Data Mapper approach rather than an Active Record approach.

    Another reason I like Hibernate is that it is more flexible in mapping relations. My Torque datastructures are forced to have an exact 1 class to 1 table mapping. Hibernate gives you a bit more flexibility, particularly with many-to-many relations. (With Torque you have to make an extra table, while Hibernate handles this for you automagically).

    A positive of Torque is the clear way of generating the Java files based on the XML descriptors. (Using Velocity). With Hibernate the variety of options can be confusing when starting out. I've had good experiences with the hbm2java tool to go from the XML descriptor to java. A colleague of mine goes the other way, keeping his source as Java and uses XDoclet to create the XML file (based on metadata). This seems to be a bit more common.

    I'm looking forward to a release of the new hbm2java, which(like Torque) apparently uses Velocity to create the Java files. (promising more flexibility in the content).
  23. Hibernate Tools[ Go to top ]

    Almost all the users apply one or more of the tools in there respective development approaches. Middlegen is mature and is being used extensively. Some users customise the velocity scripts, others may choose to plugin there own JavaTypeMapper. We do provide many options. As Christian noted, this flexibility does mean there are more decisions. The advantage is that you are in-control and not locked into a rigid solution.
  24. Hibernate Tools[ Go to top ]

    So, has anyone managed to, from scratch, generate a useable JAVA OM layer from a db schema using hibernate tools WITHOUT having to modify any mapping file our source file?
    Why would you want to do that?

    Shouldn't you design your database with x, y and z in mind.
    And design you Object model with a, b and c in mind.
    Then get a tool like Hibernate to do the "Object" to "Relational" mapping?

    I think you are just being lazy, and sacrificing quality design in both the database and object model.
  25. http://www.eclipseplugincentral.com/modules.php?op=modload&name=Web_Links&file=index&req=viewlink&cid=115
  26. Good Tool[ Go to top ]

    May I ask you support an ANT task to reduce dependency on a particular IDE?
  27. JDO?[ Go to top ]

    I understand that Gavin is now part of the Java Data Objects expert group. Does he have any plans to incorporate JDO into Hibernate in version 3 or beyond?
  28. The Scope of Hibernate 3[ Go to top ]

    I'd first like to thank gavin and the rest of the hibernate team for a wonderfull product.

    Will Hibernate3 be backwards-compatible with Hibernate2 or will we need some code changes?
  29. back-compatibility[ Go to top ]

    I'd first like to thank gavin and the rest of the hibernate team for a wonderfull product.Will Hibernate3 be backwards-compatible with Hibernate2 or will we need some code changes?
    It will be "almost" back-compatible. Meaning that we reserve the right to change some small things (only when truly worthwhile) but we guarantee that it will be /very/ easy to migrate (the migration path will be much easier than 1.2 -> 2.0, which most people found to be very easy anyway).
  30. Sure to cause a stire but...[ Go to top ]

    I'm a huge fan and proponent of Hibernate but if there was one thing I could change it would be the wretched JavaBean model that is forced upon my lovingly conceived classes.
  31. Sure to cause a stire but...[ Go to top ]

    Not a stir at all. Look at the proposed features, one of them is "Representation Independence". So just model your persistent classes as weird as you want, and there will be a way to write something-that-plugs-into-hibernate to persist your classes.
  32. Sure to cause a stire but...[ Go to top ]

    You can configure Hibernate to use an object's member variable instead of a getter/setter, by setting the access attribute for the property element to "field" (the default is "property") in your mapping file. I'm not sure what version this behaviour was introduced in, but it's in the latest documentation on the site - http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-7
  33. Is this.....[ Go to top ]

    April Fool?
  34. The Scope of Hibernate 3[ Go to top ]

    Will there be a better support for mass updates? Query and Criteria deletes would also be welcome:

    Query query = session.createQuery(
      "from Some object where object.age in ( :ages )");
    query.setParameterList("ages", ages, Hibernate.INTEGER);
    query.delete();
  35. Mass update/delete[ Go to top ]

    Will there be a better support for mass updates?
    Probably at some stage, but we are not committed to this yet. Certainly not in Hibernate3 alpha. Perhaps not even in Hibernate 3.0.
    Query and Criteria deletes would also be welcome
    Yes, this is planned for Hibernate 3.0. I almost mentioned it in the blog. Its unlikely to be ready for Hibernate3 alpha, however.
  36. Stored procedures parsing[ Go to top ]

    If Hibernate will have possibility to parse stored procedures, and redo it to synchronize inmemory cache and DB, that would be incredable cool.

    Tools to convert stored procs to java classes also needed.
    As well as supporting SQL dialects.
  37. Stored procedures parsing[ Go to top ]

    Also, it beat .NET feature, that allow remotly debuging stored procs in MS SQL Server
  38. Compare Cached HQL to new one[ Go to top ]

    Example:
    1. You execute some complex HQL that return Users with parent Groups prefetched.
    Think, you want to do something with users, who in groups.
    The HQL have joins and so on. Hibernate cache it.

    2. Later, due calling Java functions with business process logic, you call Hibernate to return parent groups by particular user.

    Hibernate should understand, that 2nd query is more restrictive that 1st and not call DB and retrive data from existing case. This need at least tool, that can compare two HQL queries to understand which one is value subset to another.
  39. The Scope of Hibernate 3[ Go to top ]

    All the features sounds great, but let me suggest something which is relatively simple but would help a lot with handling BLOBs/CLOBS: the addition of lazy loading support for individual columns.

    This would allow LOBs to be mapped to a String or byte[] with a custom type, but not force a read or write of that value when the owning entity is read or written, unless the field is actually touched.

    Regards,
    Colin
  40. It would be nice to support unidirectional associations (unidirectional one-to-one) Becasue right now it's not possible.
  41. Wrong.
  42. Unidirectional 1-to-1 associations are of course possible.
  43. Undirectional assoiciations[ Go to top ]

    Gavin:
    For example A -> B Y Then I need to have property in B which stores FK to A and it's not transparent because then I need to polute my object model with unsessecary stuff. I'm right? So it's not possible to do that transparently.
    The same applies with 1-m in hibernate. I need to have fk property in child and it sucks.

    Bauer: you are wrong
  44. This is just not correct. Either educate yourself or ask questions on our forum.
  45. I'm surprised how ignorant you are :). I can't believe that you wrote documentation for Hibernate.
    First of all if I have A->B 1-m association and B table kas not null constraint for Fk to the A. Then I need fk property in B. Without this property hibernate first does insert for B then update to update FK to the A and it violiates "not null" constaint.
  46. Mistake:
    insert violates "not null" constraint because Fk to the A is not part of B state
  47. You are right, now that you explained it in words I can understand. I still don't see anything about "one-to-one", so this was confusing.

    B doesn't have the state, so it will be inserted with a NULL foreign key. Your unidirectional 1-M mapping explicitly says that B doesn't know anything about that association, so this is the expected behavior.

    Keep in mind that the NOT NULL for the foreign key column in the relational schema says: This B must always have a relationship with an A. Your unidirectional association is quite different, you _have_ to let B know the A if you want to express the NOT NULL FK constraint in your object model. Whats your proposal? We can't throw a FK violation exception if you simply save a standalone B (and forget that you have to add it to some collection in A). If A and B have a composition relationship and a B is only reference by a single A, why not use a component mapping and be done with it?

    I think you should continue this discussion on the right forum if you are interested in more details.
  48. insults[ Go to top ]

    I'm surprised how ignorant you are :). I can't believe that you wrote documentation for Hibernate. <<<
    You claimed above that unidirectional 1-to-1 was not possible. (You said absolutely /nothing/ about 1-to-many associations.) You were Wrong. Hibernate provides support for primary key associations that certainly may be unidirectional (at either end). So don't you dare call other people "ignorant".

    If you would like to learn how to write a unidirectional 1-to-1, your best bet is to post in the user forum, but it had better be accompanied by an apology to Christian if you expect any kind of answer from me.

    What it turned out that you were actually talking about was unidirectional, *required* *1-to-many* associations. (Unidirectional 1-to-many is certainly possible if the association is optional; it is only once you add the not null constraint that we ask you to make the association bidirectional.)

    Now, it turns out that there are some good reasons for this restriction and that relaxing it would significantly complexify the internals of Hibernate and perhaps even harm performance. (This is all to do with the fact that Hibernate supports detached objects - an incredibly useful and unique feature that imposes certain constraints upon what we can actually implement.)

    But in this case, I honestly don't see how this is a real problem. If your relational schema says that "every Order must have a Customer", what the hell is so "nontransparent" about adding a customer property to Order? It seems merely sane to me. I simply can not imagine a case like this where you would not sometimes want to navigate from Order to Customer.
  49. Association[ Go to top ]

    Christian, please accept my apologies. Context of discussion wasn’t obvious from my statement and it introduced some misunderstanding.

    Gavin:
    it's very import not have depenedencies in huge domain models. Because you can end up that "everybody depends on everybody" and it's only because of hibernate.
    Imagine situation when I have big domain model with 400 classes and 20 root classes such as customer, order and so on. I do not want to relax DB constraints and I don not want to have a "web" of dependencies (cyclic graphs).

    I believe that problem still exist at some degree with 1-to-1 associations. Because I excpect that object will be gone when I have Parent.setOneChild(null) (parent and child have one-to-one mapping) but it's currently not possible to achieve transparently with Hibernate I need to call "session.delete". Now I need to polute my domain with references to hibernate session or create aspects which can handle that.

    Peace,

    Giedrius
  50. Association[ Go to top ]

    Use <component> mappings, they solve all the "problems" you mentioned at the expense of a less expressive and certainly not entirely correct object model.