Announcement Announcement Module
Collapse
No announcement yet.
$Proxy13 cannot be cast to Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • $Proxy13 cannot be cast to

    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>
    
    	<!-- SERVICE 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;
    	}
    }
    Please for help.

    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.
    Last edited by LancerX; May 1st, 2010, 12:58 PM. Reason: Additional info

  • #2
    Why you are using both
    @Transactional and TransactionProxyFactoryBean for pl.diagno.bo.impl.PersonBOImpl???

    <property name="sessionFactory" ref="sessionFactory" /> must work only with DAO objects not BO objects!

    See carefully this link about TransactionProxyFactoryBean, where is defined your transactionAttributes??

    Consider too this method setProxyTargetClass

    HTH

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Why you are using both
      @Transactional and TransactionProxyFactoryBean for pl.diagno.bo.impl.PersonBOImpl???
      I added @Transactional to BOImp by mistake.

      Originally posted by dr_pompeii View Post
      ...where is defined your transactionAttributes??
      I use annotations to configure entities, so I thought that
      <property name="transactionAttributeSource">
      <bean class="org.springframework.transaction.annotation. AnnotationTransactionAttributeSource" />
      </property>
      in annotations, is equivalent of transactionAttributes in ordinary xml way of definition.
      None the less, I added
      Code:
         <property name="transactionAttributes">
           <props>
             <prop key="insert*">PROPAGATION_REQUIRED</prop>
             <prop key="update*">PROPAGATION_REQUIRED</prop>
             <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
           </props>
         </property>
      but it nothing changed.

      Originally posted by dr_pompeii View Post
      Consider too this method setProxyTargetClass
      I have no idea how to use it, I have never used aop

      Maybe it is important that the application is not sterted in any container (ex. Tomcat) but is standalone?
      Last edited by LancerX; May 2nd, 2010, 02:26 PM.

      Comment


      • #4
        I found this from my old projects, apply to yours
        Not critical differences and see the orange part
        Code:
            <bean id="idConcreteManagerObjectTransactional" abstract="true" 
           	      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
        
                  <property name="transactionManager" >
           	      <ref bean="transactionManager" />
                  </property>
                  <property name="proxyTargetClass" >
                  	<value>true</value>
                  </property>
              
                  <!-- overwriting by my child -->
                  <!--
                  <property name="target" >
                  		<ref bean="idConcrete???ImplTarget" />
                  </property>
                   -->
                  <property name="transactionAttributes" >			     
                      <props>
                        <prop key="*">PROPAGATION_REQUIRED</prop>          			
                      </props>
                   </property>     	      
             </bean>
        
             <bean id="idConcreteProveedorImplManagerObjectTransactional"
         	  parent="idConcreteManagerObjectTransactional" >
                  <property name="target" >
                   	<ref bean="idConcreteProveedorImplTarget" />
                  </property>
              </bean>
        Let me know your advance

        Comment


        • #5
          With proxyTargetClass is works ok!
          Thank you a lot dr_pompeii!!
          My final applicationContext.xml:
          <?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.annotati on.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.OracleDialect</prop>
          </props>
          </property>
          </bean>

          <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverM anagerDataSource"> <!-- class="org.apache.commons.dbcp.BasicDataSource" -->
          <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.Hibernat eTransactionManager">
          <property name="sessionFactory" ref="sessionFactory" />
          </bean>

          <bean id="transactionProxyBean" abstract="true"
          class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
          <property name="transactionManager" ref="txManager" />
          <property name="proxyTargetClass">
          <value>true</value>
          </property>

          <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>

          Comment


          • #6
            With proxyTargetClass is works ok!
            Thank you a lot dr_pompeii!!
            You are welcome!, learn to read carefully the Spring's API, some times are very useful like complement from Spring documentation

            Comment

            Working...
            X