Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring TransactionProxyFactoryBean not loading dao for service
    primarykey
    data
    text
    <p>I'm having trouble setting up Spring with Hibernate under GWT framework. I am fairly new to GWT. I have the application context set up and loading without output errors, but my main issue at the moment is that the my Service layer implementation (PobaseServiceImpl) requires a DAO that I set up in the appcontext but its not wrapping the DAO. Naturally my RPC is attempting to call the dao methods resulting in a NullPointerException. The pobaseDao is not being set by the TransactionProxyFactoryBean when I initialize it.</p> <p><strong>In summary:</strong> The DAO should be created by (that is, configured into) Spring just like the rest of my services. Then injected to the services via Spring. Then with the DAO, wrap it in a Spring transaction proxy (org.springframework.transaction.interceptor.TransactionProxyFactoryBean) and give it a Hibernate SessionFactory (org.springframework.orm.hibernate4.LocalSessionFactoryBean). But for some reason its not setting the dao</p> <p>So my application context is being loaded through a ServletContextListener. Here is my application context:</p> <pre class="lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt; &lt;!-- Spring Framework application context definition for the POBASE Website. --&gt; &lt;beans&gt; &lt;!-- Configurer that replaces ${...} placeholders with values from a properties file --&gt; &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;value&gt;classpath:/pobase.properties&lt;/value&gt; &lt;value&gt;file:${user.home}/pobase.properties&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="ignoreResourceNotFound" value="no"/&gt; &lt;/bean&gt; &lt;!-- Hibernate Data Source --&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${pobase.database.driver}" /&gt; &lt;property name="url" value="${pobase.database.url}" /&gt; &lt;property name="username" value="${pobase.database.user}" /&gt; &lt;property name="password" value="${pobase.database.password}" /&gt; &lt;/bean&gt; &lt;!-- Hibernate SessionFactory --&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource" /&gt; &lt;/property&gt; &lt;property name="packagesToScan" value="nz.co.doltech.pobase.client.entity"/&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;${pobase.hibernate.dialect}&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;${pobase.hibernate.show_sql}&lt;/prop&gt; &lt;prop key="javax.persistence.validation.mode"&gt;none&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;!-- Default transaction proxy, defining the transactional behaviour for a typical Dao configuration --&gt; &lt;bean id="baseDaoTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"&gt; &lt;property name="transactionManager" ref="transactionManager" /&gt; &lt;property name="transactionAttributes"&gt; &lt;value&gt;*=PROPAGATION_MANDATORY&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Default transaction proxy, defining the transactional behaviour for a typical Service configuration --&gt; &lt;bean id="baseServiceTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"&gt; &lt;property name="transactionManager" ref="transactionManager" /&gt; &lt;property name="transactionAttributes"&gt; &lt;value&gt;*=PROPAGATION_REQUIRED&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= --&gt; &lt;bean id="pobaseDao" parent="baseDaoTransactionProxy"&gt; &lt;property name="target" ref="pobaseDaoTarget" /&gt; &lt;/bean&gt; &lt;bean id="pobaseDaoTarget" class="nz.co.doltech.pobase.server.dao.PobaseHibernateDao"&gt; &lt;property name="sessionFactory" ref="sessionFactory" /&gt; &lt;/bean&gt; &lt;bean id="pobaseService" parent="baseServiceTransactionProxy"&gt; &lt;property name="target" ref="pobaseServiceTarget" /&gt; &lt;/bean&gt; &lt;bean id="pobaseServiceTarget" class="nz.co.doltech.pobase.server.service.PobaseServiceImpl"&gt; &lt;property name="pobaseDao" ref="pobaseDao" /&gt; &lt;!-- property name="accessControlService" ref="accessControlService" /&gt; &lt;property name="lookupService" ref="lookupService"/&gt; &lt;property name="notificationService" ref="notificationService"/ --&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>and here is my RPC servlet implementation:</p> <pre class="lang-js prettyprint-override"><code>package nz.co.doltech.pobase.server.service; /** * Extends RSS and implements the PobaseService * @author Ben */ @SuppressWarnings("serial") public class PobaseServiceImpl extends RemoteServiceServlet implements PobaseService { @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(PobaseServiceImpl.class.getName()); private PobaseDao pobaseDao; private final HashMap&lt;Integer, PobaseEntity&gt; pobaseEntities = new HashMap&lt;Integer, PobaseEntity&gt;(); private void fetchExternPobase() { pobaseEntities.clear(); List&lt;PobaseEntity&gt; pobaseList = pobaseDao.getAllPobase(); for (int i = 0; i &lt; pobaseList.size(); i++) { PobaseEntity en = pobaseList.get(i); if(en != null) { pobaseEntities.put(en.getId(), en); } } } public void setPobaseDao(PobaseDao dao) { this.pobaseDao = dao; } public PobaseDao getPobaseDao() { return this.pobaseDao; } public PobaseData addLocalPobase(PobaseData pobase) { PobaseEntity entity = new PobaseEntity(); entity.mirrorObjectData(pobase); pobase.setId(pobaseEntities.size()); pobaseEntities.put(pobase.getId(), entity); return entity.getDataObject(); } public PobaseData updateLocalPobase(PobaseData pobase) { PobaseEntity entity = new PobaseEntity(); entity.mirrorObjectData(pobase); pobaseEntities.remove(entity.getId()); pobaseEntities.put(entity.getId(), entity); return entity.getDataObject(); } public Boolean deleteLocalPobase(int id) { pobaseEntities.remove(id); return true; } public ArrayList&lt;PobaseData&gt; deleteLocalPobases(ArrayList&lt;Integer&gt; ids) { for (int i = 0; i &lt; ids.size(); ++i) { deleteLocalPobase(ids.get(i)); } return getLocalPobaseData(); } public ArrayList&lt;PobaseData&gt; getLocalPobaseData() { ArrayList&lt;PobaseData&gt; pobaseList = new ArrayList&lt;PobaseData&gt;(); Iterator&lt;Integer&gt; it = pobaseEntities.keySet().iterator(); while(it.hasNext()) { PobaseData pobase = pobaseEntities.get(it.next()).getDataObject(); pobaseList.add(pobase); } return pobaseList; } public PobaseData getLocalPobase(int id) { return pobaseEntities.get(id).getDataObject(); } public ArrayList&lt;PobaseData&gt; resyncExternPobase() { fetchExternPobase(); return getLocalPobaseData(); } } </code></pre> <p>Also here is the start-up log for the web application:</p> <pre class="lang-html prettyprint-override"><code>ServletContextListener started Nov 12, 2012 8:20:33 PM nz.co.doltech.pobase.SpringInitialiser initSpringContext INFO: Creating new Spring context. Configs are [/nz/co/doltech/pobase/appcontext.xml] Nov 12, 2012 8:20:33 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@8423321: startup date [Mon Nov 12 20:20:33 NZDT 2012]; root of context hierarchy Nov 12, 2012 8:20:33 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [nz/co/doltech/pobase/appcontext.xml] Nov 12, 2012 8:20:33 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties INFO: Loading properties file from class path resource [pobase.properties] Nov 12, 2012 8:20:33 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties INFO: Loading properties file from URL [file:/home/ben/pobase.properties] Nov 12, 2012 8:20:33 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4c56666d: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,baseDaoTransactionProxy,baseServiceTransactionProxy,pobaseDao,pobaseDaoTarget,pobaseService,pobaseServiceTarget]; root of factory hierarchy Nov 12, 2012 8:20:33 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName INFO: Loaded JDBC driver: org.postgresql.Driver Nov 12, 2012 8:20:33 PM org.hibernate.annotations.common.Version &lt;clinit&gt; INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Nov 12, 2012 8:20:33 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.7.Final} Nov 12, 2012 8:20:33 PM org.hibernate.cfg.Environment &lt;clinit&gt; INFO: HHH000206: hibernate.properties not found Nov 12, 2012 8:20:33 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Nov 12, 2012 8:20:34 PM org.hibernate.dialect.Dialect &lt;init&gt; INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect Nov 12, 2012 8:20:34 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException Nov 12, 2012 8:20:34 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) Nov 12, 2012 8:20:34 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt; INFO: HHH000397: Using ASTQueryTranslatorFactory Nov 12, 2012 8:20:34 PM org.springframework.orm.hibernate4.HibernateTransactionManager afterPropertiesSet INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@55acc0d4] of Hibernate SessionFactory for HibernateTransactionManager Starting Jetty on port 8888 </code></pre> <p>Anyone have any ideas as to why its not working? Some specs here:</p> <ul> <li>Spring 3.2.0</li> <li>Hibernate4</li> <li>GWT SDK 2.4.0</li> </ul> <p>Appreciate any help I can get!</p> <p>Cheers, Ben</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload