Results 1 to 6 of 6

Thread: $Proxy13 cannot be cast to

  1. #1
    Join Date
    Apr 2010
    Location
    Kraków, Poland
    Posts
    14

    Default $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 at 12:58 PM. Reason: Additional info

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

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

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Apr 2010
    Location
    Kraków, Poland
    Posts
    14

    Default

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

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

    Quote 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 at 02:26 PM.

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

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

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Apr 2010
    Location
    Kraków, Poland
    Posts
    14

    Default

    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>

  6. #6
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

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

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •