Quantcast

Viewing transaction boundaries in log4j output

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Viewing transaction boundaries in log4j output

Jeff
This post was updated on .
Is there a way to turn on sql logging so that I'd be able to see the transaction boundaries that get added to my sql queries? In other words, most of my database operations are done in the service layer, so I'd expect to see 'start transaction' somewhere in the sql logs, but I'm not seeing that. I configured log4j logging to log the sql statements as shown below. Any help would be greatly appreciated.

<logger name="org.hibernate.SQL">
     <level value="trace"/>
</logger>

<logger name="org.hibernate.type">
     <level value="trace"/>
</logger>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
I also tried decompiling one of my service classes with JD-GUI. I was thinking I'd see a line of code in there somewhere referring to a transaction but I didn't see any such line. Does anyone know what I should expect to see when decompiling service classes in regards to transactions?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

basejump (Josh)
What is it you are after?
try turning on debug for org.springframework.transaction
Not sure where you got the xml that you sent as an example.
The transactions are done with AOP and not compiled into the  class.
Did you read the grails docs on Transactions. You should also read up on @Transactional in the Spring docs.

On Jun 27, 2012, at 4:38 PM, Jeff wrote:

> I also tried decompiling one of my service classes with JD-GUI. I was
> thinking I'd see a line of code in there somewhere referring to a
> transaction but I didn't see any such line. Does anyone know what I should
> expect to see when decompiling service classes in regards to transactions?
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Viewing-transaction-boundaries-in-log4j-output-tp4630729p4630741.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
Basejump,

I'll answer each of your questions in turn:

What is it you are after? The transactions aren't working in my service classes so I was hoping there would be a way to see the 'start transaction' statements in my sql logs.

Not sure where you got the xml that you sent as an example.  The xml was from the new book "Programming Grails" that Burt Beckwith is working on and it seems to work well in that it logs both the sql statements and the sql values (as opposed to just '?' for the sql values).

Did you read the grails docs on Transactions. You should also read up on @Transactional in the Spring docs.  Yes, I've been using both Grails and Spring for several years and have never encountered this issue with transactions.

It looks like none of the transactions are working in any of the services. The only thing I can think of is one of my plugins is causing a conflict.

As a quick test, I created a DummyService that has a single method that does 3 inserts into a table and then at the end of the method throws a RuntimeException and that isn't even rolling back the transaction so something is definitely amiss.

Has anyone else experienced anything like this?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

basejump (Josh)

On Jun 28, 2012, at 9:18 AM, Jeff wrote:

> The transactions aren't working in my service
> classes so I was hoping there would be a way to see the 'start transaction'
> statements in my sql logs.


You are not giving enough info for us to help. What do you mean by "aren't working"?
integration tests are transactional and should rollback at the end of the test.
turning on logging for debug for org.springframework.transaction should tell you what methods are advised.
what DB? if MySql are you running innodb?
if you create a simple app with a single service using the baked in H2 are you not seeing transactions?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
This post was updated on .
By "aren't working" I mean the inserts aren't rolling back after a RuntimeException is thrown. I copied my service code into a brand new Grails app and things worked fine, thus my thought is that it's a plugin that's causing the problem.

Running mysql. All tables are InnoDB.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
One thing of note is the app defines both a resources.groovy file and a resources.xml file. The resources.xml file has the following line it:

<tx:annotation-driven/>

I'm wondering if this may be the culprit? I tried commenting it out and running a grails clean but that didn't seem to help. I'm wondering if I should physically delete the projects directory in my .grails folder to completely remove any references to that line?

I'm clearly running out of ideas here.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

basejump (Josh)
All I can say is that your project sounds fairly convoluted. Not sure why you have both resources.groovy and resource.xml, perhaps there is a reason.
Your best bet is to try and reproduce the problem in a sample project that you can post to a jira or here.

On Jun 28, 2012, at 3:58 PM, Jeff wrote:

> One thing of note is the app defines both a resources.groovy file and a
> resources.xml file. The resources.xml file has the following line it:
>
> <tx:annotation-driven/>
>
> I'm wondering if this may be the culprit? I tried commenting it out and
> running a grails clean but that didn't seem to help. I'm wondering if I
> should physically delete the projects directory in my .grails folder to
> completely remove any references to that line?
>
> I'm clearly running out of ideas here.
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Viewing-transaction-boundaries-in-log4j-output-tp4630729p4630819.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

rlovtangen
On a general basis, there shouldn't be a problem having both resources.groovy and resources.xml.
Reason to have both could be when migrating an app to Grails, or if you just don't bother to figure out how to translate something you already know how to write to resources.groovy-style (and don't need the extra features resources.groovy gives you)

On Jun 28, 2012, at 11:19 PM, Josh (basejump) wrote:

> All I can say is that your project sounds fairly convoluted. Not sure why you have both resources.groovy and resource.xml, perhaps there is a reason.
> Your best bet is to try and reproduce the problem in a sample project that you can post to a jira or here.
>
> On Jun 28, 2012, at 3:58 PM, Jeff wrote:
>
>> One thing of note is the app defines both a resources.groovy file and a
>> resources.xml file. The resources.xml file has the following line it:
>>
>> <tx:annotation-driven/>
>>
>> I'm wondering if this may be the culprit? I tried commenting it out and
>> running a grails clean but that didn't seem to help. I'm wondering if I
>> should physically delete the projects directory in my .grails folder to
>> completely remove any references to that line?
>>
>> I'm clearly running out of ideas here.
>>
>> --
>> View this message in context: http://grails.1312388.n4.nabble.com/Viewing-transaction-boundaries-in-log4j-output-tp4630729p4630819.html
>> Sent from the Grails - user mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
In reply to this post by basejump (Josh)
I'll try reproducing. The interesting thing is that the log4j output looks the same in the sample project that works and in the project that doesn't work. In both cases, I see entries such as...

TRACE TransactionInterceptor - Getting transaction for [com.acme.DummyService.insertRows]
TRACE TransactionInterceptor - Completing transaction for [com.acme.DummyService.insertRows] after exception: com.acme.JukeboxException
TRACE RuleBasedTransactionAttribute - Applying rules to determine whether transaction should rollback on com.acme.JukeboxException
TRACE RuleBasedTransactionAttribute - Winning rollback rule is: null
TRACE RuleBasedTransactionAttribute - No relevant rollback rule found: applying default rules

So it appears that the method is getting advised correctly but the advice is just not being taken.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Viewing transaction boundaries in log4j output

Jeff
Something to note, if I wrap the inserts in a withTransaction closure and then call setRollbackOnly() when an exception is thrown, the inserts gets rolled back as expected.
Loading...