sry i made the first post a little confusing .. with <property name="current_session_context_class">managed</property> im getting : org.hibernate.HibernateException: No session currently bound to execution context ()
and with <property name="current_session_context_class">thread</ property> im getting: org.hibernate.SessionException: Session is closed! () On Feb 2, 7:13 pm, Eelco Hillenius <[email protected]> wrote: > And again, what is your value for current_session_context_class? This > defaults (still I think) to ThreadLocalSessionContext > (current_session_context_class = thread), which tries to open a > session magically (when it finds a transaction context). Like it's > documentation says, this implementation is problematic, and > JTASessionContext (current_session_context_class = jta) or > ManagedSessionContext (current_session_context_class = managed) > provide better alternatives. In case you use managed (which I'm > using), something needs to prepare the session (and clean it up > again). PersistenceFilter does for servlet requests. *If* you're not > in a servlet request, using WorkManager directly is one of the ways > you can do it. > > Eelco > > On Tue, Feb 2, 2010 at 1:55 PM, Eelco Hillenius > > > > <[email protected]> wrote: > > Keep in mind though, that you want to call beginWork before calling > > any @Transactional annotated method. The filter (the one I gave may be > > specific for the 2.0 snapshot I'm using) is the easiest way to go. > > Though I use WorkManager directly often in e.g. unit test, patching > > code, etc. > > > Eelco > > > On Tue, Feb 2, 2010 at 1:34 PM, Maurixio <[email protected]> wrote: > >> I try it with the WorkManager and it works .. thanks =) > > >> public List<Pattern> search(Application app) { > >> unitOfWork.beginWork(); > >> Criteria criteria = session.get().createCriteria > >> (Pattern.class); > >> criteria.add((Expression.eq("idApp",app))) > >> .add(Expression.ne("isCon", false)) > >> .addOrder(Order.desc("priority")); > >> return criteria.list(); > >> List<Pattern> result = criteria.list(); > >> unitOfWork.endWork(); > >> return result; > >> } > > >> On Feb 2, 3:52 pm, Eelco Hillenius <[email protected]> wrote: > >>> What is your value for current_session_context_class? If it is managed > >>> (which is the value I think is best), then you need to prepare > >>> sessions through using WorkManager (beginWork/ endWork, and this is > >>> Guice managed, so you can have it injected). Or if you're in a servlet > >>> environment, use wideplay's persistence filter, e.g. like: > > >>> public class ServletsModule extends ServletModule { > >>> @Override > >>> protected void configureServlets() { > >>> filter("/*").through(PersistenceFilter.class); > > >>> Eelco > > >>> On Tue, Feb 2, 2010 at 6:35 AM, Maurixio <[email protected]> wrote: > >>> > Hello everyone ... after reading the Dependency Injection book (love > >>> > this book btw) im trying to put up a project with Guice , Warp and > >>> > Hibernate ... I have been trying a lot of thing the last week ... and > >>> > i cant make it work .. > >>> > im getting : > >>> > org.hibernate.HibernateException: No session currently bound to > >>> > execution context (<property > >>> > name="current_session_context_class">managed</property>) > >>> > or > >>> > org.hibernate.SessionException: Session is closed! (<property > >>> > name="current_session_context_class">thread</property>) > > >>> > The configure of guice is like > >>> > protected void configure() { > >>> > install(PersistenceService.usingHibernate().across > >>> > (UnitOfWork.REQUEST).buildModule()); > >>> > bind(Configuration.class).toInstance(new > >>> > AnnotationConfiguration().configure()); > >>> > ... > >>> > bind(MyInitializer.class).asEagerSingleton(); > >>> > } > > >>> > the MyInitializer.class is like : > >>> > .. > >>> > @Inject MyInitializer(PersistenceService service) { > >>> > service.start(); > >>> > } > >>> > .. > > >>> > and im using it like: > > >>> > private final Provider<Session> session; > > >>> > @Inject > >>> > public HibernateFooManager(Provider<Session> session) { > >>> > this.session = session; > >>> > } > > >>> > @Transactional(type=TransactionType.READ_ONLY) > >>> > public List<Foo> search(Application app) { > >>> > Criteria criteria = session.get().createCriteria > >>> > (Pattern.class); > >>> > criteria.add((Expression.eq("idApp",app))) > >>> > .add(Expression.ne("isCon", false)) > >>> > .addOrder(Order.desc("priority")); > >>> > return criteria.list(); > >>> > } > > >>> > Can someone help me , to see what im doing wrong? > > >>> > -- > >>> > You received this message because you are subscribed to the Google > >>> > Groups "google-guice" group. > >>> > To post to this group, send email to [email protected]. > >>> > To unsubscribe from this group, send email to > >>> > [email protected]. > >>> > For more options, visit this group > >>> > athttp://groups.google.com/group/google-guice?hl=en. > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "google-guice" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]. > >> For more options, visit this group > >> athttp://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
