Return-Path: X-Original-To: apmail-incubator-deltaspike-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-deltaspike-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2DBB3E510 for ; Tue, 12 Mar 2013 22:03:18 +0000 (UTC) Received: (qmail 42889 invoked by uid 500); 12 Mar 2013 22:03:16 -0000 Delivered-To: apmail-incubator-deltaspike-dev-archive@incubator.apache.org Received: (qmail 42860 invoked by uid 500); 12 Mar 2013 22:03:16 -0000 Mailing-List: contact deltaspike-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltaspike-dev@incubator.apache.org Delivered-To: mailing list deltaspike-dev@incubator.apache.org Received: (qmail 42806 invoked by uid 99); 12 Mar 2013 22:03:16 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Mar 2013 22:03:16 +0000 Date: Tue, 12 Mar 2013 22:03:16 +0000 (UTC) From: "Gerhard Petracek (JIRA)" To: deltaspike-dev@incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DELTASPIKE-319) JPA module fails to start transaction if a qualifier is not used under certain conditions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DELTASPIKE-319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13600540#comment-13600540 ] Gerhard Petracek commented on DELTASPIKE-319: --------------------------------------------- then we have to change the title of this issue or create a new one. > JPA module fails to start transaction if a qualifier is not used under certain conditions > ----------------------------------------------------------------------------------------- > > Key: DELTASPIKE-319 > URL: https://issues.apache.org/jira/browse/DELTASPIKE-319 > Project: DeltaSpike > Issue Type: Bug > Components: JPA-Module > Affects Versions: 0.3-incubating > Reporter: Gabriel Sosa > Fix For: 0.3-incubating > > > I stumbled upon this by coincidence and it gave me major headaches as it was a bit hard to realize why and where it happened. > I started using Picketlink 3.0.0.alpha1 and it provides an IdentityManager that handles precisely that. Now the problem is that after looking at Deltaspike's source code for a while, it does the following: > On a method annotated with @Transactional: > @Transactional > public void myTransactionalMethod() { > identityManager.createUser("foo"); > } > As far as I understand, the module needs to know which EntityManager should execute within a transaction, so basically it first scans the annotation (@Transactional) looking for qualifiers, if it finds a qualifier, it performs some checks then starts a transaction. If the annotation does not have a qualifier, then it takes the class that has the @Transactional method, and starts scanning its fields to find the EntityManager used and get its qualifier, if it finds an EntityManager it will take its qualifier. This is expected behaviour but the problem arises when the class calling the transactional method does not have an EntityManager because it doesn't need one. > Say in this scenario: > Public class IdentityManager { > protected EntityManager doBlackMagicToGetAnEntityManager() { > //find an entitymanager..... > } > public void createUser(String username) { > doBlackMagicToGetAnEntityManager().persist(new User(username)); > } > } > @Named > @RequestScoped > public class VictimBean { > @Inject > IdentityManager identityManager; > protected String name; > @Transactional > public void doCreate() { > identityManager.createUser(this.name); > } > } > Deltaspike will look for a qualifier, won't find it in Transactional. Therefore, it will scan VictimBean looking for a qualifier for an EntityManager, it won't find one, it won't open a transaction, the application throws an exception because createUser(..) modifies the database and is required to be executed within a transaction. > Is this behavior expected? Because it is very unpredictable. I didn't really see it coming. > PicketLink requires me to use a @PicketLink qualifier in a field producer so it can get an entity manager but I have this in my Resources bean, which doesn't directly participate in that code. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira