I m using JSF 2.0 with Spring 3.2.8 and JPA 2.0 and hibernate 4.2.11.Final, and i have an issue, i'm struggling more than 2 days now to undestand this problem but i have no explanation for it
actually the flow consist of viewing a list of employees with a Primefaces datatable and then selecting a specific row to set it in the JSF ManagedBean .
The case works perfectly when the JSF Managed Bean scope is set to SessionScoped But when i change the scope to ViewScoped , the list is loaded with no problem but when i select a row the ajax request returns an error and here is the XML response :
when i debuggued the hibernate class that is throwing the exception , EntityManagerFactoryRegistry.getNamedEntityManager Factory it finds 2 already registred EntityManagerFactory . i dont understand who did register them and when and why the case does only occur when using ViewScoped JSF Beans (i'm not using CDI anywhere)
here is my managed bean
I'm using extended EntityManager because i have Lazy relationsShip in my model , so i'm calling close method on the persistent context at the end of my flow.
Any one have idea what's the matter with the ViewScoped within Spring or may be it has nothing to do ( i m saying so because it just work fine with SessionScoped but i don't won't to have My Beans as Session Objects)
I don't see anything wrong with the JSF code itself.
What I suspect is that your method of obtaining DAOs is at fault.
I do Spring+JPA+JSF all the time, although for my stuff, the actual DAO stuff is a separate layer beneath a transactional business persistence layer. The business persistence layer handles working with graphs of persistence model objects, whereas the DAO layer does table-at-a-time persistence.
But that's just how things work for me and not essential for this problem. Back to my original speculation, I'd say that your Spring config isn't manufacturing the DAO as a singleton object. Another thing I suppose I should mention about my particular architectural style is that my DAOs are essentially the same thing as stateless session EJBs, fulfilling that function since Tomcat has no native EJB support.
You might actually be having the same problem long-term doing your work in session scope, but it's simply showing up more quickly in View scope, simply because the View scope objects are created and destroyed much more frequently.
Another possibility suggested by the original error message would be that your actual persistence factory isn't a single object. Either you're tapping into multiple persistency providers or the persistence factory isn't defined as a singleton object.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Mar 31, 2014
Hi Tim ,
Thank you for your reply , y re right , that was about the LocalContainerEntityManagerFactoryBean configuration ,
There are many ways to declare the persistence configuration ,my first configuration use a persistenceUnitManager and was like this
Actually, it would have been a lot more useful if you'd indicated which item(s) you changed in your spring config instead of simply listing the entire changed config. Once a listing gets too long for the screen, it's too much work to follow. And the relative vertical heights on computer screens aren't what they used to be.
Joined: Mar 31, 2014
What it changed is the declaration of the LocalContainerEntityManagerFactoryBean , in the failing configuration i was declaring a persistenceUnitManager that load my persistence.xml config and referencing it in the LocalContainerEntityManagerFactoryBean
in the working config the LocalContainerEntityManagerFactoryBean , i provided the dataSource , the package to scan where my entities are ,and the jpa implementation (hibernate).
that is the main difference , i looking now on to the source of Spring LocalContainerEntityManagerFactoryBean to see how things works for the two config .
subject: Hibernate Exception when using Spring dao withing JSF ViewScoped Bean