Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

bhushanngage
  Hello everyone, I am kind of new to BTM. I have seen and implemented demo examples on Bitronix. Its awesome.
  My question is that, Is it absolutely necessary to use sf.getCurrentSession instead of sf.openSession() and why ? because my example in tomcat + hibernate without spring is executing fine with openSession but not with getCurrentSession. Getting error like 'Unable to locate current JTA transaction'.
  Any help is appreciated.
Thanks in advance.
Bhushan Patil
Bhushan Patil
Software Engineer
Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

Ludovic Orban-2
Yes, you must always use getCurrentSession() otherwise you're simply
bypassing JTA and end up using the BTM connection pool in non-XA mode.

Hibernate is meant to manage data, BTM is meant to manage
transactions. Those are two distinct concepts that unfortunately
usually are mistakenly mixed together. You should use BTM to start and
commit/rollback your transactions and Hibernate to read and modify
your data. When properly configured, Hibernate will communicate with
BTM and data will automatically be flushed on commit.

If you get a 'Unable to locate current JTA transaction' error, this
almost certainly is because you did not start a JTA transaction before
using Hibernate. Have a look at this page to get an idea of what a
proper setup looks like:
http://docs.codehaus.org/display/BTM/Hibernate2x
This is a bit outdated, but the general idea is still valid: do not
use the Hibernate API to manage your transactions.




On Sun, Dec 14, 2014 at 8:06 PM, bhushanngage <[hidden email]> wrote:

>   Hello everyone, I am kind of new to BTM. I have seen and implemented demo
> examples on Bitronix. Its awesome.
>   My question is that, Is it absolutely necessary to use
> sf.getCurrentSession instead of sf.openSession() and why ? because my
> example in tomcat + hibernate without spring is executing fine with
> openSession but not with getCurrentSession. Getting error like '*Unable to
> locate current JTA transaction*'.
>   Any help is appreciated.
> Thanks in advance.
> Bhushan Patil
>
>
>
> --
> View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Why-do-we-need-to-open-sf-getCurrentSession-instead-of-sf-openSession-tp1676.html
> Sent from the Bitronix Transaction Manager 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
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

bhushanngage
This post was updated on .
    Thanks Ludovic for your valuable help.
I am using BTM 3.0.0 Snapshot with database name : Microsoft SQL Server version : 11.00.2100 and driver name : Microsoft SQL Server JDBC Driver 3.0    version : 3.0.1301.101.
    Sometimes my application gets hung. Only after restart sql server, I could re-connect to DB. I am trying figure out cause. For that purpose, I wanted to examine logs. There are two log files, btm1.tlog and btm2.tlog. But when I tried to open it in vim, only few strange character are there.
    How can I run BTM in debug mode? I have slf4j-api-1.6.1.jar and slf4j-jdk14-1.6.1.jar in my classpath.
    Do I need to do changes in SQL server in order to start debug logging there also ?
Any help is appreciated.
Bhushan Patil
Software Engineer
Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

Ludovic Orban-2
The *.tlog files are what make the transactional journal. It's not
meant to be human readable, it's binary data BTM requires internally.
And there shouldn't be any need to touch sql server either.

BTM can output a ton of very precise debug logs when your logger is
configured to do just that. There's a quick summary of what's what at
http://docs.codehaus.org/display/BTM/DebugLogging2x but you should
refer to your favorite logger implementation's documentation to figure
out how to turn on debug logging.

On Thu, Dec 18, 2014 at 1:19 PM, bhushanngage <[hidden email]> wrote:

