Hi all!

I'm using Tapestry Hibernate in a sample project and am experiencing some
strange behavior. The first time the user of my webapp is trying to change
data or save it to the database, it fails telling me that the transaction
has not been started. After this first hickup all subsequent operations work
as expected.

I've placed breakpoints in HibernateSessionManagerImpl and see that the
first time the session is created and a transaction is started in the
constructor. My breakpoint in my application's AppModule
adviseTransactions() method where I add the advisor for the @CommitAfter
annotation gets hit after the session and transaction are created/started.
Then the actual database operation fails ("transaction has not been
started"). If I hit refresh in the browser, the flow of execution goes again
through the HibernateSessionManagerImpl(Session), a session and transaction
get created and this time it succeeds to write to the database.

>From my AppModule:

    @Match("StoreService")
    public static void adviseTransactions(HibernateTransactionAdvisor
advisor, MethodAdviceReceiver receiver) {
        advisor.addTransactionCommitAdvice(receiver);
    }

StoreService is an interface that as @CommitAfter annotations on those
methods that change data.

One method in the implementation is

        public void storeSaleItem(final StoreUser storeUser, final SaleItemDO
saleItem) {
                try {
                        saleItemRepository.storeSaleItem(storeUser, 
saleItem.getSaleItem()) ;
                } catch (SaleItemRepositoryException e) {
                        throw new RuntimeException(e) ; // to be caught be the 
transaction advice
                }
        }

and inside the saleItemRepository.storeSaleItem I do

                saleItem.setStoreUser(storeUser) ;
                saleItem.setModifiedDate(new Date()) ;
                session.saveOrUpdate(saleItem) ;

I have a dependency on both tapestry-hibernate and tapestry-hibernate-core.
The underlying database is MySQL 5. My HibernateConfigurer does:

        configuration
        .setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQLInnoDBDialect")
        .setProperty("hibernate.connection.driver_class",
"com.mysql.jdbc.Driver")
        .setProperty("hibernate.connection.url",
"jdbc:mysql://localhost/petstore_prod")
        .setProperty("hibernate.connection.username", "root")
        .setProperty("hibernate.connection.password", "")
        .setProperty("hibernate.current_session_context_class", "thread")
        .setProperty("hibernate.hbm2ddl.auto", "update") ;

Any thoughts what might be the reason for the described behavior?

Stephan


-----
--
http://www.caimito.net - Caimito One Team - Agile Collaboration and Planning
tool
http://www.stephan-schwab.com - Personal blog
http://code.google.com/p/tapestry-sesame - Authentication extension for
Tapestry 5

-- 
View this message in context: 
http://old.nabble.com/Tapestry-Hibernate---Transaction-starts-on-second-attempt-tp28936067p28936067.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to