Announcement Announcement Module
Collapse
No announcement yet.
Configuring dpHibernate with Spring BlazeDS Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring dpHibernate with Spring BlazeDS Integration

    Creating this thread to continue an ongoing discussion from Jira about getting dpHibernate set up:
    http://jira.springsource.org/browse/FLEX-26

  • #2
    Well the differences I can see straight away...

    1. I have been using spring 2.5.5 (you 2.5.6A)
    2. I am running under jboss

    Given its a may well be a spring version difference.
    Will try your test under jboss.

    What version of blazeds did you use?

    Comment


    • #3
      OK got past that error and found the root problem with dpHibernate integration....

      From the dphibernate spring sample, remoting-config.xml...
      Code:
              <destination id="storeService">
                      <properties>
                              <source>storeService</source>
                          <factory>spring</factory>
                              <scope>application</scope>
                              <hibernate>
                                      <!--
                                              //the name of the method in this class which follows the hibernate
                                              //load(Class clazz, Serializable id) argument signature.
                                      -->
                                      <loadMethod>load</loadMethod>
                              </hibernate>
                      </properties>
              </destination>
      This loadMethod is missing in the spring config.

      By adding a load method to the service class, and referencing it in the spring config:
      Code:
      <bean id="hibernate-lazy-adapter" class="org.springframework.flex.core.ManageableComponentFactoryBean">
          <constructor-arg value="net.digitalprimates.persistence.hibernate.HibernateAdapter"/>
              <property name="properties">
                  <value>
              {
                  "hibernate":
                  {
                      "sessionFactory":
                      { 
                          "class":"net.digitalprimates.persistence.hibernate.utils.SpringSessionUtil",
                          "getCurrentSessionMethod":"getCurrentSession"
                      },
                      "loadMethod":"load"
                  }
              } 
                  </value>
          </property>
      </bean>
      all finally working.


      A couple of points to note...
      I get an error from blazeds on deployment in jboss if I have no remoting-config.xml file at all, so I just leave a default in place.
      Also, the adpater needs specifying on the remoting-desitnation:

      Code:
      <flex:remoting-destination ref="TestService" service-adapter="hibernate-lazy-adapter"/>
      as the default-adapter-id on remoting-service element doesnt seem to work:

      <flex:message-broker>
      <flex:remoting-service default-adapter-id="hibernate-lazy-adapter"/>
      </flex:message-broker>

      Comment


      • #4
        Thank you for your posting, it almost helped. But I got some exception with the code below:

        Code:
        <bean id="hibernate-lazy-adapter" class="org.springframework.flex.core.ManageableComponentFactoryBean">
            <constructor-arg value="net.digitalprimates.persistence.hibernate.HibernateAdapter"/>
                <property name="properties">
                    <value>
                {
                    "hibernate":
                    {
                        "sessionFactory":
                        { 
                            "class":"net.digitalprimates.persistence.hibernate.utils.SpringSessionUtil",
                            "getCurrentSessionMethod":"getCurrentSession"
                        },
                        "loadMethod":"load"
                    }
                } 
                    </value>
            </property>
        </bean>
        The type of the "properties" property is flex.messaging.config.ConfigMap, and Spring treats the content between {} as a String, and I got a exception saying that cannot convert String to ConfigMap. I really don't know why this happened to me.

        Please help.

        Comment


        • #5
          Hi, currently my DAOs are extending HibernateDAOSupport.

          I'm planning on using dpHibernate.

          How should I modify my code to match with dphibernate ones?

          p/s : I need to extend dpHibernate's HibernateService for DAOs?

          Comment


          • #6
            You could migrate your DAOs to use @Repository instead of extending HibernateDaoSupport.

            Comment


            • #7
              Jeremy,

              Can you update the example at http://static.springsource.org/spring-flex/ as it uses the older style of SBI? I have been trying to integrate dbHibernate with SBI 1.0.1 and I am getting strange errors. I can post what I am getting but I think it would be fastest if you are able to update the example "dpHibernate-test.zip".

              I am not sure how to integrate
              Code:
                      <destination id="storeService">
                              <properties>
                                      <source>storeService</source>
                                  <factory>spring</factory>
                                      <scope>application</scope>
                                      <hibernate>
                                              <!--
                                                      //the name of the method in this class which follows the hibernate
                                                      //load(Class clazz, Serializable id) argument signature.
                                              -->
                                              <loadMethod>load</loadMethod>
                                      </hibernate>
                              </properties>
                      </destination>
              into code that no longer uses the remoting-congif.xml.

              Thanks,
              Joshua

              Comment


              • #8
                Ok, I've updated the test project, but I don't know that it's going to give you any answers. I didn't really have to change anything other than updating the libraries being used.

                I think you should just be able to make that object a singleton Spring bean and use the normal Spring remoting-destination configuration, assuming you've got the dpHibernate adapter set up. Did that not work?

                Comment


                • #9
                  Thanks for updating the example. You are right, it still doesn't help much. I am using DAOs and your example doesn't have any flex app in it either. Would it be possible to update something out of test drive? I am not asking that you post it in test drive, only add a little more to the example.

                  The reason I ask is that when I try to run my example without the line
                  Code:
                  "loadMethod":"load"
                  in the flex-servlet.xml, I get the following error.
                  Code:
                  {operation})****************createItem
                  flex.messaging.MessageException: Cannot invoke method ''. Method '' not found.
                  	at flex.messaging.util.MethodMatcher.methodNotFound(MethodMatcher.java:355)
                  	at flex.messaging.util.MethodMatcher.getMethod(MethodMatcher.java:163)
                  	at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:420)
                  	at net.digitalprimates.persistence.hibernate.HibernateAdapter.superInvoke(HibernateAdapter.java:101)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.invokeLoad(HibernateDeserializer.java:176)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.readHibernateProxy(HibernateDeserializer.java:232)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.translate(HibernateDeserializer.java:105)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.readCollection(HibernateDeserializer.java:223)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.translate(HibernateDeserializer.java:114)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.readBean(HibernateDeserializer.java:194)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.translate(HibernateDeserializer.java:123)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.readBean(HibernateDeserializer.java:194)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.translate(HibernateDeserializer.java:123)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.readCollection(HibernateDeserializer.java:223)
                  	at net.digitalprimates.persistence.translators.hibernate.HibernateDeserializer.translate(HibernateDeserializer.java:114)
                  {operation})****************
                  When I add the line above, and I don't have a "Load" method in my Service class then I get
                  Code:
                  Cannot invoke method 'load'. Method 'load' not found.
                  With the follow load method in the Service I start to make progress but I still can't get it to do work smoothly.
                  Code:
                  	public Object load(Class clazz, Serializable id){
                  		Object result = null;
                  		if( "com.mycompany.myclass".equals(clazz.getName()) ) {
                  			result = this.dao.read(new Long(id.toString()));			
                  		}
                  
                  		// if for some reason hibernate is waiting until the session is closed to initialize
                  		// the collection we need to force the issue now.
                  		if( !Hibernate.isInitialized(result) ) {
                  			Hibernate.initialize(result);
                  			//SpringSessionUtil.getCurrentSession().flush();
                  		}
                  		return result;
                  	}
                  I didn't write this but found it from Mike Nimer, who I think was the original author of dpHibernate.

                  So I am hoping that an updated example that actually has some flex in it will not be too much. If you can do it, it would help a lot of us out.

                  We also eagerly await your version in 1.5.

                  Thanks in advance for you help,
                  Joshua

                  Comment


                  • #10
                    I just noticed this example in the dpHibernate wiki:

                    Code:
                    <bean id="hibernate-lazy-adapter" class="org.springframework.flex.core.ManageableComponentFactoryBean">
                        <constructor-arg value="net.digitalprimates.persistence.hibernate.HibernateAdapter"/>
                        <property name="properties">
                            <value>
                                {
                                    "hibernate": {
                                        "sessionFactory": {
                                            "class":"net.digitalprimates.persistence.hibernate.utils.SpringSessionUtil?", "getCurrentSessionMethod":"getCurrentSession"
                                        }, "loadMethod":"load"
                                    }
                                }
                            </value>
                        </property>
                    </bean>
                    Note the additional "loadMethod" specified there. Can you give that a try?

                    Comment


                    • #11
                      That example is the one that allowed me to get as far as I did but I am still having trouble integrating it. I have a series of objects that are embedded in each other. A is in B, B is in C, C is in D. I Create D then add the data to C and B. Then I save(Update/Merge) D, holding C, holding B. And so on. I have yet to get true lazy loading to work with real objects that are stacked together. I was hoping you could add some flex and the "load" method to the example that you posted to give us all some insight into integrating it to SBI. It is worth meantioning that there is also a branch to dbHibernate that has some code that is supposed to be more integrated with Spring. I am trying it now.

                      thanks,
                      joshua

                      Comment


                      • #12
                        hello jeremy,

                        I tried your modification and it works but there is an exception thrown:


                        java.lang.NullPointerException
                        at net.digitalprimates.persistence.translators.hibern ate.SessionManager.getCurrentSession(SessionManage r.java:85)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.getCollectionProxies(Hiber nateSerializer.java:293)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.writeAbstractPersistentCol lection(HibernateSerializer.java:193)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.translate(HibernateSeriali zer.java:96)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.writeBean(HibernateSeriali zer.java:156)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.translate(HibernateSeriali zer.java:106)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.writeCollection(HibernateS erializer.java:179)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.translate(HibernateSeriali zer.java:100)
                        at net.digitalprimates.persistence.translators.hibern ate.HibernateSerializer.translate(HibernateSeriali zer.java:67)
                        at net.digitalprimates.persistence.hibernate.Hibernat eAdapter.invoke(HibernateAdapter.java:181)
                        at flex.messaging.services.RemotingService.serviceMes sage(RemotingService.java:183)
                        at flex.messaging.MessageBroker.routeMessageToService (MessageBroker.java:1503)
                        at flex.messaging.endpoints.AbstractEndpoint.serviceM essage(AbstractEndpoint.java:884)
                        at flex.messaging.endpoints.AbstractEndpoint$$FastCla ssByCGLIB$$1a3ef066.invoke(<generated>)
                        at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy. java:149)
                        at org.springframework.aop.framework.Cglib2AopProxy$C glibMethodInvocation.invokeJoinpoint(Cglib2AopProx y.java:700)

                        any idea how to fix this?

                        thanks a lot.
                        cheers.

                        Comment


                        • #13
                          hi

                          how can i use more than one service ( eg : TestService, UserService etc.,) using dpHibernate? pls guide me

                          Comment

                          Working...
                          X