Here goes the code
applicationContext.xml
Code:
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="citFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<bean class="com.sep.padron.business.facade.CITFacade">
<property name="entityDao">
<ref bean="entityDao"/>
</property>
</bean>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-com.sep.padron.business.exception.SystemException</prop>
</props>
</property>
</bean>
<bean id="sequenceDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="sequenceDaoTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
</beans>
dataAccessContext.xml
Code:
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${dataSource.jndiName}</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean id="sqlMap" class="org.springframework.orm.ibatis.SqlMapFactoryBean">
<property name="configLocation">
<value>/WEB-INF/sql-map-config.xml</value>
</property>
</bean>
<bean id="entityDao" class="com.sep.padron.persistence.ibatis.SqlMapEntityDao">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="sqlMap">
<ref local="sqlMap"/>
</property>
<property name="sequenceDaoName">
<value>sequenceDao</value>
</property>
</bean>
<!-- Sequence generator -->
<bean id="sequenceDaoTarget" class="com.sep.padron.persistence.ibatis.SqlMapSequenceDao">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="sqlMap">
<ref local="sqlMap"/>
</property>
</bean>
</beans>
SqlMapSequenceDao
Code:
public class SqlMapSequenceDao extends SqlMapDaoSupport implements SequenceDAO{
public Integer getNextValue(String sequenceName){
// fetch next sequence value from 'SEQUENCE' table
}
}
SqlMapEntityDao
Code:
public class SqlMapEntityDao extends SequenceDependentDao implements EntityDAO{
public String insertRow(Entity entity) {
entity.setEntityId(
super.getSequenceDao().getNextValue("C_ENTIDAD.ENTIDAD_ID").toString());
super.getSqlMapTemplate().executeUpdate("insertEntity", entity);
return entity.getEntityId();
}
}
SequenceDependentDao
Code:
1 -public class SequenceDependentDao extends SqlMapDaoSupport implements ApplicationContextAware{
2 - private String sequenceDaoName;
3 - private ApplicationContext applicationContext;
4 -
5 - public SqlMapSequenceDao getSequenceDao(){
6 - return (SqlMapSequenceDao) this.applicationContext.getBean(this.sequenceDaoName);
7 - }
8 -
9 - public void setSequenceDaoName(String sequenceDaoName){
10- this.sequenceDaoName = sequenceDaoName;
11- }
12-
13- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
14- this.applicationContext = applicationContext;
15- }
16-}
In line 6 is where i get a ClassCastException because the object returned by getBean is an instance of Proxy
I hope this can help you help me :P