-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: $Proxy13 cannot be cast to
PostPosted: Sat May 01, 2010 9:20 am 
Newbie

Joined: Wed Mar 11, 2009 7:15 am
Posts: 13
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.


Top
 Profile  
 
 Post subject: Re: $Proxy13 cannot be cast to
PostPosted: Mon May 03, 2010 5:01 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Seems to be the problem with proxy instances like described in book 'java persistence with hiberante' section 7.3.1.
Anyway, please post the whole exception with full stacktrace,


Top
 Profile  
 
 Post subject: Re: $Proxy13 cannot be cast to
PostPosted: Mon May 03, 2010 12:28 pm 
Newbie

Joined: Wed Mar 11, 2009 7:15 am
Posts: 13
Adding
Code:
<property name="proxyTargetClass">
<value>true</value>
</property>

to my transactionProxyBean solved the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.