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
开发者_StackOverflowWhat 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?
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
.
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.
精彩评论