I am trying to get dpHibernate 2.0 RC6 running on an Apache Tomcat 7.0.12 with BlazeDS 4.0.0.14931, Spring 3.0.5 and Spring-BlazeDS-Integration 1.5.0.M2
With the following configuration the server starts fine, but as soon as I want to access a service or the RDSDispatchServlet via FlashBuilder4 DCD I am getting a NullPointerException. It seems the serializerFactory is not correctly injected into the dpHibernate HibernateUtil. Did I miss something in the configuration in remoting-config.xml?
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Server</display-name>
<description>Server Side based on BlazeDS, Spring and Hibernate</description>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- begin SPRING INTEGRATION -->
<servlet>
<servlet-name>springMessageBroker</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<!-- <init-param> -->
<!-- <param-name>contextConfigLocation</param-name> -->
<!-- <param-value></param-value> Do not use if using ContextLoaderListener (would load app context twice -> Error) -->
<!-- </init-param> -->
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMessageBroker</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<!-- end SPRING INTEGRATION -->
<!-- begin rds -->
<servlet>
<servlet-name>RDSDispatchServlet</servlet-name>
<servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
<init-param>
<param-name>useAppserverSecurity</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>messageBrokerId</param-name>
<param-value>_messageBroker</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RDSDispatchServlet</servlet-name>
<url-pattern>/CFIDE/main/ide.cfm</url-pattern>
</servlet-mapping>
<!-- end rds -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<filter>
<filter-name>dpHibernateSessionFilter</filter-name>
<filter-class>org.dphibernate.filters.HibernateSessionServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dpHibernateSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
applicationContext.xml (Spring Servlet default configuration file)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="flexContext.xml" />
<import resource="dataAccessContext.xml" />
<import resource="dpHibernateContext.xml"/>
<!-- Enable Spring Transaction Manager with Annotations -->
<tx:annotation-driven />
<context:annotation-config />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="/WEB-INF/server.properties" /></bean>
<context:component-scan base-package="com.mycompany.myproject.*" />
</beans>
flexContext.xml (definitions of services available for flex)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
<flex:message-destination id="chat"/>
<flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml">
<flex:remoting-service default-adapter-id="dpHibernateRemotingAdapter" default-channels="my-amf,my-secure-amf" />
<flex:message-service default-channels="my-streaming-amf,my-polling-amf"/>
</flex:message-broker>
</beans>
fpHibernateContext.xml (configuration of dpHibernate)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
">
<!-- Defines the remoting adapter, which intercepts inbound & outbound messages, and routes them thruogh dpHibernate -->
<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>
<bean id="dpHibernateMessagingAdapter"
class="org.springframework.flex.core.ManageableComponentFactoryBean">
<constructor-arg value="org.dphibernate.adapters.MessagingAdapter" />
</bean>
<bean id="dataAccessService" class="org.dphibernate.services.SpringLazyLoadService" autowire="constructor">
<flex:remoting-destination />
</bean>
<!-- Required -->
<bean id="hibernateSessionFilter" class="org.dphibernate.filters.SpringHibernateSessionServletFilter" />
<!-- The cache is used to prevent serializing the same object many times during serialization. Required -->
<bean id="dpHibernateCache"
class="org.dphibernate.serialization.DPHibernateCache" scope="prototype" />
<!-- 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" />
<!-- Handles entity updates (CRUD). Required if using entity persistence. -->
<bean id="objectChangeUpdater"
class="org.dphibernate.persistence.state.AuthenticatedObjectChangeUpdater"
scope="prototype">
<property name="preProcessors" ref="dpHibernatePreProcessors" />
<property name="postProcessors" ref="dpHibernatePostProcessors" />
</bean>
</beans>
remoting-config.xml (imported in services-config.xml)
<service id="remoting-service"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<adapters>
<adapter-definition id="hibernate-object" class="org.dphibernate.adapters.RemotingAdapter" default="true">
<properties>
<hibernate>
<sessionFactory>
<class>org.dphibernate.utils.HibernateUtil</class>
<getCurrentSessionMethod>getCurrentSession</getCurrentSessionMethod>
</sessionFactory>
</hibernate>
</properties>
</adapter-definition>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</service>
NullPointerException (on service access or rds access via FB4 DCD)
startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.12 11.04.2011 18:34:19 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext 1027 [Thread-2] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final 1066 [Thread-2] INFO org.hibernate.cfg.Environment - Hibernate 3.6.2.Final 1074 [Thread-2] INFO org.hibernate.cfg.Environment - hibernate.properties not found 1085 [Thread-2] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 1116 [Thread-2] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 2146 [Thread-2] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring 2182 [Thread-2] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled. 2194 [Thread-2] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider 2658 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Database -> name : MySQL version : 5.0.51a-24+lenny5-log major : 5 minor : 0 2658 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Driver -> name : MySQL-AB JDBC Driver version : mysql-connector-java-5.1.15 ( Revision: ${bzr.revision-id} ) major : 5 minor : 1 2861 [Thread-2] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 2981 [Thread-2] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory 2991 [Thread-2] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 20 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled 2998 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled 2998 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled 2998 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 3023 [Thread-2] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory 3023 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {} 3023 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled 3023 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled 3023 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled 3029 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge 3074 [Thread-2] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.HashtableCacheProvider 3084 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled 3084 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled 3131 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled 3239 [Thread-2] INFO org.hibernate.impl.SessionFactoryImpl - building session factory 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@17f7be7b 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@17f7be7b 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@9fa8988 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@1f5b44d6 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@21044daf 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@21044daf 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@21882d18 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@734893da 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@21e30857 3379 [Thread-2] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured 11.04.2011 18:34:36 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet 'springMessageBroker' 11.04.2011 18:34:36 org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["http-bio-8080"] 11.04.2011 18:34:36 org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["ajp-bio-8009"] 11.04.2011 18:34:36 org.apache.catalina.startup.Catalina start INFO: Server startup in 21332 ms 11.04.2011 18:49:02 org.apache.catalina.core.StandardWrapperValve invoke SCHWERWIEGEND: Servlet.service() for servlet [RDSDispatchServlet] in context with path [/myJavaServer] threw exception java.lang.NullPointerException at org.dphibernate.utils.HibernateUtil.getSessionFactory(Unknown Source) at org.dphibernate.filters.HibernateSessionServletFilter.getSessionFactory(Unknown Source) at org.dphibernate.filters.AbstractHibernateSessionServletFilter.doFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
org.dphibernate.utils.HibernateUtil (snippet)
private static ISerializerFactory serializerFactory; // should be injected by Spring
public static SessionFactory getSessionFactory() throws HibernateException
{
return serializerFactory.getSessionFactory(); // but is null on this call?
}