When I use my BO (buissness object) there is an exception:
Code:
$Proxy13 cannot be cast to pl.diagno.bo.impl.PersonBOImpl
This is quite strange because I use that configuration in the another project and it works fine.
My applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>pl.diagno.model.vo.City</value>
<value>pl.diagno.model.vo.Users</value>
<value>pl.diagno.model.vo.Person</value>
<value>pl.diagno.model.vo.Permitions</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="show_sql">true</prop>
<prop key="dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@xxx-90ac33161e0:1521:XE" />
<property name="username" value="diagno" />
<property name="password" value="1234" />
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionProxyBean" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean>
<!-- DAO BEANS -->
<bean id="cityDao" class="pl.diagno.dao.impl.CityDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="personDao" class="pl.diagno.dao.impl.PersonDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- BO BEANS -->
<bean id="personBo" parent="transactionProxyBean">
<property name="target">
<bean class="pl.diagno.bo.impl.PersonBOImpl">
<property name="personDAO" ref="personDao" />
<property name="cityDAO" ref="cityDao" />
</bean>
</property>
</bean>
<bean id="cityBo" parent="transactionProxyBean">
<property name="target">
<bean class="pl.diagno.bo.impl.CityBOImpl">
<property name="cityDAO" ref="cityDao" />
</bean>
</property>
</bean>
</beans>
Code:
public class PersonBOImpl implements IPersonBO {
IPersonDAO personDAO;
ICityDAO cityDAO;
public PersonBOImpl() {
}
@Transactional(propagation = Propagation.SUPPORTS)
public void saveNewPerson(String name, String surname, String city,
String street, String pesel, Date birthDate, String sex, boolean isClient, boolean isMember, Users users) {
City cityToSave;
List<City> cityList = cityDAO.find("from City c where name = ?", city);
long id = ((City)cityList.get(0)).getId();
cityToSave = cityDAO.load(id);
personDAO.save(new Person(name, surname, cityToSave, street, pesel, birthDate, sex, isClient, isMember, users));
}
public IPersonDAO getPersonDAO() {
return personDAO;
}
public void setPersonDAO(IPersonDAO personDAO) {
this.personDAO = personDAO;
}
public ICityDAO getCityDAO() {
return cityDAO;
}
public void setCityDAO(ICityDAO cityDAO) {
this.cityDAO = cityDAO;
}
}
When I use DAO bean (personDAO) to execute some operations it works ok. But when I use personBO (with injected personDAO) and wrapped into transactionProxyBean, there is this problem.
Please for help.
EDIT:
I edit my personBo bean removing parent bean and add sessionFactory reference.
Code:
<bean id="personBo" class="pl.diagno.bo.impl.PersonBOImpl"> <!-- autowire="byName" -->
<property name="sessionFactory" ref="sessionFactory" />
<property name="personDAO" ref="personDao" />
<property name="cityDAO" ref="cityDao" />
</bean>
I added sessionFactory setter to PersonBOImpl.java and it works!
So the problem is with transactions.