James P.
James P.

Reputation: 19617

OpenEntityManagerInViewFilter and testing the presence of an EntityManager

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

Answers (2)

James P.
James P.

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

BalusC
BalusC

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

Related Questions