Granite Data Services - JPA and Lazy-Initialization

JPA and Lazy-Initialization

GraniteDS integrates with the major Java Persistence API engines available in the JavaEE world:

  • Hibernate
  • OpenJPA (formerly WebLogic Kodo)
  • EclipseLink (formerly Oracle TopLink)
  • DataNucleus (formerly JPOX)

This integration is again closely coupled with code generation tools available in GraniteDS that replicate on-the-fly JPA entities into an ActionScript3 model. The serialization of JPA entities from Java to Flex (or from Flex to Java) uses a custom mechanism called externalization, that preserves the entire state of the objects, instead of keeping only public properties.

With code generation and externalization, GraniteDS is able to retain JPA entities metadata in the ActionScript3 entities, such as their entire initialization states. Serializing partially uninitialized entities with GraniteDS guaranties that:

  • Uninitialized properties are not unexpectingly initialized during the serialization (for both single-valued associations and collections).
  • ActionScript3 beans keep internally informations about unitialized properties.
  • Sending partially uninitialized ActionScript3 beans back to Java (with these metadata) allows the recreation of JPA entities with the same uninitialized properties.

Thus, this mechanism prevents database and memory overloads (only expected references between entities are actually loaded end serialized) and unexpected database updates (an uninitialized property sent back from Flex to Java will not be considered as a null reference or an empty collection).

Together with the Tide client framework, you may even benefit from transparent initialization, when accessing a lazy-loaded property in your Flex code: this access will trigger an asynchronous initialization request to the server that will serialize back the initialized value.

Read more about this topic:  Granite Data Services