I had a similar problem, maybe this will help. I used the booking-faces example to build an application, and I noticed in some cases, <persistence-context/> worked as expected, and in other cases, it did not.
It turned out that all of the LazyDataModel instances, which I initialized like this:
Code:
<persistence-context/>
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.SearchCriteria" />
....
<on-entry>
<set name="flowScope.hotels" value="searchCriteria.getDataModel(bookingService)" />
</on-entry>
Had a different entity manager , which did not appear to be persistent across the flow, than other elements in the flow using the same bookingService.
I ended up doing it this way and it resolved the problem:
Code:
// I added these lines to HotelLazyDataModel:
public HotelLazyDataModel(){}
// Recall bookingService is annotated with @Service("bookingService")
// and has a @PersistenceContext annotation to define the EntityManager
@Autowired
public void setBookingService(BookingService service)
{
bookingService = service;
}
public void setSearchCriteria(SearchCriteria criteria){...}
// and the flow was changed like this:
<var name="searchCriteria" class="org.springframework.webflow.samples.booking.SearchCriteria" />
<var name="hotelDataModel" value="org.springframework.webflow.samples.booking.HotelLazyDataModel"/>
...
<on-entry>
<evaluate expression="hotelDataModel.setSearchCriteria(searchCriteria)"/>
...
I got the idea for the solution b/c I had an action class that had an @Autowired annotation to set the bookingService, and the action class seemed to be using the same (persistent) EntityManager as other elements of the flow
I tested it like this:
Code:
<set name="flowScope.testHotel" value="bookingService.findHotel(0)">
<evaluate expression="myAction.checkHotelInEntityManager(testHotel)/>