2 Replies Latest reply on Jul 26, 2006 6:16 PM by goik

    booking example and db2

    goik

      Starting the 'booking' example with 1.0.1 GA I tried to configure a db2 DB server. Following http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpADB2Datasource I changed booking-ds.xml to:

      <datasources>
       <local-tx-datasource>
       <jndi-name>bookingDatasource</jndi-name>
       <connection-url>jdbc:db2://localhost:10000/hdm</connection-url>
       <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
       <user-name>midb2</user-name>
       <password>XXX</password>
       <min-pool-size>0</min-pool-size>
      
       <metadata>
       <type-mapping>DB2</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>


      My persistence.xml has an added DB2 dialect property:

      <persistence>
       <persistence-unit name="bookingDatabase">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/bookingDatasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
       </properties>
       </persistence-unit>
      </persistence>


      Starting the application on jboss-4.0.4.GA app. server I can register a new user, browse the list of available hotels. When I try to create a reservation I can still reach the "confirmation" window. But by clicking the "Confirm" button the application hangs.

      The corresponding log entries are:


      00:09:44,726 INFO [STDOUT] Hibernate: select user_.username, user_.name as name2_, user_.password as password2_ from User user_ where user_.username=?
      00:09:44,732 INFO [STDOUT] Hibernate: insert into Booking (id, user_username, checkinDate, checkoutDate, hotel_id, creditCard, smoking, beds, creditCardName, creditCardExpiryMonth, creditCardExpiryYear) values (default, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      00:09:44,742 INFO [STDOUT] Hibernate: values identity_val_local()
      00:09:44,747 INFO [HotelBookingAction] New booking: 1 for goiki
      00:09:44,754 INFO [STDOUT] Hibernate: select booking0_.id as id0_, booking0_.user_username as user10_0_, booking0_.checkinDate as checkinD2_0_, booking0_.checkoutDate as checkout3_0_, booking0_.hotel_id as hotel11_0_, booking0_.creditCard as creditCard0_, booking0_.smoking as smoking0_, booking0_.beds as beds0_, booking0_.creditCardName as creditCa7_0_, booking0_.creditCardExpiryMonth as creditCa8_0_, booking0_.creditCardExpiryYear as creditCa9_0_ from Booking booking0_ where booking0_.user_username=? order by booking0_.checkinDate
      00:14:44,739 WARN [TransactionImpl] Transaction TransactionImpl:XidImpl[FormatId=257, GlobalId=goiki/32, BranchQual=, localId=32] timed out. status=STATUS_ACTIVE
      00:14:44,756 WARN [TransactionImpl] Transaction TransactionImpl:XidImpl[FormatId=257, GlobalId=goiki/33, BranchQual=, localId=33] timed out. status=STATUS_ACTIVE



      I can still access the 'User' and 'Hotel' tables via SQL. The 'booking' table cannot be accessed so there seems to be some sort of locked up transaction. There are definitely no other users accessing the RDBMS. Am I missing something?

      My system: Linux Fedora core 5, DB2 UDB 8.2, IBM's standard JDBC driver, SUN's java 1.5.0_07-b03 .




        • 1. Re: booking example and db2
          tazo

          Got same problem with MSSQL and Derby on Glassfish.

          Booking conformation action handler (HotelBookingAction.confirm method) invokes BookingListAction.getBookings method to update bookings list used in main page after inserting new booking to DB:

          // HotelBookingAction.java
           @End
           public String confirm()
           {
           if (booking==null || hotel==null) return "main";
           em.persist(booking);
           facesMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
           log.info("New booking: #{booking.id} for #{user.username}");
           events.raiseEvent("bookingConfirmed");
           return "confirmed";
           }
          
          // BookingListAction.java
          @SuppressWarnings("unchecked")
           @Factory
           @Observer("bookingConfirmed")
           public void getBookings() {
           bookings = em
           .createQuery(
           "from Booking b where b.user.username = :username order by b.checkinDate")
           .setParameter("username", user.getUsername()).getResultList();
           }
          
          
          


          BookingListAction is annotated with @TransactionAttribute(REQUIRES_NEW). That's why deadlock.


          • 2. Re: booking example and db2
            goik

            Thanks a lot! I read SUN's j2ee 1.5 introduction, changing the annotation to javax.ejb.TransactionAttributeType.REQUIRED thus avoiding a deadlock. I still wonder about impacts to the business logic, Maybe reading further will clarify my open questions.