Hello, I have a problem when I enable AOP transactions on services that are using hibernate based DAO.
Here is my domain model and hibernate mapping file:
Code:public abstract class PaymentMethod implements Serializable { public Integer getId() { return _id; } public void setId( final Integer id ) { _id = id; } public String getName() { return _name; } public void setName( final String name ) { _name = name; } public Subscriber getSubscriber() { return _subscriber; } public void setSubscriber( final Subscriber subscriber ) { _subscriber = subscriber; } private Integer _id; private String _name; private Subscriber _subscriber; }Code:public class InternalCard extends PaymentMethod { public Double getBalance() { return _balance; } public void setBalance( final Double balance ) { _balance = balance; } private Double _balance; }As you can see, the payment method class is abstract, Internal Card, Credit Card and so on are concrete classes.Code:<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping default-cascade="save-update" auto-import="false"> <class name="com.f4.owl.domain.billing.PaymentMethod" table="bil_payment_method" schema="public"> <id name="id" type="java.lang.Integer"> <column name="bil_payment_method_id"/> <generator class="sequence"> <param name="sequence">bil_payment_method_bil_payment_method_id_seq</param> </generator> </id> <property name="name" type="string"> <column name="bil_payment_method_name" length="50" not-null="true"/> </property> <many-to-one name="subscriber" class="com.f4.owl.domain.billing.Subscriber" fetch="select"> <column name="acc_account_id" not-null="true"/> </many-to-one> <joined-subclass name="com.f4.owl.domain.billing.InternalCard" table="bil_internal_card"> <key column="bil_payment_method_id"/> <property name="balance" type="java.lang.Double"> <column name="bil_internal_card_balance" precision="8" scale="0" not-null="true"/> </property> </joined-subclass> </class> </hibernate-mapping>
Here is my AOP configuration:
The following piece of code is used in a transactional method of the billing service :Code:<!-- the aspects --> <tx:advice id="billingTransactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="buy*"/> <tx:method name="change*"/> <tx:method name="create*"/> <tx:method name="delete*"/> <tx:method name="get*" read-only="true"/> <tx:method name="pay*"/> <tx:method name="transfer*"/> <tx:method name="use*"/> <tx:method name="refresh*" read-only="true"/> <tx:method name="revive*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="billingOperation" expression="execution(* com.f4.owl.service.billing.BillingService.*(..))"/> <aop:advisor advice-ref="billingTransactionAdvice" pointcut-ref="billingOperation"/> <aop:aspect id="detailsLog" ref="detailsLogAspect"> <aop:around pointcut-ref="billingOperation" method="log"/> </aop:aspect> <aop:aspect id="performanceLog" ref="performanceLogAspect"> <aop:around pointcut-ref="billingOperation" method="log"/> </aop:aspect> </aop:config>
Here is the simplified code in the DAO for the selectByPrimaryKey():Code:... PaymentMethod paymentMethod = _paymentMethodDAO.selectByPrimaryKey( paymentMethodId ); Assert.assertTrue( paymentMethod instanceof PaymentMethod); Assert.assertTrue( paymentMethod instanceof InternalCard ); ...
When I use no transactions, the 2 asserts succeed.Code:... return (PaymentMethod) session.get(PaymentMethod.class, primaryKey); ...
When I enable transactions, the second assert failed.
Why is the payment method is proxied in transaction ?
Why the InternalCard is proxied as a PaymentMethod ?
Thanks


Reply With Quote
