Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
questions about UnitOfWork.REQUEST and transactions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Day  
View profile  
 More options Aug 17 2010, 10:43 pm
From: Michael Day <blake...@gmail.com>
Date: Tue, 17 Aug 2010 19:43:59 -0700 (PDT)
Local: Tues, Aug 17 2010 10:43 pm
Subject: questions about UnitOfWork.REQUEST and transactions
Hi,

I'm hoping someone could shed some light on how warp-persist is
supposed to work. I'm using PersistenceFilter with UnitOfWork.REQUEST
and hibernate.  My changes are being persisted to the database even
when I have not specified @Transactional anywhere.  Is this supposed
to happen?

My unit tests have the opposite problem.  I use WorkManager to wrap my
tests in a UnitOfWork, and I specify @Transactional on both the test
method and the service method that I'm calling from the test.
Regardless, no transaction is started, and changes do not get
persisted.

I understand that Spring's OSIV keeps the FlushMode set to NEVER when
outside a transaction and temporarily sets it to AUTO during a
transaction.  Is warp supposed to do this?

Thanks,

Michael Day


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dhanji R. Prasanna  
View profile  
 More options Aug 20 2010, 9:52 am
From: "Dhanji R. Prasanna" <dha...@gmail.com>
Date: Fri, 20 Aug 2010 23:52:43 +1000
Local: Fri, Aug 20 2010 9:52 am
Subject: Re: questions about UnitOfWork.REQUEST and transactions

On Wed, Aug 18, 2010 at 12:43 PM, Michael Day <blake...@gmail.com> wrote:
> Hi,

> I'm hoping someone could shed some light on how warp-persist is
> supposed to work. I'm using PersistenceFilter with UnitOfWork.REQUEST
> and hibernate.  My changes are being persisted to the database even
> when I have not specified @Transactional anywhere.  Is this supposed
> to happen?

This will happen depending on your database. If the commit mode of the sql
connection is AUTO (MySQL) then yes an implicit transaction will be started.
Usually databases don't allow you to do anything (including reading) unless
you're inside a transaction so they will complain vociferously otherwise.

There is a lot of literature about why it doesn't make sense to read unless
you're inside a txn. I'll leave it to say it's not so much a WP thing as it
is a combination of database, hibernate and session settings.

> My unit tests have the opposite problem.  I use WorkManager to wrap my
> tests in a UnitOfWork, and I specify @Transactional on both the test
> method and the service method that I'm calling from the test.
> Regardless, no transaction is started, and changes do not get
> persisted.

> I understand that Spring's OSIV keeps the FlushMode set to NEVER when
> outside a transaction and temporarily sets it to AUTO during a
> transaction.  Is warp supposed to do this?

You can do this--but it's a hack to create read-only transactions. In
warp-persist (hibernate only) you can specify @Transactional(type=READ_ONLY)
or something similar which does roughly the same trick.

Dhanji.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Retzlaff  
View profile  
 More options Aug 20 2010, 10:13 am
From: Dan Retzlaff <dretzl...@gmail.com>
Date: Fri, 20 Aug 2010 07:13:12 -0700
Local: Fri, Aug 20 2010 10:13 am
Subject: Re: questions about UnitOfWork.REQUEST and transactions
Hi Michael,

I could have written the same questions two days ago, and even started
drafting the message to warp-core. Pardon some irrelevant details in
this message; my goal is partially to document the knowledge that
would have helped me. :)

First, it's important to differentiate session open/close from
transaction begin/end. The PersistenceFilter and WorkManager open and
close *sessions*. They should be used with Hibernate's
ManagedSessionContext (i.e.
hibernate.current_session_context_class=managed). The common
alternative, ThreadLocalSessionContext
(hibernate.current_session_context_class=thread) will automatically
create a session when SessionFactory.getCurrentSession() is called,
requires that a transaction is started, and automatically closes the
session when that transaction is ended. That is clearly not the
session lifecycle expected with UnitOfWork.REQUEST and
PersistenceFilter or WorkManager. If you want
ThreadLocalSessionContext, you should be using UnitOfWork.TRANSACTION
without PersistenceFilter or WorkManager.

As for *transaction* management, that's where the PersistenceService
and those @Transactional annotations come in. Note that Hibernate
itself does not require you to put session.beginTransaction() and
session.endTransaction() around your operations. If you omit these,
then Dhanji's comment applies: with MySQL, an implicit transaction
gets used for each operation, and the operations get sent on flush.

I can't explain the difference in behavior between your unit tests and
servlet, except to suggest that some Hibernate or database
configuration is different (flush mode?). After all, the
PersistenceFilter just uses WorkManager behind the scenes. Also, check
that you're instantiating the @Transaction annotated classes through
Guice so the PersistenceService's interceptor can take effect.

Hope that helps.

Dan

On Aug 20, 2010 6:21 AM, "Michael Day" <blake...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »