Topic: Hibernate

GWT, Remote Models and the Need for Better Replication Algorithms

PESSIMISM, n.
A philosophy forced upon the convictions of theĀ  observer by the disheartening prevalence of the optimist with hisĀ  scarecrow hope and his unsightly smile.

-- Ambrose Bierce, The Devil's Dictionary

I frequently crawl through the various GWT project hosted on Google Code, as well as the few that aren't (like the almost venerable GWT Widget Library). One type of solution that is emerging is what I would call model synchronization libraries. These build on top of the GWT-RPC mechanism and allow a synchronization of an object model on the client-side with a corresponding one on the server-side.

Right now there are two major choices available:

  • hibernate4gwt - Number one with a bullet. Elegant and powerful library that allows you to ship domain objects back and forth between the GWT client and the Java server, persisting changes, all at the cost of extending one class: LazyGwtPojo. There are two basic flavors -- stateless and stateful -- with a couple of different subflavors to support a variety of development use cases.
  • Gwittir - Developed by the two dudes who wrote GWT in Practice, this library provides domain object bindings without forcing a dependency on Hibernate (should we add "Hibernate infected" to our lexicon along side "Maven infected?").

It's clear why these libraries are gaining in popularity. The whole idea of writing applications in GWT is to have a commonality of language and domain model. You want to be consistent and not have to navigate the OO/RPC boundary every time you modify or retrieve your client-side model. (An additional alternative worth mentioning is IT Mill Toolkit 5, which as a server-side ajax framework with it's widgets realized in GWT, already has the client-server synchronization baked in.)

Continue reading »

Hibernate Gotcha: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

This can occur for several different reasons. For example, http://opensource.atlassian.com/projects/spring/browse/SPR-1598. Here is how I came across: Missing hibernate mapping file (hbm.xml) in hibernate SessionFactory.

When we forget to list a hibernate mapping file (*.hbm.xml) during SessionFactory creation, it usually fails fast. This fail fast happens since there is another domain-entity mapping that has many-to-one relationship with this class. However, if a given domain-entity is not being referenced by any other entity mapping file, then Hibernate (obviously) will have no knowledge that this entity-exists.

This is fine, but you expect your query to fail with proper error message when any hibernate query method is called in relation to an unlisted entity. For example, I have a User entity in addition to many other entities. For the sake of argument, let us say that no other entity refers to User entity. So, if I list hibernate mapping files (*.hbm.xml) for all entities except User.hbm.xml, SessionFactory creation won't fail. This is fine since SessionFactory has no magical way to figure out how many entity-classes should have their mapping defined and listed.

However, it should fail when I call methods like Session.createQuery("from com.package.User as s where userName=?"). You would expect Hibernate to fail-fast and complain about un-mapped class (com.package.User in this case). It doesn't. Under these circumstances, trying to execute hql query with positional parameter gives "java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!". Trying to run query with named-param will result in 'org.hibernate.QueryParameterException: could not locate named parameter [<paramname>]". None of these errors say anything about the unmapped entity.

Related Services: Java Application Development, Custom Software Development

Launch: Pathfinder Newsletter

Topics

Search

WordPress

Comments about this site: info@pathf.com