On Mar 30, 2009, at 9:32 PM, Scott Hernandez wrote: > Well, I have configured a test app to use hibernate and I have a few > problems (and a bit of success): > > I was able to get the same code working from a servlet, but when > trying to get data I get an exception when running from a @Service (in > the @PostConstruct method): > > [21:26:06.430] {main} java.lang.IllegalStateException: > EntityManagerTransactionProxy[test,null]: @PersistenceContext > EntityManager may not be used outside of a transaction > [21:26:06.430] {main} at
> > trying to use entityManager.getTransaction().begin got me this > exception: > java.lang.IllegalStateException: Container-manager @PersistenceContext > may not use getTransaction. > > I'm guessing that the problem is that the @Service post construction > is happened too soon, maybe. It's a different issue, I believe. The EntityManager is intended to be used inside a UserTransaction, i.e. a container-managed transaction. The JavaEE model is that you're running inside a Session bean, although that's not strictly necessary as long as it's inside a transaction. If you're managing transactions with the EntityManager, you need to use EntityManagerFactory, not EntityManager. (It's been a little while since I've read that part of the spec, though.) -- Scott > > > [snip] > > > _______________________________________________ > resin-interest mailing list > resin-interest@caucho.com > http://maillist.caucho.com/mailman/listinfo/resin-interest _______________________________________________ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest