Sequence of statements' executing is not right in the non-transaction scope

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

Sequence of statements' executing is not right in the non-transaction scope

Daniel.Sun
Hi all,

I found sequence of statement's executing is not right in the non-transaction scope.
Let's have a look at the following example:

domain class:
Book


controller:
class BookController {
    ...
    def test = {
    System.out.println("Begin")
    def book = Book.get(3)
    System.out.println(book)
    System.out.println("1")
    book.delete()
    System.out.println("2")
    def books = Book.list()
    System.out.println("3")
    System.out.println(books)
    render "END"
    }
}

I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
After I execute test closure via http://localhost:8080/dbtest/book/test ,
the output written to console is(sequence of delete and list is not right, they are reversed, the sequence are right if these statements are put in service whose transactional property value is true):

Begin
Hibernate:
    select
        book0_.id as id1_0_,
        book0_.version as version1_0_
    from
        book book0_
    where
        book0_.id=?
Book : 3
1
2
Hibernate:
    select
        this_.id as id1_0_,
        this_.version as version1_0_
    from
        book this_
3
[Book : 3, Book : 4]
Hibernate:
    delete
    from
        book
    where
        id=?
        and version=?
Hibernate:
    select
        top ? this_.id as id1_0_,
        this_.version as version1_0_
    from
        book this_
View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can severely impair performance
Hibernate:
    select
        count(*) as y0_
    from
        book this_


Any help is appreciated.

Thanks,
Daniel.Sun
Reply | Threaded
Open this post in threaded view
|

Re: Sequence of statements' executing is not right in the non-transaction scope

Daniel.Sun
Is it a critical bug?
Any idea?

Daniel.Sun
Daniel.Sun wrote
Hi all,

I found sequence of statement's executing is not right in the non-transaction scope.
Let's have a look at the following example:

domain class:
Book


controller:
class BookController {
    ...
    def test = {
    System.out.println("Begin")
    def book = Book.get(3)
    System.out.println(book)
    System.out.println("1")
    book.delete()
    System.out.println("2")
    def books = Book.list()
    System.out.println("3")
    System.out.println(books)
    render "END"
    }
}

I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
After I execute test closure via http://localhost:8080/dbtest/book/test ,
the output written to console is(sequence of delete and list is not right, they are reversed, the sequence are right if these statements are put in service whose transactional property value is true):

Begin
Hibernate:
    select
        book0_.id as id1_0_,
        book0_.version as version1_0_
    from
        book book0_
    where
        book0_.id=?
Book : 3
1
2
Hibernate:
    select
        this_.id as id1_0_,
        this_.version as version1_0_
    from
        book this_
3
[Book : 3, Book : 4]
Hibernate:
    delete
    from
        book
    where
        id=?
        and version=?
Hibernate:
    select
        top ? this_.id as id1_0_,
        this_.version as version1_0_
    from
        book this_
View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can severely impair performance
Hibernate:
    select
        count(*) as y0_
    from
        book this_


Any help is appreciated.

Thanks,
Daniel.Sun
Reply | Threaded
Open this post in threaded view
|

Re: Sequence of statements' executing is not right in the non-transaction scope

graemer
Its not a bug, its the way hibernate works. It uses a session based
approach so updates don't happen immediately but are batched up until
the end to reduce the number of SQL calls performed. Hibernate is
developed this way because it scales better.

Cheers

On 6/7/07, Daniel.Sun <[hidden email]> wrote:

