SQL being executed outside of transaction boundaries
sarnac Dec 12, 2008 8:47 PMHi all,
I am running the JPA Booking example on a PostgreSQL database and it seems that some of the generated SQL is being executed outside of the Seam transaction boundaries. I haven't changed anything in the example except the datasource and JDBC driver, which is PostrgeSQL instead of the default Hypersonic.
I have found this while looking at the logs, which I have configured as such:
<logger name="org.hibernate.SQL"> <level value="DEBUG"/> </logger> <logger name="org.jboss.seam.transaction"> <level value="DEBUG"/> </logger> <logger name="org.jboss.seam.contexts.FacesLifecycle"> <level value="DEBUG"/> </logger> <logger name="org.jboss.seam.jsf"> <level value="DEBUG"/> </logger>
With this logging configuration, the following logs are produced when I confirm a Booking in the example application:
2008-12-12 13:57:07,910 DEBUG [org.jboss.seam.contexts.FacesLifecycle] >>> Begin JSF request for /jboss-seam-jpa/confirm.seam
2008-12-12 13:57:07,914 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] beginning transaction prior to phase: APPLY_REQUEST_VALUES 2
2008-12-12 13:57:07,914 DEBUG [org.jboss.seam.transaction.EntityTransaction] beginning JPA resource-local transaction
2008-12-12 13:57:07,917 DEBUG [org.jboss.seam.transaction.EntityTransaction] registering synchronization: ManagedPersistenceContext(java:/em)
2008-12-12 13:57:07,919 DEBUG [org.hibernate.SQL]
select
nextval ('hibernate_sequence')
2008-12-12 13:57:07,921 DEBUG [org.hibernate.SQL]
select
user_.username,
user_.name as name478_,
user_.password as password478_
from
Customer user_
where
user_.username=?
2008-12-12 13:57:07,975 INFO [org.jboss.seam.example.jpa.HotelBookingAction] New booking: 1 for demo
2008-12-12 13:57:07,995 DEBUG [org.jboss.seam.transaction.EntityTransaction] registering synchronization: TransactionSuccessEvent(bookingConfirmed)
2008-12-12 13:57:07,996 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] committing transaction after phase: INVOKE_APPLICATION 5
2008-12-12 13:57:07,996 DEBUG [org.jboss.seam.transaction.EntityTransaction] committing JPA resource-local transaction
2008-12-12 13:57:07,998 DEBUG [org.hibernate.SQL]
insert
into
Booking
(user_username, checkinDate, hotel_id, checkoutDate, creditCard, smoking, beds, creditCardName, creditCardExpiryMonth, creditCardExpiryYear, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2008-12-12 13:57:08,480 DEBUG [org.jboss.seam.transaction.EntityTransaction] beginning JPA resource-local transaction
2008-12-12 13:57:08,480 DEBUG [org.jboss.seam.transaction.EntityTransaction] registering synchronization: ManagedPersistenceContext(java:/em)
2008-12-12 13:57:08,482 DEBUG [org.hibernate.SQL]
select
booking0_.id as id477_,
booking0_.user_username as user11_477_,
booking0_.checkinDate as checkinD2_477_,
booking0_.hotel_id as hotel10_477_,
booking0_.checkoutDate as checkout3_477_,
booking0_.creditCard as creditCard477_,
booking0_.smoking as smoking477_,
booking0_.beds as beds477_,
booking0_.creditCardName as creditCa7_477_,
booking0_.creditCardExpiryMonth as creditCa8_477_,
booking0_.creditCardExpiryYear as creditCa9_477_
from
Booking booking0_
where
booking0_.user_username=?
order by
booking0_.checkinDate
2008-12-12 13:57:08,485 DEBUG [org.jboss.seam.transaction.EntityTransaction] committing JPA resource-local transaction
2008-12-12 13:57:08,487 DEBUG [org.jboss.seam.contexts.FacesLifecycle] After render response, destroying contexts
2008-12-12 13:57:08,489 DEBUG [org.jboss.seam.contexts.FacesLifecycle] <<< End JSF request for /jboss-seam-jpa/confirm.seam
Notice that the INSERT statement for a new Booking appears after the transaction commit. If I were using Hypersonic, the insert would be logged before the commit. Does anyone know the reason for this? Does that mean the insert is being executed outside of the Seam-managed transaction?
Thanks in advance,
Mathieu