• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Can't Retrieve EntityManager With Multiple Dao Persistence

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Struts 2, Spring, Hibernate+JPA, with Generic definitions for the Daos and Services (i.e. GenericDao<T, ID> and GenericService<T>). Up to this point I've been able to handle basic lists within my views. As I'm proceeding with development of the application, I now need to edit the data.

When generating the form to do this (the form is generated from a view which requires a method in the ClothingAction >> setupForInsertUpdate() ) I need to generate a list of clothing types during the setup process so that my list of options in the form can be populated as provided by the DB (accessed via ClothingTypesDao). The problem I'm having is that when I create a service within my action to handle this list creation (ClothingTypeService) and try to process the method within it called getAllClothingTypes() which uses the EntityManager defined within the GenericDao, the EntityManager is not available (most likely because it's been detached, or closed, I'm assuming).

I can post code later, but can anyone provide general insight into how I can have my ClothingTypeDao access the same EntityManager as my ClothingAction > ClothingService > ClothingDao object during that "setupForInsertUpdate()" method defined in the ClothingAction?

Thanks.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't duplicate post or resurrect old threads. Either post a new thread or reply to a thread, please don't do both.

In JavaRanch's case, both threads are now at the top, and are duplicates now. If you just do one, then people will see it. They shouldn't be wasting time having to see it now twice.

Thanks for understanding, I am going to close the resurrected thread and leave this thread.

Mark
 
Eugene Williams
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new.

Thanks sir
 
Eugene Williams
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the solution to my problem. In order to obtain an entity manager for all DAOs defined within the context of the application, I needed to access the ApplicationContext before generating my supplemental data request.

this required that I pull the bean from those defined in the applicationContext.xml file, rather than using a DAO object instantiated within the struts action.
so, rather than

setupForInsertUpdate now contains the following lines:

my applicationContext.xml file is stored in my WEB-INF/ folder - the above request forced it upon the classpath so that it was retrievable by the ClassPathXml... convenience class
now that I have an object which gives me access to the app context, I can now grab beans which are defined within it, namely the DAOs I need
 
I found a beautiful pie. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic