Announcement Announcement Module
Collapse
No announcement yet.
saveOrUpdate issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • saveOrUpdate issue

    Hello,

    I have met a problem for getHibernateTemplate().saveOrUpdate(order);

    If the method is tested from class OrderTest's testCreateOrder(), it works fine and one order is inserted in the db. But if it is called from a serviceTest, no order is created and no error also. I am using Spring1.01, Hibernate 2.* and Oracle10g.

    The method in OrderTest is :

    public void testCreateOrder() {
    Market market = marketDAO.loadMarket(new Long(1));

    PaymentMethod pm = new PaymentMethod();
    pm.setPaymentMethodId(new Long(1));

    User u = new User();
    u.setUserId(new Long(3));

    String orderType = DomainCodes.ORDER_TYPE_ASK;

    Order o = new Order();
    o.setMarket(market);
    o.setGroup(market.getGroup());
    o.setUltimateGroup(market.getUltimateGroup());
    o.setNumberOfLots(new Long(1));
    o.setOrderFunction(DomainCodes.ORDER_FUNCTION_BID_ ASK);
    o.setOrderStatus(DomainCodes.ORDER_STATUS_OPEN);
    o.setOrderType(orderType);
    o.setQuantityPerLot(new Long(2));
    o.setPricePerUnit(new Long(10000));
    o.setPaymentMethod(pm);
    o.setProgram(market.getProgram());
    o.setUser(u);
    o.setAuditable(new Long(3), DomainCodes.AUDIT_REASON_NEW_RECORD, DomainCodes.AUDIT_STATUS_ACTIVE);

    orderDAO.saveOrder(o);

    if(orderType.equals(DomainCodes.ORDER_TYPE_ASK))
    setCertificatesToOrder(market.getMarketId(), u.getUserId(), o, new Long(2));
    }

    It is fine with one order created.

    =====================

    Method in ServiceTest is:

    public void testCreateOrder() {
    Market market = marketDAO.loadMarket(new Long(1));

    PaymentMethod pm = new PaymentMethod();
    pm.setPaymentMethodId(new Long(1));

    User u = new User();
    u.setUserId(new Long(3));

    String orderType = DomainCodes.ORDER_TYPE_ASK;

    orderService.createOrder(new Long(2), new Long(30000), orderType, new Long(1), market, u);
    }

    No error but no order created in table.

    ============

    The method createOrder() in Service is :

    public void createOrder(Long quantity, Long pricePerUnit, String orderType, Long paymentMethodId, Market market, User user) {
    PaymentMethod pm = new PaymentMethod();
    pm.setPaymentMethodId(paymentMethodId);

    Order o = new Order();
    o.setMarket(market);
    o.setAuditable(user.getUserId(), DomainCodes.AUDIT_REASON_NEW_RECORD, DomainCodes.AUDIT_STATUS_ACTIVE);
    o.setGroup(market.getGroup());
    o.setUltimateGroup(market.getUltimateGroup());
    o.setNumberOfLots(new Long(1));
    o.setOrderFunction(DomainCodes.ORDER_FUNCTION_BID_ ASK);
    o.setOrderStatus(DomainCodes.ORDER_STATUS_OPEN);
    o.setOrderType(orderType);
    o.setQuantityPerLot(quantity);
    o.setPricePerUnit(pricePerUnit);
    o.setPaymentMethod(pm);
    o.setProgram(market.getProgram());
    o.setUser(user);

    orderDAO.saveOrder(o);

    if(orderType.equals(DomainCodes.ORDER_TYPE_ASK))
    setCertificatesToOrder(market.getMarketId(), user.getUserId(), o, quantity);
    }

    The testCreateOrder method in OrderTest is almost a copy of createOrder method in ServiceTest.

    =================

    The applicationContext is :

    <bean id="orderDAO" class="com.xyz.persistence.hibernate.dao.impl.Orde rDAOImpl">
    <property name="sessionFactory"><ref local="localSession"/></property>
    </bean>

    <bean id="orderDAOService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></property>
    <property name="target"><ref local="orderDAO"/></property>
    <property name="transactionAttributes">
    <!-- define the transaction specs here -->
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>


    <bean id="orderServiceTarget" class="com.xyz.services.frontend.OrderServiceImpl" >
    <property name="orderDAO"><ref local="orderDAO"/></property>
    <property name="marketDAO"><ref local="marketDAO"/></property>
    </bean>

    <bean id="orderService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></property>
    <property name="target"><ref local="orderServiceTarget"/></property>
    <property name="transactionAttributes">
    <!-- define the transaction specs here -->
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    I drop Other beans associated in applicationContext here to save space.

    ===================

    The hibernate sql results are
    (1) testCreateOrder in OrderTest

    Hibernate: select market0_.MARKET_ID as MARKET_ID11_ .......
    Hibernate: select order_sequence.nextval from dual
    Hibernate: insert into ORDER_TABLE (ORDER_FUNCTION, .....

    (2) testCreateOrder in ServiceTest
    Hibernate: select market0_.MARKET_ID as MARKET_ID11_ .......
    Hibernate: select order_sequence.nextval from dual

    no insert into sql for this case.

    Any input or thought?

    Thanks very much

  • #2
    saveOrUpdate issue

    Not really sure... just some guesses....:
    For me it is not quite clear why you are declaring the "orderService" TransactionProxy with the "orderServiceTarget" Target. Should'nt "orderDAOService" be suffient? Also i guess that the <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> rule applies always for the "oderService", which could explain your problem.
    As said just some guesses ;-)
    Maybe it helps.
    Christoph

    Comment


    • #3
      I think you are right. Thanks very much for the help.

      Comment

      Working...
      X