>     Thanks Ludovic for your valuable help.
> I am using BTM 3.0.0 Snapshot with database name : Microsoft SQL Server
> version : 11.00.2100 and driver name : Microsoft SQL Server JDBC Driver 3.0
> version : 3.0.1301.101.
>     Sometimes my application gets hung. Only after restart sql server, I
> could re-connect to DB. I am trying figure out cause. For that purpose, I
> wanted to examine logs. There are two log files, *btm1.tlog* and
> *btm2.tlog*. But when I tried to open it in vim, only few strange character
> are there.
>     How can I run BTM in debug mode? I have slf4j-api-1.6.1.jar and
> slf4j-jdk14-1.6.1.jar in my classpath.
>     Do I need to do changes in SQL server in order to start debug logging
> there also ?
>
>
>
> -----
> Bhushan Patil
> Software Engineer
> --
> View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Why-do-we-need-to-open-sf-getCurrentSession-instead-of-sf-openSession-tp1676p1678.html
> Sent from the Bitronix Transaction Manager 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
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

Brett Wooldridge-2
In reply to this post by bhushanngage
Bhushan, I suspect you may have a code path that is not releasing (closing) a connection from the pool.  Eventually this will consume all connections in the pool and cause your application to hang on getConnection().  I suggest taking a thread dump when the process is hung as a starting place for troubleshooting.

Brett


On Thu, Dec 18, 2014 at 9:19 PM, bhushanngage <[hidden email]> wrote:
    Thanks Ludovic for your valuable help.
I am using BTM 3.0.0 Snapshot with database name : Microsoft SQL Server
version : 11.00.2100 and driver name : Microsoft SQL Server JDBC Driver 3.0
version : 3.0.1301.101.
    Sometimes my application gets hung. Only after restart sql server, I
could re-connect to DB. I am trying figure out cause. For that purpose, I
wanted to examine logs. There are two log files, *btm1.tlog* and
*btm2.tlog*. But when I tried to open it in vim, only few strange character
are there.
    How can I run BTM in debug mode? I have slf4j-api-1.6.1.jar and
slf4j-jdk14-1.6.1.jar in my classpath.
    Do I need to do changes in SQL server in order to start debug logging
there also ?



-----
Bhushan Patil
Software Engineer
--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Why-do-we-need-to-open-sf-getCurrentSession-instead-of-sf-openSession-tp1676p1678.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

bhushanngage
Hello Brett and Ludovic.
Frustrating thing about this issue is that its hard to reproduce. But it happened once again. My application got hanged. So when I tried to restart it I am getting this exception. If I restart my ms-sql server then this error won't show up. Any idea why this is happening ? Any help is appreciated.

com.paramatrix.common.exceptions.InitFailed: cannot create JDBC datasource named RIL11RRJ
        at com.paramatrix.pace.orm.ORMServiceFactory.<init>(ORMServiceFactory.java:178)
        at com.paramatrix.pace.core.RequestHandler.<init>(RequestHandler.java:301)
        at com.paramatrix.pace.core.Controller.<init>(Controller.java:570)
        at com.paramatrix.pace.core.Controller.init(Controller.java:118)
        at com.paramatrix.pace.StartupServlet.init(StartupServlet.java:69)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1213)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named RIL11RRJ
        at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:76)
        at com.paramatrix.pace.orm.BitronixDataSourceFactory.init(BitronixDataSourceFactory.java:44)
        at com.paramatrix.pace.orm.ORMServiceFactory.<init>(ORMServiceFactory.java:159)
        ... 21 more
Caused by: bitronix.tm.recovery.RecoveryException: failed recovering resource RIL11RRJ
        at bitronix.tm.recovery.IncrementalRecoverer.recover(IncrementalRecoverer.java:104)
        at bitronix.tm.resource.ResourceRegistrar.register(ResourceRegistrar.java:78)
        at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:88)
        at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:72)
        ... 23 more
Caused by: javax.transaction.xa.XAException: The function RECOVER: has failed. The status is: -3. Error: "*** SQLJDBC_XA DTC_ERROR Context: xa_recover, state=1, StatusCode:-3 (0xFFFFFFFD) ***"
        at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:545)
        at com.microsoft.sqlserver.jdbc.SQLServerXAResource.recover(SQLServerXAResource.java:723)
        at bitronix.tm.recovery.RecoveryHelper.recover(RecoveryHelper.java:103)
        at bitronix.tm.recovery.RecoveryHelper.recover(RecoveryHelper.java:61)
        at bitronix.tm.recovery.IncrementalRecoverer.recover(IncrementalRecoverer.java:64)
