tags:

views:

34

answers:

2

I posted a question a few days ago mentionning Spring's OpenEntityManagerInViewFilter: http://stackoverflow.com/questions/2385858/uirepeat-inside-a-uirepeat-and-lazyinitexception

What I'd like to know is of a way to test if an EntityManager is available during a request. What is a good way of doing this?

+1  A: 

It's unclear where exactly you intend to test it, but in general just checking if the following doesn't throw an exception (e.g. PersistenceException) ought to be a sufficient hint.

EntityManagerFactory emf = Persistence.createEntityManagerFactory(name);
EntityManager em = emf.createEntityManager();

The name is obviously the persistence unit name as definied in the /META-INF/persistence.xml.

BalusC
A: 

My team has given up trying to get OpenEntityManagerInViewFilter to work for the moment because of time constraints and we've switched FetchTypes to eager. It might not be initializing properly or is incompatible with JSF 1.2. If anyone reading this comes accross a solution please let me know.

James P.