E
eunever32
Hi
Hi
I started with the recommendation in APress "beginnng hibernate"
The example worked fine and all the controllers would work so long as the dao was injected directly into the controller.
But then I tried to put a "service" layer between the controller and the dao.
So I was now injecting the "service" into the controller.
And injecting the dao into the service.
I then got this error
Error creating bean with name 'detailsService' defined in ServletContext resource [/WEB-INF/details-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [package.MyDao$$EnhancerByCGLIB$$73073c23] torequired type [package.MyDao] for property 'myDao'; nested exception is java.lang.IllegalArgumentException: Original must not be null
Eventually I discovered I could overcome this error by changing the type ofthe myDao in the service class to just
"Object" and it worked!
Any thoughts on why the problem
1. would happen and
2. if this is an acceptable workaround.
Thanks in advance
Here is the details-servlet.xml:
Here is the database-data.xml:
The dao is defined as follows
<bean id="myDao" parent="daoTxTemplate">
<property name="target">
<bean class="package.myDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- Data Source to use. -->
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>myDto</value>
</list>
</property>
<!-- Hibernate Properties -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.IngresDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<!--<prop key="hibernate.current_session_context_class">thread</prop>
--></props>
</property>
</bean>
<bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="daoTxTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="myDao" parent="daoTxTemplate">
<property name="target">
<bean class="package.myDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</property>
</bean>
Hi
I started with the recommendation in APress "beginnng hibernate"
The example worked fine and all the controllers would work so long as the dao was injected directly into the controller.
But then I tried to put a "service" layer between the controller and the dao.
So I was now injecting the "service" into the controller.
And injecting the dao into the service.
I then got this error
Error creating bean with name 'detailsService' defined in ServletContext resource [/WEB-INF/details-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [package.MyDao$$EnhancerByCGLIB$$73073c23] torequired type [package.MyDao] for property 'myDao'; nested exception is java.lang.IllegalArgumentException: Original must not be null
Eventually I discovered I could overcome this error by changing the type ofthe myDao in the service class to just
"Object" and it worked!
Any thoughts on why the problem
1. would happen and
2. if this is an acceptable workaround.
Thanks in advance
Here is the details-servlet.xml:
Here is the database-data.xml:
The dao is defined as follows
<bean id="myDao" parent="daoTxTemplate">
<property name="target">
<bean class="package.myDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- Data Source to use. -->
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>myDto</value>
</list>
</property>
<!-- Hibernate Properties -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.IngresDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<!--<prop key="hibernate.current_session_context_class">thread</prop>
--></props>
</property>
</bean>
<bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="daoTxTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="myDao" parent="daoTxTemplate">
<property name="target">
<bean class="package.myDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</property>
</bean>