My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
SetupAndConfigurationV2  
Steps for getting going with dpHibernate
Featured
Updated Feb 17, 2011 by martypit...@gtempaccount.com

Client entity classes

Client classes are required to either subclass HibernateBean or implement IHibernateProxy. A sample implementation of IHibernate proxy can be found here.

Additionally, client classes must be annotated with the [Managed] metatag. Eg:

        [Managed]
        [RemoteClass(alias="com.mangofactory.pepper.model.Post")]
        public class Post extends BaseEntity
        {
           ...
        }

Server entity classes

Similarly, your server-side Java classes must either subclass HibernateProxy or implement IHibernateProxy.

A sample implementation of IHibernateProxy can be found here.

IHibernateProxy.java implementation

If implementing IHibernateProxy yourself, you must make sure that getProxyKey() returns your entities primary key. Note - composite keys are not supported.

Server side services

dpHibernate provides various server side configurations. Depending on which features you wish to activate, you need to expose different services

Feature Required Service Interface Shipped Default
Lazy loadingIProxyLoadServiceProxyLoadService
Batched lazy loadingIProxyBatchLoaderProxyBatchLoader
Lazy loading + Batched Loading (recommended minimum)ILazyLoadService + IProxyBatchLoaderLazyLoadService
Update / Delete entitiesIProxyUpdateServiceProxyUpdaterService
All the above (recommended configuration) DataAccessService

  • Note - Spring based versions of the default services are also provided, if your configuration uses Spring. Services are provided both for Spring 2.5.6 and Spring 3.x

A typical server configuration for lazy loading only can be found here, or with both lazy loading and entity persistence here.

Server configuration

Once your services extend / implement the appropraite interfaces, you need to configure them.

The spring configuration is currently somewhat verbose. This is an issue currently being investigated.

An example spring configuration is shown here:

        <bean id="dpHibernateRemotingAdapter"
                class="org.springframework.flex.core.ManageableComponentFactoryBean">
                <constructor-arg value="org.dphibernate.adapters.RemotingAdapter" />
                <property name="properties">
                        <value>
                                {"dpHibernate" :
                                {
                                "serializerFactory" : "org.dphibernate.serialization.SpringContextSerializerFactory"
                                }
                                }
        </value>
                </property>
        </bean>
        <!--
                Provides a basic service for lazy loading operations through
                dpHibernate. It's also exported as a remoting destination, which makes
                it accessible to flex clients
        -->
        <bean id="dataAccessService" class="org.dphibernate.services.SpringLazyLoadService"
                autowire="constructor">
                <flex:remoting-destination />
        </bean>
        <!--
                The main serializer. Converts outbound POJO's to ASObjects with
                dpHibernate proxies for lazy loading. Required
        -->
        <bean id="dpHibernateSerializer" class="org.dphibernate.serialization.HibernateSerializer"
                scope="prototype">
                <property name="pageSize" value="10" />
        </bean>
        <bean id="dpHibernateDeserializer" class="org.dphibernate.serialization.HibernateDeserializer"
                scope="prototype" />

See also this example

This is the minimum configuration. For a more complete example, see here, or more detailed ConfigurationOptions.

Client configration

Client configuration is minimal.

Any services you wish dpHibernate to provide paging support for should be declared as a HibernateRemoteObject, instead of a normal RemoteObject.

For example:

<fx:Declarations>
       <dphibernate:HibernateRemoteObject id="dataService"
                   destination="dataService"
                   bufferProxyLoadRequests="true"
                   fault="faultHandler(event)"/>
</fx:Declarations>

Note: bufferProxyLoadRequests is optional, and is used to define if proxy loads should be buffered to improve performance. See this blog post for more details.

A HibernateRemoteObject can be used like any standard mx:RemoteObject, and configured to point to any destination on your server and invoke methods as per normal. Note: The destination of a HibernateRemoteObject does not need to be a dpHibernateService.

Define DefaultHibernateService

Once your application is initialized, you are required to define the defaultHibernateService. This is the service which calls to fetch lazy-loaded entities will be made over. This destination MUST implement the appropriate interfaces, as defined above.

Set up your service on initialization as follows:

public function onApplicationComplete():void
{
	HibernateManaged.defaultHibernateService = this.dataAccessService;
}

That's it. Now, any entities and collections lazy loaded by Hibernate will be lazily fetched / serialized by dpHibernate.

Comment by galip39, Feb 18, 2011

You made a small mistake :

Lazy loading + Batched Loading (recommended minimum) ILazyLoadService + IProxyBatchLoader

ILazyLoadService doesn't exist, it's IProxyLoadService

Thanks for this article !

Comment by vi.mass...@gmail.com, Apr 29, 2011

Hello,

I set up everything as described in the previous SetupAndConfiguration (V1) because I am not using Spring.

I don't get any java exceptions server side but Lazy loading does not work and I get the following error messages on the client side when I try to access a lazily loaded property onan object :

Asking for Lazy Data for Property country Something bad happend Cannot invoke method ''. Lazy load failed

Any ideas of what could cause this ?

Also I do not use Spring that's why I set up dbHibernate 1.0 and not dpHibernate 2, is it possible to use dpHibernate 2 if I don't use spring ? How would I declare the adapter in the remoting-cnofig.xml ?

One last question, is it possible to disable debug messages (both on client and server side) ?

Thank you for your help.

Comment by lina.hov...@gmail.com, May 11, 2011

Hi, I have a problem. I don't use spring in my project . I just use Flex+BlazeDS+Hibernate so in this case how should I define DefaultHibernateService?(HibernateManaged?.defaultHibernateService = this.dataAccessService;???)

and how should I configure the server while I dont have any <bean>?
thanks ;-)


Sign in to add a comment
Powered by Google Project Hosting