672329 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 5 Messages: 5 Messages: 5 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Using the UJO in Hibernate

Posted by: Pavel Ponec on October 14, 2009 DIGG
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:
<hibernate-mapping>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:

Threaded replies

·  Using the UJO in Hibernate by Pavel Ponec on Wed Oct 14 11:58:06 EDT 2009
  ·  I like the name "Hiberante" :) by Matthew Passell on Wed Oct 14 14:28:31 EDT 2009
    ·  Re: I like the name "Hiberante" :) by Pavel Ponec on Wed Oct 14 15:06:07 EDT 2009
      ·  plagiarism by Dimon Jumper on Fri Oct 16 09:22:05 EDT 2009
  ·  Key Value Coding by Alejandro M. Ramallo on Tue Oct 20 15:34:01 EDT 2009
    ·  Re: Key Value Coding by Pavel Ponec on Thu Oct 22 16:12:47 EDT 2009
  Message #325781 Post reply Post reply Post reply Go to top Go to top Go to top

I like the name "Hiberante" :)

Posted by: Matthew Passell on October 14, 2009 in response to Message #324608
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

  Message #325784 Post reply Post reply Post reply Go to top Go to top Go to top

Re: I like the name "Hiberante" :)

Posted by: Pavel Ponec on October 14, 2009 in response to Message #325781
The wrong title is fixed, thank you :)

  Message #326106 Post reply Post reply Post reply Go to top Go to top Go to top

plagiarism

Posted by: Dimon Jumper on October 16, 2009 in response to Message #325784
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.

  Message #326850 Post reply Post reply Post reply Go to top Go to top Go to top

Key Value Coding

Posted by: Alejandro M. Ramallo on October 20, 2009 in response to Message #324608
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.

  Message #327500 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Key Value Coding

Posted by: Pavel Ponec on October 22, 2009 in response to Message #326850
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

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 2

Reza Rahman continues to explore the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (January 21, Article)

Ted Neward Q&A: What you must know about JavaScript, Scala and more

Ted Neward is an independent consultant specializing in high-scale enterprise systems, and an authority in Java and .NET technologies. He is the author and co-author of several books, including Effective Enterprise Java. At TheServerSide Java Symposium in March, he will be presenting sessions on pragmatic architecture, ECMAScript and Scala. (January 15, Article)

Developers split on open sourcing Java

Now that Oracle is absorbing Sun Microsystems, there mixed views on what should come of the Java Community Process (JCP). While some say Oracle should become the new steward of Java and keep the JCP much as it was, others argue that it may be time to open-source this widespread language. (November 24, Article)

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map