Hi,

so this thread has inspired me (along with some freetime) to clean up my Tapestry-Hibernate DAO code, but I'm having a hard time getting the @CommitAfter annotation to seemingly work correctly. I'm assuming I'm missing a small step. I advise the TransactionCommitAdvice in my AppModule:

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

In my DAO service class I take the session as a constructor injection:

public DAO(Session session, Logger log){

        this.ses = session;

        this.log = log;

        getNextTxnId(); //load in a new txn_id

}


and I have my update method as follows:

@CommitAfter
        protected void executeUpdate(Entity entity){
                try{
        //              txn = ses.beginTransaction();
                        
                        System.out.println("In executeUpdate of DAO base class: 
about to commit a " + entity.getClass().getName());
                        
                        ses.update( (entity.getClass().cast(entity)) ); //Use 
reflection to cast the object correctly
                        System.out.println("**Between ses.update and 
txn.commit**");
        //              txn.commit();
                        System.out.println("**after txn.commit**");
                }catch(HibernateException he){
                        System.out.println("**Between ses.update and txn.rollback 
because of an exception! Exception: " + he);
        //              txn.rollback();
                        throw new DAOException("Could not commit the " + 
entity.getClass().getName() + " object!");
                }
                }catch(ClassCastException cce){
                        System.out.println("**Between ses.update and txn.rollback 
because of an exception! Exception: " + cce);
                        //              txn.rollback();
                        throw new DAOException("Could not commit the " + 
entity.getClass().getName() + " object! ClassCastException reflecting the entity.");
                }

        }


As you can see, I used to manage the Transaction manually, as this actually worked (although occasionally would give some Hibernate error about Transaction not started that never seemed to affect functionality).

Now that I added @CommitAfter and removed the Transaction logic code, the entities no longer get committed to the database.

I have the Hibernate configuration set to show SQL executed, and the UPDATE line never occurs now like it used to.

Is there something I'm missing? Does @CommitAfter need to be on every method along the stack from the top level call on the page class down through this update method or something?

Thanks,
Rich


On 10/08/2010 03:41 AM, Howard Lewis Ship wrote:
Which is true, but if you aren't going to use the facilites of
Tapestry, such as its built-in Hibernate integration, then please seek
answers to your problems elsewhere.

Using the Tapestry mechanisms means that the you can be sure of using
the same session instance across all pages, components and services
(within a transaction). The session will be created only as needed and
will be discarded automatically at the end of the request. You can use
@CommitAfter on any component method, and can configure you services
to recognize it as well. In addtion, you have added in-Tapestry hooks
to configure Hibernate at startup, and Tapestry will automatically
register entity beans it finds in your applications' entities package,
and automatically set up URL encoding/decoding of entity objects.
It's actually quite a lot.

So there's reasons to use the right tools. But again, if you want to
use some other approach, that's fine ... just don't seek help here. Go
on the Hibernate mailing lists.

On Fri, Oct 8, 2010 at 12:07 AM, ael<alan-lua...@dash.com.ph>  wrote:
So what would be the difference?
The important is you achieve
what you want to do.
--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Early-steps-getting-Tapestry-and-Hibernate-working-via-DAO-tp3072498p3204134.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






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

Reply via email to