>
> Is it a critical bug?
> Any idea?
>
> Daniel.Sun
>
> Daniel.Sun wrote:
> >
> > Hi all,
> >
> > I found sequence of statement's executing is not right in the
> > non-transaction scope.
> > Let's have a look at the following example:
> >
> > domain class:
> > Book
> >
> >
> > controller:
> > class BookController {
> >     ...
> >     def test = {
> >       System.out.println("Begin")
> >       def book = Book.get(3)
> >       System.out.println(book)
> >       System.out.println("1")
> >       book.delete()
> >       System.out.println("2")
> >       def books = Book.list()
> >       System.out.println("3")
> >       System.out.println(books)
> >       render "END"
> >     }
> > }
> >
> > I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
> > After I execute test closure via http://localhost:8080/dbtest/book/test ,
> > the output written to console is(sequence of delete and list is not right,
> > they are reversed, the sequence are right if these statements are put in
> > service whose transactional property value is true):
> >
> > Begin
> > Hibernate:
> >     select
> >         book0_.id as id1_0_,
> >         book0_.version as version1_0_
> >     from
> >         book book0_
> >     where
> >         book0_.id=?
> > Book : 3
> > 1
> > 2
> > Hibernate:
> >     select
> >         this_.id as id1_0_,
> >         this_.version as version1_0_
> >     from
> >         book this_
> > 3
> > [Book : 3, Book : 4]
> > Hibernate:
> >     delete
> >     from
> >         book
> >     where
> >         id=?
> >         and version=?
> > Hibernate:
> >     select
> >         top ? this_.id as id1_0_,
> >         this_.version as version1_0_
> >     from
> >         book this_
> > View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can
> > severely impair performance
> > Hibernate:
> >     select
> >         count(*) as y0_
> >     from
> >         book this_
> >
> >
> > Any help is appreciated.
> >
> > Thanks,
> > Daniel.Sun
> >
>
> --
> View this message in context: http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11003746
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Sequence of statements' executing is not right in the non-transaction scope

Daniel.Sun
Hi graemer,

I have another question:
The sequence of statements' executing in the non-transaction is different from that in the transaction.
Could you please tell me why?

BTW, The sequence of statements' executing in the non-transaction is not what I expected, because it change the business logic.

Thanks in advance.

Daniel.Sun
graemer wrote
Its not a bug, its the way hibernate works. It uses a session based
approach so updates don't happen immediately but are batched up until
the end to reduce the number of SQL calls performed. Hibernate is
developed this way because it scales better.

Cheers

On 6/7/07, Daniel.Sun <realbluesun@hotmail.com> wrote:
>
> Is it a critical bug?
> Any idea?
>
> Daniel.Sun
>
> Daniel.Sun wrote:
> >
> > Hi all,
> >
> > I found sequence of statement's executing is not right in the
> > non-transaction scope.
> > Let's have a look at the following example:
> >
> > domain class:
> > Book
> >
> >
> > controller:
> > class BookController {
> >     ...
> >     def test = {
> >       System.out.println("Begin")
> >       def book = Book.get(3)
> >       System.out.println(book)
> >       System.out.println("1")
> >       book.delete()
> >       System.out.println("2")
> >       def books = Book.list()
> >       System.out.println("3")
> >       System.out.println(books)
> >       render "END"
> >     }
> > }
> >
> > I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
> > After I execute test closure via http://localhost:8080/dbtest/book/test ,
> > the output written to console is(sequence of delete and list is not right,
> > they are reversed, the sequence are right if these statements are put in
> > service whose transactional property value is true):
> >
> > Begin
> > Hibernate:
> >     select
> >         book0_.id as id1_0_,
> >         book0_.version as version1_0_
> >     from
> >         book book0_
> >     where
> >         book0_.id=?
> > Book : 3
> > 1
> > 2
> > Hibernate:
> >     select
> >         this_.id as id1_0_,
> >         this_.version as version1_0_
> >     from
> >         book this_
> > 3
> > [Book : 3, Book : 4]
> > Hibernate:
> >     delete
> >     from
> >         book
> >     where
> >         id=?
> >         and version=?
> > Hibernate:
> >     select
> >         top ? this_.id as id1_0_,
> >         this_.version as version1_0_
> >     from
> >         book this_
> > View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can
> > severely impair performance
> > Hibernate:
> >     select
> >         count(*) as y0_
> >     from
> >         book this_
> >
> >
> > Any help is appreciated.
> >
> > Thanks,
> > Daniel.Sun
> >
>
> --
> View this message in context: http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11003746
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

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

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Sequence of statements' executing is not right in the non-transaction scope

