• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Exception when using Spring dao withing JSF ViewScoped Bean

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
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

The Dao

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)

Thank's for your Help.

Ryan
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am linkign this post to JSF forum to see if someone over there has an answer
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ryan Rha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


and i changed it like this


but i dont understand why the first way fails .

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ryan Rha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic