Passing a SQLSession to a method

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

Passing a SQLSession to a method

rhummy
Hi,

I would like to know if there will be a problem if I pass a SQLSession
variable to a method. With all the warnings in the myBatis guide, i
would like to know if I expose myself to issue if I do that.

I have a method inside my bean :

public boolean save(SqlSession session) throws
org.postgresql.util.PSQLException{

}

Inside it, I do stuff using mappers.

Thank you for your answers.
Reply | Threaded
Open this post in threaded view
|

Re: Passing a SQLSession to a method

rhummy
Since Java will pass everything by value and I will have a second
reference to the SQLSession, will it be a problem ?

From the guide, we can read :
"Never keep references to a SqlSession instance in a static field or
even an instance field of a class. Never keep references to a
SqlSession in any sort of managed scope, such as HttpSession of of the
Servlet framework."
I think I do not understand well what this sentence want to explain.

Please, can someone tell me if I can pass a SQLSession to a method ?

Thank you.


On Oct 25, 6:45 pm, rhummy <[hidden email]> wrote:

> Hi,
>
> I would like to know if there will be a problem if I pass a SQLSession
> variable to a method. With all the warnings in the myBatis guide, i
> would like to know if I expose myself to issue if I do that.
>
> I have a method inside my bean :
>
> public boolean save(SqlSession session) throws
> org.postgresql.util.PSQLException{
>
> }
>
> Inside it, I do stuff using mappers.
>
> Thank you for your answers.
Reply | Threaded
Open this post in threaded view
|

Re: Passing a SQLSession to a method

François Schiettecatte
Yes, I think the key message is that a SqlSession instance is not re-entrant.

F.

On Oct 26, 2010, at 6:09 PM, rhummy wrote:

> Since Java will pass everything by value and I will have a second
> reference to the SQLSession, will it be a problem ?
>
> From the guide, we can read :
> "Never keep references to a SqlSession instance in a static field or
> even an instance field of a class. Never keep references to a
> SqlSession in any sort of managed scope, such as HttpSession of of the
> Servlet framework."
> I think I do not understand well what this sentence want to explain.
>
> Please, can someone tell me if I can pass a SQLSession to a method ?
>
> Thank you.
>
>
> On Oct 25, 6:45 pm, rhummy <[hidden email]> wrote:
>> Hi,
>>
>> I would like to know if there will be a problem if I pass a SQLSession
>> variable to a method. With all the warnings in the myBatis guide, i
>> would like to know if I expose myself to issue if I do that.
>>
>> I have a method inside my bean :
>>
>> public boolean save(SqlSession session) throws
>> org.postgresql.util.PSQLException{
>>
>> }
>>
>> Inside it, I do stuff using mappers.
>>
>> Thank you for your answers.

Reply | Threaded
Open this post in threaded view
|

RE: Passing a SQLSession to a method

Rick.Wellman
In reply to this post by rhummy
You can pass the SQLSession to a method, as long as the method does not do any of the things contained in the quote from the guide.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of rhummy
Sent: Tuesday, October 26, 2010 5:09 PM
To: mybatis-user
Subject: Re: Passing a SQLSession to a method

Since Java will pass everything by value and I will have a second
reference to the SQLSession, will it be a problem ?

From the guide, we can read :
"Never keep references to a SqlSession instance in a static field or
even an instance field of a class. Never keep references to a
SqlSession in any sort of managed scope, such as HttpSession of of the
Servlet framework."
I think I do not understand well what this sentence want to explain.

Please, can someone tell me if I can pass a SQLSession to a method ?

Thank you.


On Oct 25, 6:45 pm, rhummy <[hidden email]> wrote:

> Hi,
>
> I would like to know if there will be a problem if I pass a SQLSession
> variable to a method. With all the warnings in the myBatis guide, i
> would like to know if I expose myself to issue if I do that.
>
> I have a method inside my bean :
>
> public boolean save(SqlSession session) throws
> org.postgresql.util.PSQLException{
>
> }
>
> Inside it, I do stuff using mappers.
>
> Thank you for your answers.
Reply | Threaded
Open this post in threaded view
|

Re: Passing a SQLSession to a method

rhummy
Thank you, you two for your answers.

On Oct 26, 6:30 pm, Rick.Wellman <[hidden email]> wrote:

> You can pass the SQLSession to a method, as long as the method does not do any of the things contained in the quote from the guide.
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of rhummy
> Sent: Tuesday, October 26, 2010 5:09 PM
> To: mybatis-user
> Subject: Re: Passing a SQLSession to a method
>
> Since Java will pass everything by value and I will have a second
> reference to the SQLSession, will it be a problem ?
>
> From the guide, we can read :
> "Never keep references to a SqlSession instance in a static field or
> even an instance field of a class. Never keep references to a
> SqlSession in any sort of managed scope, such as HttpSession of of the
> Servlet framework."
> I think I do not understand well what this sentence want to explain.
>
> Please, can someone tell me if I can pass a SQLSession to a method ?
>
> Thank you.
>
> On Oct 25, 6:45 pm, rhummy <[hidden email]> wrote:
> > Hi,
>
> > I would like to know if there will be a problem if I pass a SQLSession
> > variable to a method. With all the warnings in the myBatis guide, i
> > would like to know if I expose myself to issue if I do that.
>
> > I have a method inside my bean :
>
> > public boolean save(SqlSession session) throws
> > org.postgresql.util.PSQLException{
>
> > }
>
> > Inside it, I do stuff using mappers.
>
> > Thank you for your answers.
>
>