graemer
Its different because in a transcational state the transaction is
committed after the method completes in a service. Committing the
transaction automatically flushes the session, whilst in
non-transactional mode the session won't be flushed until after the
action is completed

Cheers

On 6/7/07, Daniel.Sun <[hidden email]> wrote:

>
> Hi graemer,
>
> I have another question:
> The sequence of statements' executing in the non-transaction is different
> from that in the transaction.
> Could you please tell me why?
>
> BTW, The sequence of statements' executing in the non-transaction is not
> what I expected, because it change the business logic.
>
> Thanks in advance.
>
> Daniel.Sun
>
> graemer wrote:
> >
> > Its not a bug, its the way hibernate works. It uses a session based
> > approach so updates don't happen immediately but are batched up until
> > the end to reduce the number of SQL calls performed. Hibernate is
> > developed this way because it scales better.
> >
> > Cheers
> >
> > On 6/7/07, Daniel.Sun <[hidden email]> wrote:
> >>
> >> Is it a critical bug?
> >> Any idea?
> >>
> >> Daniel.Sun
> >>
> >> Daniel.Sun wrote:
> >> >
> >> > Hi all,
> >> >
> >> > I found sequence of statement's executing is not right in the
> >> > non-transaction scope.
> >> > Let's have a look at the following example:
> >> >
> >> > domain class:
> >> > Book
> >> >
> >> >
> >> > controller:
> >> > class BookController {
> >> >     ...
> >> >     def test = {
> >> >       System.out.println("Begin")
> >> >       def book = Book.get(3)
> >> >       System.out.println(book)
> >> >       System.out.println("1")
> >> >       book.delete()
> >> >       System.out.println("2")
> >> >       def books = Book.list()
> >> >       System.out.println("3")
> >> >       System.out.println(books)
> >> >       render "END"
> >> >     }
> >> > }
> >> >
> >> > I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
> >> > After I execute test closure via http://localhost:8080/dbtest/book/test
> >> ,
> >> > the output written to console is(sequence of delete and list is not
> >> right,
> >> > they are reversed, the sequence are right if these statements are put
> >> in
> >> > service whose transactional property value is true):
> >> >
> >> > Begin
> >> > Hibernate:
> >> >     select
> >> >         book0_.id as id1_0_,
> >> >         book0_.version as version1_0_
> >> >     from
> >> >         book book0_
> >> >     where
> >> >         book0_.id=?
> >> > Book : 3
> >> > 1
> >> > 2
> >> > Hibernate:
> >> >     select
> >> >         this_.id as id1_0_,
> >> >         this_.version as version1_0_
> >> >     from
> >> >         book this_
> >> > 3
> >> > [Book : 3, Book : 4]
> >> > Hibernate:
> >> >     delete
> >> >     from
> >> >         book
> >> >     where
> >> >         id=?
> >> >         and version=?
> >> > Hibernate:
> >> >     select
> >> >         top ? this_.id as id1_0_,
> >> >         this_.version as version1_0_
> >> >     from
> >> >         book this_
> >> > View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can
> >> > severely impair performance
> >> > Hibernate:
> >> >     select
> >> >         count(*) as y0_
> >> >     from
> >> >         book this_
> >> >
> >> >
> >> > Any help is appreciated.
> >> >
> >> > Thanks,
> >> > Daniel.Sun
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11003746
> >> Sent from the grails - user mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe from this list please visit:
> >>
> >>     http://xircles.codehaus.org/manage_email
> >>
> >>
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11005047
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Sequence of statements' executing is not right in the non-transaction scope

Daniel.Sun
graemer,

Thanks for your patient reply :)

The last question:
Are these actions such as list, update and delete in controllers managed by Spring's transaction manager or something like that ?

