1
votes

Spring Webflow: 2.3.1
Spring Data: 1.0.2
JSF: 2.1.9
Primefaces: 3.3.1

I'm trying to combine Spring Data JPA Repositories with JSF DataModel, in this case, Primefaces with LazyDataModel. This happens in a WebApp integrating Spring with JSF, using Spring Webflow.

The problem is when i use a JpaRepository inside LazyDataModel that lives in ViewScope of Spring Webflow:


Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.(SerializedFlowExecutionSnapshot.java:75)"


Without the JpaRepository inside LazyDataModel, i cannot get the correct page and use the Pagination model of spring data. I already found someone with the same problem, but unfortunately no one answered:

http://forum.springsource.org/showthread.php?116022-Webflow-Serialization-error-on-object-holding-ref-to-JPA-Data-Repository

Thanks for you help in advance

Best regards

JSimas

2

2 Answers

3
votes

Already found a solution for this problem!

Whenever you need to add a reference to a Spring Data JPA Repository in an object that will live in your spring webflow context, just to declare the JPA repository as transient! Then you need to add the following annotations in the object that contain the transient reference:

  • @Configurable - to mark the class to be configured on the fly (this will add some overhead to your application, be careful to use this annotation only when you need)
  • @Autowired - add this to the transient JPA Repository

So, if you're extending a DataModel JSF base class, and you want to add some JPA repository, here is an example:

@Configurable
public class XptoLazyDataModel extends LazyDataModel<Xpto> {

    @Autowired
    private transient JpaRepository<Xpto> repository;

 (...)
}

And there you go. Hope that this can help someone.

Best regards

0
votes

It also occurred to me that I should apply the transient keyword to my JPA repository field, as you have. This solved the problem, however, I did not need to use @Configurable or @Autowired.