Discussions

News: Using the UJO in Hibernate

  1. Using the UJO in Hibernate (5 messages)

    This article describes how to use UJO objects in the ORM framework Hibernate. What may be the reason to replace traditional POJO objects by more invasive alternative? I think the main advantage is an easy processing of data results by a powerful API - however someone will appreciate the performance increase of certain types of HQL queries too.

    First I would like to refute the myth that the UJO object is complicated magic.
    The UJO can be any object that implements the interface Ujo with four methods. There are available more implementations, but now I will describe QuickUjo contained in UJO Framework 0.91, which is characterized by ease of use and high speed value access in comparison to Java reflection.

    Do you ask how the QuickUjo is working? Inside the object there is only one private field type of object array with a fix length equal to the number of object properties. Because an access to the object values is available by a constant UjoProperty, so we can assign any such property index which is pointing to a one cell from the field. Now we can get the value by this UJO + UjoProperty easily and then the implementation UjoProperty takes care about the appropriate value casting. It's easy, isn't it?

    A typical example of code for reading values:
    String name = Person.NAME.getValue(person);

    the alternative use of extended implementation QuickUjoMid:
    String name = person.get(Person.NAME);

    Let's compare the performance of UJO and POJO objects in an ORM framework Hibernate, however we need to know how to map UJO objects. My colleague Tomas Hampl, wrote an elegant solution based on the implementation of the interface PropertyAccessor, which is now available in UJO Framework 0.91. Due to an imperfection of Hibernate we need to implement more appropriate getters, but they are used by Hibernate only at the startup of applications. We can also write setters for our own convenience so the objects can be used as the common POJOs. Sample implementation UJO is done here.

    The specification of alternative accessor in HBM file is the following:
    default-access =
    "org.ujoframework.hibernateSupport.UjoPropertyAccessor"
    ... >

    If you choose annotations, use the
    @org.hibernate.annotations.AccessType(
    "org.ujoframework.hibernateSupport.UjoPropertyAccessor" )

    and locate annotations on the getters. See the benchmark results. Eeach action contains the time ratio POJO/UJO:
    • SINGLE SELECT: 1.13 (the UJO is 1.13 times faster)
    • EMPTY SELECTS: 1.62
    • MULTI SELECT: 1.79
    • UPDATE: 0.99
    • DELETE: 1.50
    • INSERT: 0.92
    The competent interpretation of results I leave to experts in a discussion on Hibernate rather. Description of the test environment include time values can be found here. Source code can be downloaded from the project page on SourceForge.

    In conclusion, I would like to say to debunk, that the real speed increase occurs mainly in fast and well-indexed SQL queries with a reasonable degree of application logic. If the response is the slow SQL query or the result is intented to to intensive treatment so the time benefit may be lost in the context of another events.

    Related links:

    Video Tutorials on Learning Hibernate
    Hibernate Made Easy WebSite
    Recommended Books for Learning Hibernate

    Threaded Messages (5)

  2. I like the name "Hiberante" :)[ Go to top ]

    I know it was a typo, but I quite like the name "Hiberante". :) Does it mean something in a language other than English? I see from a search on Google that many have made this same mistake. --Matt The Software Grove
  3. Re: I like the name "Hiberante" :)[ Go to top ]

    The wrong title is fixed, thank you :)
  4. plagiarism[ Go to top ]

    I think it's compelling, because it expand a very academic-focussed attitude. Preserving the honestness of the academic system seems to be a lead, although candidly close down compensated ads for such a service seems a fragile response. When the association is known by your friends who were assuaged with the results of the association, about hiberante. But don't foreget always to use check for plagiarism run them through this plagiarism detection system for absolute checking and make sure that your material is authentic.
  5. Key Value Coding[ Go to top ]

    Nice to see the old KVC coming back to JAVA again. The authors claim to have been inspired by the Cayenne projects, which it is inspired by the Next/Apple frameworks. See the following doc http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueCoding/index.html Search for Key Value Observing as well.
  6. Re: Key Value Coding[ Go to top ]

    This is interesting information, thank you. It seems the concept has a long history: http://wiki.objectstyle.org/confluence/display/WO/Overview-Key+Value+Coding