Hi,
I've been attempting to add persistence to the seam-cron module for
which I need to use transaction events. Unfortunately I cannot get them
to work. They always get called immediately rather than when the
transaction is completed. So I turned to the seam-booking example
(https://github.com/seam/examples/tree/master/booking) which I saw was
using transaction events and added some logging (attached), but this
appears to have the same issue. The output from the log is:
17:13:16,580 INFO
[org.jboss.seam.examples.booking.booking.BookingAgent]
(http--127.0.0.1-8080-1) confirm begin
17:13:16,587 INFO
[org.jboss.seam.examples.booking.booking.BookingHistory]
(http--127.0.0.1-8080-1) Adding new booking to user's cached booking history
17:13:16,588 INFO
[org.jboss.seam.examples.booking.booking.BookingAgent]
(http--127.0.0.1-8080-1) onBookingComplete begin
17:13:16,589 INFO
[org.jboss.seam.examples.booking.booking.BookingAgent]
(http--127.0.0.1-8080-1) New booking at the W New York - Union Square
confirmed for Shane Bryzak.
17:13:16,599 INFO
[org.jboss.seam.examples.booking.booking.BookingAgent]
(http--127.0.0.1-8080-1) onBookingComplete end
17:13:16,600 INFO
[org.jboss.seam.examples.booking.booking.BookingAgent]
(http--127.0.0.1-8080-1) confirm end
But in theory the order of the logging should be:
confirm begin
confirm end
onBookingComplete begin
onBookingComplete end
I did note that there was nothing specifying a transaction was required
for the entirety of the confirm method so I also added
@TransactionAttribute(TransactionAttributeType.REQUIRED) to the method
(also in attached patch), but that had the same result.
I've been trying this in jboss-as-web-7.0.2.Final. I'm probably doing
something wrong but I don't know what. Does anyone have any ideas?
Cheers,
Dave.
diff --git a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
index 07dffaa..cb37cac 100644
--- a/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
+++ b/booking/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
@@ -19,6 +19,8 @@ package org.jboss.seam.examples.booking.booking;
import java.util.Locale;
import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
@@ -45,6 +47,7 @@ import org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor
import org.jboss.seam.faces.context.conversation.End;
import org.jboss.seam.international.status.Messages;
import org.jboss.seam.international.status.builder.TemplateMessage;
+import org.jboss.solder.logging.Logger;
import org.jboss.solder.logging.TypedCategory;
import static javax.persistence.PersistenceContextType.EXTENDED;
@@ -61,6 +64,9 @@ public class BookingAgent {
@TypedCategory(BookingAgent.class)
private BookingLog log;
+ @Inject
+ private Logger LOG;
+
@PersistenceContext(type = EXTENDED)
private EntityManager em;
@@ -120,9 +126,12 @@ public class BookingAgent {
}
@End
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
public void confirm() {
+ LOG.info("confirm begin");
em.persist(booking);
bookingConfirmedEventSrc.fire(booking);
+ LOG.info("confirm end");
}
@End
@@ -132,9 +141,11 @@ public class BookingAgent {
}
public void onBookingComplete(@Observes(during = TransactionPhase.AFTER_SUCCESS) @Confirmed final Booking booking) {
+ LOG.info("onBookingComplete begin");
log.bookingConfirmed(booking.getHotel().getName(), booking.getUser().getName());
messages.info(new DefaultBundleKey("booking_confirmed")).defaults("You're booked to stay at the {0} {1}.")
.params(booking.getHotel().getName(), new PrettyTime(locale).format(booking.getCheckinDate()));
+ LOG.info("onBookingComplete end");
}
@Produces
_______________________________________________
seam-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/seam-dev