You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jochen Frey <jo...@jochenfrey.com> on 2012/01/12 03:20:34 UTC
@CommitAfter Problem?
Hi!
I am trying to create a startup service that will initialize a database for me. I'm on Tapestry 5.3.1 and I am using tapestry-hibernate.
All the evidence I've been able to find suggests that @CommitAfter isn't executing a commit. Transactions in components that write to the DB after initialization work fine (using @CommitAfter). I can see from the logs that the 'flush' for the transaction in question works correctly (but apparently no commit, which I know because the record is not in the DB afterwards).
Any suggestions as to what I'm missing?
Thanks!!!
Jochen
PS: I tried setting up my own transaction, but that fails miserably with an Exception (Transaction trx = session.beginTransaction();... trx.commit();)
================== Code which isn't committing (DevelopmentDBStartupServiceImp.java) ========
public DevelopmentDBStartupServiceImpl(Logger logger, Session session,
@Symbol(SymbolConstants.PRODUCTION_MODE) boolean isProductionMode) {
this.logger = logger;
this.session = session;
this.isProductionMode = isProductionMode;
}
--- SNIP ---
@CommitAfter
private boolean initSchemaVersion ()
{
// ---- SNIP ----
// we'll assume that it's a virgin DB
SchemaVersion version = new SchemaVersion(SchemaVersion.MAJOR_VERSION, SchemaVersion.MINOR_VERSION);
session.save(version);
session.flush();
return true;
}
=========== How it's called (excerpts from DevelopmentModule.java) =========
public static void bind(ServiceBinder binder)
{
binder.bind(DevelopmentDBStartupService.class, DevelopmentDBStartupServiceImpl.class);
}
@Match("*DB*")
public static void adviseTransactions(HibernateTransactionAdvisor advisor, MethodAdviceReceiver receiver)
{
advisor.addTransactionCommitAdvice(receiver);
}
@Startup
public static void initDevelopmentDatabase (Logger logger, DevelopmentDBStartupService service)
{
logger.info("START Initializing development database.");
service.init();
logger.info("DONE initializing development database.");
}
---
Jochen Frey
jochen@beckon.com
+1.415.366.0450
@jochen_frey
---
jochen@jochenfrey.com
+1.415.366.0450
@jochen_frey
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter Problem?
Posted by Jochen Frey <jo...@jochenfrey.com>.
Turns out I need to annotate the method in the ***INTERFACE*** not the implementing class.
public interface DevelopmentDBStartupService {
/**
* Basic database initialization for development. Confirm schema version and load basic test data.
*/
@CommitAfter
public boolean init();
}
Hope this helps someone else :-)
Cheers!
Jochen
On Jan 11, 2012, at 6:20 PM, Jochen Frey wrote:
> Hi!
>
> I am trying to create a startup service that will initialize a database for me. I'm on Tapestry 5.3.1 and I am using tapestry-hibernate.
>
> All the evidence I've been able to find suggests that @CommitAfter isn't executing a commit. Transactions in components that write to the DB after initialization work fine (using @CommitAfter). I can see from the logs that the 'flush' for the transaction in question works correctly (but apparently no commit, which I know because the record is not in the DB afterwards).
>
> Any suggestions as to what I'm missing?
>
> Thanks!!!
> Jochen
>
> PS: I tried setting up my own transaction, but that fails miserably with an Exception (Transaction trx = session.beginTransaction();... trx.commit();)
>
> ================== Code which isn't committing (DevelopmentDBStartupServiceImp.java) ========
>
> public DevelopmentDBStartupServiceImpl(Logger logger, Session session,
> @Symbol(SymbolConstants.PRODUCTION_MODE) boolean isProductionMode) {
> this.logger = logger;
> this.session = session;
> this.isProductionMode = isProductionMode;
> }
>
> --- SNIP ---
>
> @CommitAfter
> private boolean initSchemaVersion ()
> {
>
> // ---- SNIP ----
>
> // we'll assume that it's a virgin DB
> SchemaVersion version = new SchemaVersion(SchemaVersion.MAJOR_VERSION, SchemaVersion.MINOR_VERSION);
> session.save(version);
> session.flush();
> return true;
> }
>
> =========== How it's called (excerpts from DevelopmentModule.java) =========
>
> public static void bind(ServiceBinder binder)
> {
> binder.bind(DevelopmentDBStartupService.class, DevelopmentDBStartupServiceImpl.class);
> }
>
> @Match("*DB*")
> public static void adviseTransactions(HibernateTransactionAdvisor advisor, MethodAdviceReceiver receiver)
> {
> advisor.addTransactionCommitAdvice(receiver);
> }
>
> @Startup
> public static void initDevelopmentDatabase (Logger logger, DevelopmentDBStartupService service)
> {
> logger.info("START Initializing development database.");
> service.init();
> logger.info("DONE initializing development database.");
> }
>
>
>
>
> ---
> Jochen Frey
> jochen@beckon.com
> +1.415.366.0450
> @jochen_frey
>
>
>
>
>
>
> ---
> jochen@jochenfrey.com
> +1.415.366.0450
> @jochen_frey
>
---
jochen@jochenfrey.com
+1.415.366.0450
@jochen_frey
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter Problem?
Posted by Jochen Frey <jo...@jochenfrey.com>.
Thanks for the quick response, Taha!
On Jan 11, 2012, at 6:24 PM, Taha Hafeez Siddiqi wrote:
> Hi
>
> @CommitAfter should be on the service interface as that is the one being advised
>
> regards
> Taha
>
> On Jan 12, 2012, at 7:50 AM, Jochen Frey wrote:
>
>> Hi!
>>
>> I am trying to create a startup service that will initialize a database for me. I'm on Tapestry 5.3.1 and I am using tapestry-hibernate.
>>
>> All the evidence I've been able to find suggests that @CommitAfter isn't executing a commit. Transactions in components that write to the DB after initialization work fine (using @CommitAfter). I can see from the logs that the 'flush' for the transaction in question works correctly (but apparently no commit, which I know because the record is not in the DB afterwards).
>>
>> Any suggestions as to what I'm missing?
>>
>> Thanks!!!
>> Jochen
>>
>> PS: I tried setting up my own transaction, but that fails miserably with an Exception (Transaction trx = session.beginTransaction();... trx.commit();)
>>
>> ================== Code which isn't committing (DevelopmentDBStartupServiceImp.java) ========
>>
>> public DevelopmentDBStartupServiceImpl(Logger logger, Session session,
>> @Symbol(SymbolConstants.PRODUCTION_MODE) boolean isProductionMode) {
>> this.logger = logger;
>> this.session = session;
>> this.isProductionMode = isProductionMode;
>> }
>>
>> --- SNIP ---
>>
>> @CommitAfter
>> private boolean initSchemaVersion ()
>> {
>>
>> // ---- SNIP ----
>>
>> // we'll assume that it's a virgin DB
>> SchemaVersion version = new SchemaVersion(SchemaVersion.MAJOR_VERSION, SchemaVersion.MINOR_VERSION);
>> session.save(version);
>> session.flush();
>> return true;
>> }
>>
>> =========== How it's called (excerpts from DevelopmentModule.java) =========
>>
>> public static void bind(ServiceBinder binder)
>> {
>> binder.bind(DevelopmentDBStartupService.class, DevelopmentDBStartupServiceImpl.class);
>> }
>>
>> @Match("*DB*")
>> public static void adviseTransactions(HibernateTransactionAdvisor advisor, MethodAdviceReceiver receiver)
>> {
>> advisor.addTransactionCommitAdvice(receiver);
>> }
>>
>> @Startup
>> public static void initDevelopmentDatabase (Logger logger, DevelopmentDBStartupService service)
>> {
>> logger.info("START Initializing development database.");
>> service.init();
>> logger.info("DONE initializing development database.");
>> }
>>
>>
>>
>>
>> ---
>> Jochen Frey
>> jochen@beckon.com
>> +1.415.366.0450
>> @jochen_frey
>>
>>
>>
>>
>>
>>
>> ---
>> jochen@jochenfrey.com
>> +1.415.366.0450
>> @jochen_frey
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---
jochen@jochenfrey.com
+1.415.366.0450
@jochen_frey
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter Problem?
Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
Hi
@CommitAfter should be on the service interface as that is the one being advised
regards
Taha
On Jan 12, 2012, at 7:50 AM, Jochen Frey wrote:
> Hi!
>
> I am trying to create a startup service that will initialize a database for me. I'm on Tapestry 5.3.1 and I am using tapestry-hibernate.
>
> All the evidence I've been able to find suggests that @CommitAfter isn't executing a commit. Transactions in components that write to the DB after initialization work fine (using @CommitAfter). I can see from the logs that the 'flush' for the transaction in question works correctly (but apparently no commit, which I know because the record is not in the DB afterwards).
>
> Any suggestions as to what I'm missing?
>
> Thanks!!!
> Jochen
>
> PS: I tried setting up my own transaction, but that fails miserably with an Exception (Transaction trx = session.beginTransaction();... trx.commit();)
>
> ================== Code which isn't committing (DevelopmentDBStartupServiceImp.java) ========
>
> public DevelopmentDBStartupServiceImpl(Logger logger, Session session,
> @Symbol(SymbolConstants.PRODUCTION_MODE) boolean isProductionMode) {
> this.logger = logger;
> this.session = session;
> this.isProductionMode = isProductionMode;
> }
>
> --- SNIP ---
>
> @CommitAfter
> private boolean initSchemaVersion ()
> {
>
> // ---- SNIP ----
>
> // we'll assume that it's a virgin DB
> SchemaVersion version = new SchemaVersion(SchemaVersion.MAJOR_VERSION, SchemaVersion.MINOR_VERSION);
> session.save(version);
> session.flush();
> return true;
> }
>
> =========== How it's called (excerpts from DevelopmentModule.java) =========
>
> public static void bind(ServiceBinder binder)
> {
> binder.bind(DevelopmentDBStartupService.class, DevelopmentDBStartupServiceImpl.class);
> }
>
> @Match("*DB*")
> public static void adviseTransactions(HibernateTransactionAdvisor advisor, MethodAdviceReceiver receiver)
> {
> advisor.addTransactionCommitAdvice(receiver);
> }
>
> @Startup
> public static void initDevelopmentDatabase (Logger logger, DevelopmentDBStartupService service)
> {
> logger.info("START Initializing development database.");
> service.init();
> logger.info("DONE initializing development database.");
> }
>
>
>
>
> ---
> Jochen Frey
> jochen@beckon.com
> +1.415.366.0450
> @jochen_frey
>
>
>
>
>
>
> ---
> jochen@jochenfrey.com
> +1.415.366.0450
> @jochen_frey
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org