Announcement Announcement Module
Collapse
No announcement yet.
Declarative transactions - cd... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declarative transactions - cd...

    Hi,

    Based on your previous suggestions I made some experiences, so today I have only one question.

    Let me add in the first step an entry of applicationContext.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <tx:annotation-driven/>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="configLocation"
    value="file:src/hibernate.cfg.xml">
    </property>
    <property name="useTransactionAwareDataSource" value="true" />
    </bean>

    <bean id="PersonsDAO" class="spring.hibernate.PersonsDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="transactionManagerProxy"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="proxyTargetClass" value="true"/>
    <property name="target" ref="PersonsDAO" />
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    </beans>


    After that I get en exception:

    Caused by: org.springframework.aop.framework.AopConfigExcepti on: Couldn't generate CGLIB subclass of class [class $Proxy6]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6
    Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer .java:446)
    at net.sf.cglib.transform.TransformingClassGenerator. generateClass(TransformingClassGenerator.java:33)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:216)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:377)
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:2 85)
    at org.springframework.aop.framework.Cglib2AopProxy.g etProxy(Cglib2AopProxy.java:196)
    at org.springframework.aop.framework.ProxyFactory.get Proxy(ProxyFactory.java:110)
    at org.springframework.aop.framework.AbstractSingleto nProxyFactoryBean.getProxy(AbstractSingletonProxyF actoryBean.java:187)
    at org.springframework.aop.framework.AbstractSingleto nProxyFactoryBean.afterPropertiesSet(AbstractSingl etonProxyFactoryBean.java:159)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1202)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1172)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:428)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:156)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:160)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:284)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:352)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:93)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:77)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:67)
    at spring.hibernate.PersonsDAO.getDao(PersonsDAO.java :78)
    at spring.hibernate.Client.main(Client.java:11)



    What was wrong
    KM

  • #2
    What does "Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy6" tell you? Do you use final classes anywhere?

    Regards, Ollie

    PS: Please use the code tag to make stacktraces and config samples more readable...

    Comment


    • #3
      OK, I noticed that, but I used there only standard libraraies shipped with MyEclipse (equals Eclipse 3.2.1) installation actually.

      Does it mean I should change something in my build environment?

      Krzysztof

      Comment


      • #4
        I guess you don't have to. Have you marked any transactional classes as final? It seems to be aproblem of your business code, not the infrastructural one.

        Regards, Ollie

        Comment


        • #5
          Originally posted by kmalinow View Post
          What was wrong
          You probably get your beans double-proxied by using tx:annotation-driven and TransactionFactoryBean. Use only the one or the other.

          Joerg

          Comment


          • #6
            Thanks,

            I selected only one type of TransactionFactoryBean, it works, but I noticed a new one case.

            For testing I described tarnsaction property for saving method, named 'save()' just like that:

            <property name="transactionAttributes">
            <props>
            <prop key="save*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="delete*">PROPAGATION_REQUIRED</prop>
            <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
            </property>

            Even the 'save()' method was described as readOnly, I could modify some values inside databse.

            Why?

            Comment


            • #7
              readOnly is just an hint to the database driver to eventually optimize data acess it is NOT preventing you from writing into the database.

              Regards, Ollie

              Comment

              Working...
              X