Announcement Announcement Module
Collapse
No announcement yet.
LocalSessionFactoryBean bean can't be referenced as a SessionFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LocalSessionFactoryBean bean can't be referenced as a SessionFactory

    I have an application currently working as a Spring app in a single ApplicationContext, which has a LocalSessionFactoryBean bean defined which is then used later in data access objects and provided to other beans as a reference within a property. However, when I create a bundle and try the same thing - I get a "could not be converted to the required type 'interface org.hibernate.SessionFactory'" error.

    <bean id="hibernateSession" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Post greSQLDialect</prop>
    <prop key="hibernate.default_schema">core</prop>
    <prop key="hibernate.current_session_context_class">org. hibernate.context.ThreadLocalSessionContext</prop>
    <prop key="hibernate.connection.release_mode">after_stat ement</prop>
    </props>
    </property>
    </bean>

    <bean id="process.catalogueProcess" class="xxx.GenericCaptureProcess">
    <property name="inBeanName" value="catalogueDTO"/>
    <property name="outBeanName" value="catalog"/>
    <property name="assemblyName" value="assembly/product.xml"/>
    <property name="sessionFactory" ref="hibernateSession"/>
    <property name="sender" ref="sender"/>
    </bean>

    In this example the process.catalogueProcess receives the sessionFactory successfully. When running under DM Server however the startup will fail and I get a message:

    The property value 'org.springframework.orm.hibernate3.LocalSessionFa ctoryBean@193bf6c8', specified in the definition of bean 'process.catalogueProcess', could not be converted to the required type 'interface org.hibernate.SessionFactory'.

    Any ideas about whats going on here?

  • #2
    What does your bundle's manifest look like? Are you importing the org.hibernate package so that you bundle's classloader can see the SessionFactory type?

    Comment


    • #3
      Originally posted by Andy Wilkinson View Post
      What does your bundle's manifest look like? Are you importing the org.hibernate package so that you bundle's classloader can see the SessionFactory type?
      I am importing the org.hibernate package as you can see below. Also, I would expect a ClassNotFound exception if this was the case. What is odd is that it seems to actually assign the LocalSessionFactoryBean object to the bean - rather than calling getObject from LocalSessionFactoryBean and assigning this to the bean.

      Its like it is ignoring the fact it implements FactoryBean and simply assigns it like any other bean.

      Manifest-Version: 1.0
      Export-Package: xxx.service;version=0;uses:="org.hibernate"
      Bundle-Classpath: .
      Bundle-Version: 1.0.0
      Bundle-Name: Resource Manager
      Bundle-ManifestVersion: 2
      Import-Package: org.apache.commons.dbcp;version="[1.2.2.osgi,1.2.2.osgi]",
      org.apache.log4j,
      org.hibernate,
      org.hibernate.cfg,
      org.springframework.orm.hibernate3;version="[2.5.5.A,2.5.5.A]"
      Bundle-SymbolicName: ResourceManager

      Comment


      • #4
        I've tried this on dm Server 1.0.2 using Spring 2.5.6.A and it works fine.

        In your case there would appear to be a type incompatibility. I noticed that you're using Spring 2.5.5.A, what version of dm Server are you running on? 1.0.0 ships with 2.5.5.A, but 1.0.1 and 1.0.2 both ship with 2.5.6.A.

        In dm Server 1.0, you can only use the version of Spring which is packaged with dm Server, so if you're on 1.0.1 or 1.0.2, I'd recommend using Spring 2.5.6.A.

        Comment


        • #5
          Originally posted by Andy Wilkinson View Post
          In your case there would appear to be a type incompatibility. I noticed that you're using Spring 2.5.5.A, what version of dm Server are you running on? 1.0.0 ships with 2.5.5.A, but 1.0.1 and 1.0.2 both ship with 2.5.6.A. In dm Server 1.0, you can only use the version of Spring which is packaged with dm Server, so if you're on 1.0.1 or 1.0.2, I'd recommend using Spring 2.5.6.A.
          Thank you very much, it solved the issue. The problem was that I installed something with a dependency on 2.5.5. To get the bundle to deploy I had to install Spring 2.5.5 specifically. Once you gave me the above information I tracked down the real problem - a dependency which insisted on 2.5.5, removed the version specification, and removed all the Spring 2.5.5 bundles. All is now working fine.

          Thanks to everyone who helped,

          Regards,
          Peter

          Comment

          Working...
          X