Reputation: 19617
I posted a question a few days ago mentionning Spring's OpenEntityManagerInViewFilter: ui:repeat inside a ui:repeat 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?
Upvotes: 1
Views: 654
Reputation: 19617
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.
Upvotes: 0
Reputation: 1109362
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
.
Upvotes: 1