Thanks,
Daniel.Sun
graemer wrote
Its different because in a transcational state the transaction is
committed after the method completes in a service. Committing the
transaction automatically flushes the session, whilst in
non-transactional mode the session won't be flushed until after the
action is completed

Cheers

On 6/7/07, Daniel.Sun <realbluesun@hotmail.com> wrote:
>
> Hi graemer,
>
> I have another question:
> The sequence of statements' executing in the non-transaction is different
> from that in the transaction.
> Could you please tell me why?
>
> BTW, The sequence of statements' executing in the non-transaction is not
> what I expected, because it change the business logic.
>
> Thanks in advance.
>
> Daniel.Sun
>
> graemer wrote:
> >
> > Its not a bug, its the way hibernate works. It uses a session based
> > approach so updates don't happen immediately but are batched up until
> > the end to reduce the number of SQL calls performed. Hibernate is
> > developed this way because it scales better.
> >
> > Cheers
> >
> > On 6/7/07, Daniel.Sun <realbluesun@hotmail.com> wrote:
> >>
> >> Is it a critical bug?
> >> Any idea?
> >>
> >> Daniel.Sun
> >>
> >> Daniel.Sun wrote:
> >> >
> >> > Hi all,
> >> >
> >> > I found sequence of statement's executing is not right in the
> >> > non-transaction scope.
> >> > Let's have a look at the following example:
> >> >
> >> > domain class:
> >> > Book
> >> >
> >> >
> >> > controller:
> >> > class BookController {
> >> >     ...
> >> >     def test = {
> >> >       System.out.println("Begin")
> >> >       def book = Book.get(3)
> >> >       System.out.println(book)
> >> >       System.out.println("1")
> >> >       book.delete()
> >> >       System.out.println("2")
> >> >       def books = Book.list()
> >> >       System.out.println("3")
> >> >       System.out.println(books)
> >> >       render "END"
> >> >     }
> >> > }
> >> >
> >> > I have 2 Book instance stored in HSQLDB: Book : 3, Book : 4
> >> > After I execute test closure via http://localhost:8080/dbtest/book/test
> >> ,
> >> > the output written to console is(sequence of delete and list is not
> >> right,
> >> > they are reversed, the sequence are right if these statements are put
> >> in
> >> > service whose transactional property value is true):
> >> >
> >> > Begin
> >> > Hibernate:
> >> >     select
> >> >         book0_.id as id1_0_,
> >> >         book0_.version as version1_0_
> >> >     from
> >> >         book book0_
> >> >     where
> >> >         book0_.id=?
> >> > Book : 3
> >> > 1
> >> > 2
> >> > Hibernate:
> >> >     select
> >> >         this_.id as id1_0_,
> >> >         this_.version as version1_0_
> >> >     from
> >> >         book this_
> >> > 3
> >> > [Book : 3, Book : 4]
> >> > Hibernate:
> >> >     delete
> >> >     from
> >> >         book
> >> >     where
> >> >         id=?
> >> >         and version=?
> >> > Hibernate:
> >> >     select
> >> >         top ? this_.id as id1_0_,
> >> >         this_.version as version1_0_
> >> >     from
> >> >         book this_
> >> > View caching is SWITCHED OFF -- DEVELOPMENT SETTING ONLY: This can
> >> > severely impair performance
> >> > Hibernate:
> >> >     select
> >> >         count(*) as y0_
> >> >     from
> >> >         book this_
> >> >
> >> >
> >> > Any help is appreciated.
> >> >
> >> > Thanks,
> >> > Daniel.Sun
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11003746
> >> Sent from the grails - user mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe from this list please visit:
> >>
> >>     http://xircles.codehaus.org/manage_email
> >>
> >>
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Sequence-of-statements%27-executing-is-not-right-in-the-non-transaction-scope-tf3822713.html#a11005047
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

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

    http://xircles.codehaus.org/manage_email