Return-Path: X-Original-To: apmail-deltaspike-users-archive@www.apache.org Delivered-To: apmail-deltaspike-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 64E3417580 for ; Sat, 19 Sep 2015 20:25:51 +0000 (UTC) Received: (qmail 56768 invoked by uid 500); 19 Sep 2015 20:25:51 -0000 Delivered-To: apmail-deltaspike-users-archive@deltaspike.apache.org Received: (qmail 56730 invoked by uid 500); 19 Sep 2015 20:25:51 -0000 Mailing-List: contact users-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@deltaspike.apache.org Delivered-To: mailing list users@deltaspike.apache.org Received: (qmail 56715 invoked by uid 99); 19 Sep 2015 20:25:50 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Sep 2015 20:25:50 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 85CD918034C for ; Sat, 19 Sep 2015 20:25:50 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Ik1zY52TL2-m for ; Sat, 19 Sep 2015 20:25:42 +0000 (UTC) Received: from mail-ob0-f169.google.com (mail-ob0-f169.google.com [209.85.214.169]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 6809320F4B for ; Sat, 19 Sep 2015 20:25:42 +0000 (UTC) Received: by obbmp4 with SMTP id mp4so24927459obb.3 for ; Sat, 19 Sep 2015 13:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Y2EVtc/8WXr82N+BFnKR2TaQRI5BpZyxebS+3cV+u78=; b=oITE5GSjbeY/hbdprGOoE+NKTf8WEneeq868etfyvGCV022f/M6QyCEwIstWsoTIea GE987pHZ1nVHdDcQgfMZlMEUE8h9im9AUURCYdPRY2Q7ASaQem5TSy8yPPkxAr3j6LbH 54+fO+128wFETydbb7W/A77eFq9u8LnVPUaLUCbVzIGFAnB/VAeWNv9IQ4RAqrYHDsWe ZA1YXVlbvrE2Tv/sURITYSdnWLODuSeUgiqpgqkOxOnbvUsyY1XHHEVBSAkZcRWU+KaL feRSBGpYig8yvZSWOZFNTUbkwPrPaa3ni300KsgSZXRQF+3htJ3pFWsba+7OV5+lUMcH BeTw== X-Received: by 10.182.158.231 with SMTP id wx7mr7293720obb.53.1442694335647; Sat, 19 Sep 2015 13:25:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.84.196 with HTTP; Sat, 19 Sep 2015 13:25:16 -0700 (PDT) In-Reply-To: References: From: Gerhard Petracek Date: Sat, 19 Sep 2015 22:25:16 +0200 Message-ID: Subject: Re: Exception "Transaction not active" inside my own interceptor combined with @Transactional To: users@deltaspike.apache.org Content-Type: multipart/alternative; boundary=089e013d0a4c6556f405201f7302 --089e013d0a4c6556f405201f7302 Content-Type: text/plain; charset=UTF-8 hi greg, #1 please have a look at e.g. [1] and [2] to see a valid (and even simpler) way to implement a cdi-interceptor (the source-code of ds itself is also a nice reference to see valid usages of the cdi-api) #2 check if your stereotype-annotation is correct (you can compare it e.g. with [3]). #3 use e.g. @Priority(Interceptor.Priority.APPLICATION) for your interceptors (per default ds-interceptors get called before interceptors with that priority, but you could even change that via config.) fyi (since you are using weld anyway): you can have a look at their documentation. it's quite detailed and nice to read. regards, gerhard [1] https://github.com/CDIatWork/IdeaFork/blob/master/ideafork_core/src/main/java/at/irian/cdiatwork/ideafork/core/impl/monitoring/Monitored.java [2] https://github.com/CDIatWork/IdeaFork/blob/master/ideafork_core/src/main/java/at/irian/cdiatwork/ideafork/core/impl/monitoring/MonitoredInterceptor.java [3] https://github.com/CDIatWork/IdeaFork/blob/master/ideafork_core/src/main/java/at/irian/cdiatwork/ideafork/core/impl/repository/Repository.java http://www.irian.at Your JavaEE powerhouse - JavaEE Consulting, Development and Courses in English and German Professional Support for Apache MyFaces, DeltaSpike and OpenWebBeans 2015-09-19 19:35 GMT+02:00 Grzesiek : > Hi Gerhard, thanks for answering. Nice to see that somebody cares. > > your code isn't valid with cdi. > > > > I'm surprised. Why? Could you give me a reason? > > I've tried both of your hints also. But still no luck. > > ... just create a cdi-stereotype annotation (e.g. @Service) and annotate > > that one with both interceptor-annotations. > > > > // btw. to be honest, I've already created this stereotype annotation, > exactly with name "@Service" ;-) > > > I guess my whole problem is about the order of the interceptors. My custom > *@DetectIntegrityConstraintViolation* is processed first, before > *@Transactional* - thus exception during execution of the former > interceptor. If yes how to solve this? Any other clues? > > Greg > > > 2015-09-19 18:16 GMT+02:00 Gerhard Petracek : > > > hi greg, > > > > you are very welcome to ask questions on this list. > > (helping deltaspike-users is the main intention here...) > > > > @your issue: > > your code isn't valid with cdi. if you don't like to use both > > interceptor-annotations in your service-classes, just create a > > cdi-stereotype annotation (e.g. @Service) and annotate that one with both > > interceptor-annotations. > > > > regards, > > gerhard > > > > > > > > 2015-09-19 17:56 GMT+02:00 Grzesiek : > > > > > Hi all, > > > > > > It is my first post here, usually I would use StackOverflow, but there > is > > > almost none questions/ answers tagged with DeltaSpike. > > > > > > Sorry for wasting your precious time. But I'm struggling for a couple > of > > > hours with not working @Transactional interceptor from > > > *deltaspike-jpa-module* inside my own interceptor. > > > > > > Details: > > > My own interceptor: @DetectIntegrityConstraintViolationInterceptor > needs > > to > > > have injected an EntityManager instance, but unfortunately I'm always > > > getting "*java.lang.IllegalStateException: Transaction not active*" > > inside > > > this interceptor (injection of EntityManager works fine, but > transaction > > is > > > not started automatically). > > > > > > Do somebody know why? > > > > > > My use case is quite simple: one service, marked with @Transactional, > and > > > its one method is also annotated with > > > @DetectIntegrityConstraintViolationInterceptor. > > > > > > I've been trying blindly a couple of combinations, but none works: > > > * I've marked also my interceptor with @Transactional > > > * I've marked also both my Interceptor and InterceptorBinding with > > > @Transactional > > > > > > Simplified code: > > > > > > @ManagedBean // make it a CDI bean > > > > @Interceptor > > > > @DetectIntegrityConstraintViolation > > > > public class DetectIntegrityConstraintViolationInterceptor { > > > > > > > > @Inject > > > > private EntityManager em; > > > > > > > > @AroundInvoke > > > > > > > // @Transactional // ALSO BLINDLY TRIED THIS, but no luck > > > > > > > public Object processInvocation(InvocationContext ctx) > > > > throws Exception { > > > > Object o = null; > > > > try { > > > > o = ctx.proceed(); > > > > em.flush(); // THIS CAUSES EXCEPTION, AS > > TRANSACTION > > > > DOESN'T EXIST > > > > } catch (PersistenceException ex) { > > > > // .... > > > > } > > > > return o; > > > > } > > > > > > > } > > > > > > > > > > Service class looks like: > > > > > > import org.apache.deltaspike.jpa.api.transaction.Transactional; > > > > > > > > > > > > > > @Transactional > > > > public class MyServiceBean implements MyService { > > > > > > > > @Inject > > > > EntityManager em; > > > > > > > > @DetectIntegrityConstraintViolation > > > > public ResponseEntity createUser(User user) { > > > > em.persist(user); > > > > } > > > > } > > > > > > > > > > Tip: EntityManager was tried both: @TransactionScoped and > @RequestScoped > > - > > > result similar, only message was a bit different ;-) > > > > > > Any clues? > > > Ps. I'm sorry, if above code is not readable, bu I don't know how to > > format > > > code inside an email. > > > > > > Libs versions used: > > > * deltaspike-jpa-module-api 1.4.1 > > > * weld-servlet-core 2.2.0.Final > > > * JDK 1.7 > > > > > > Kind regards > > > Greg Demecki > > > > > > --089e013d0a4c6556f405201f7302--