Bhushan Patil
Software Engineer
Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to open sf.getCurrentSession instead of sf.openSession() ?

Ludovic Orban-2
Google the reported error message "*** SQLJDBC_XA DTC_ERROR Context:
xa_recover, state=1, StatusCode:-3 (0xFFFFFFFD) ***" and you'll notice
there are quite a few persons with very similar or exactly the same
error, all reported as happening with various transaction managers.

This IMHO clearly indicates a bug in the JDBC driver or SQL server.
You should ask for microsoft's help as they probably are the only ones
who can come up with an explanation and a fix.

On Sat, Jan 17, 2015 at 12:33 PM, bhushanngage
<[hidden email]> wrote:

> Hello Brett and Ludovic.
> Frustrating thing about this issue is that its hard to reproduce. But it
> happened once again. My application got hanged. So when I tried to restart
> it I am getting this exception. If I restart my ms-sql server then this
> error won't show up. Any idea why this is happening ? Any help is
> appreciated.
>
> com.paramatrix.common.exceptions.InitFailed: cannot create JDBC datasource
> named RIL11RRJ
>         at
> com.paramatrix.pace.orm.ORMServiceFactory.<init>(ORMServiceFactory.java:178)
>         at com.paramatrix.pace.core.RequestHandler.<init>(RequestHandler.java:301)
>         at com.paramatrix.pace.core.Controller.<init>(Controller.java:570)
>         at com.paramatrix.pace.core.Controller.init(Controller.java:118)
>         at com.paramatrix.pace.StartupServlet.init(StartupServlet.java:69)
>         at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1213)
>         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
>         at
> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
>         at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
>         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
>         at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
>         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
>         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
>         at org.apache.catalina.core.StandardService.start(StandardService.java:525)
>         at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
>         at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:606)
>         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
>         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
> Caused by: bitronix.tm.resource.ResourceConfigurationException: cannot
> create JDBC datasource named RIL11RRJ
>         at
> bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:76)
>         at
> com.paramatrix.pace.orm.BitronixDataSourceFactory.init(BitronixDataSourceFactory.java:44)
>         at
> com.paramatrix.pace.orm.ORMServiceFactory.<init>(ORMServiceFactory.java:159)
>         ... 21 more
> Caused by: bitronix.tm.recovery.RecoveryException: failed recovering
> resource RIL11RRJ
>         at
> bitronix.tm.recovery.IncrementalRecoverer.recover(IncrementalRecoverer.java:104)
>         at
> bitronix.tm.resource.ResourceRegistrar.register(ResourceRegistrar.java:78)
>         at
> bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:88)
>         at
> bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:72)
>         ... 23 more
> Caused by: javax.transaction.xa.XAException: The function RECOVER: has
> failed. The status is: -3. Error: "*** SQLJDBC_XA DTC_ERROR Context:
> xa_recover, state=1, StatusCode:-3 (0xFFFFFFFD) ***"
>         at
> com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:545)
>         at
> com.microsoft.sqlserver.jdbc.SQLServerXAResource.recover(SQLServerXAResource.java:723)
>         at bitronix.tm.recovery.RecoveryHelper.recover(RecoveryHelper.java:103)
>         at bitronix.tm.recovery.RecoveryHelper.recover(RecoveryHelper.java:61)
>         at
> bitronix.tm.recovery.IncrementalRecoverer.recover(IncrementalRecoverer.java:64)
>
>
>
> -----
> Bhushan Patil
> Software Engineer
> --
> View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Why-do-we-need-to-open-sf-getCurrentSession-instead-of-sf-openSession-tp1676p1685.html
> Sent from the Bitronix Transaction Manager 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