I'm afraid it is a problem. If I'm not closing the session explicitly in my component code, I end up getting pool exhausted exceptions. Some time ago, before I started migrating to component design, I used to close the session manually in my plugin, but still was getting the same exceptions. Maybe my code was buggy, but I would like, if possible, avoid handling sessions myself. Is it even possible? Does XWiki use any kind of JTA?
2010/7/15 Caleb James DeLisle <[email protected]>: > Yes, it's closed before you have an opportunity to get a hold of it. > > You could add session.close() to the end of the script. > I don't think it is a problem because after extensive testing of that script > I still only have 5 processes of postgres running. > according to the javadoc, connection.commit() releases the actual connection > to the database. The garbage collector would take care of the rest. > > I just made a snippet in codeville. > http://code.xwiki.org/xwiki/bin/view/Snippets/DehiddenifierSnippet > > Caleb > > Igor Popov wrote: >> Thanks, Caleb! That saved me a lot of time. >> >> I have another question. Maybe I'm not getting the hibernate sessions >> idea right, but >> how can I get the current hibernate session that XWiki uses? I'm not >> eager to open my own session, as >> I'll have to make sure that it's closed correctly in the end. >> >> I've tried XWikiHibernateStore.getSession() but it appears to give me >> a null value. >> >> 2010/7/14 Caleb James DeLisle <[email protected]>: >>> If you don't mind declaring a dependency on xwiki-core, you can >>> import org.xwiki.context.Execution >>> import com.xpn.xwiki.XWikiContext >>> import com.xpn.xwiki.XWiki >>> import com.xpn.xwiki.store.XWikiHibernateStore >>> and then use: >>> >>> @Requirement >>> Execution ex; >>> >>> XWikiHibernateStore hib = >>> ex.getContext().get("xwikicontext").getWiki().getHibernateStore(); >>> >>> and you have XWikiHibernateStore, from that you can get the SessionFactory, >>> open a session and do whatever. >>> >>> The API: >>> http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/store/XWikiHibernateStore.html >>> >>> Caleb >>> >>> Igor Popov wrote: >>>> Again I have a question. QueryManager class allows to make queries to >>>> the database, but, for example, >>>> If I want to store an object in the database, I'll have to use >>>> something similar to hibernate session's save() method. >>>> What should I do? >>>> >>>> 2010/7/9 Igor Popov <[email protected]>: >>>>> Thanks, Alex! Never thought that it could be in the "scripting" >>>>> section of docs... >>>>> >>>>> 2010/7/9 Alex Busenius <[email protected]>: >>>>>> I guess this will answer your question: >>>>>> http://platform.xwiki.org/xwiki/bin/view/DevGuide/QueryGuide#HFromJavacomponents >>>>>> >>>>>> On 07/09/2010 06:28 AM, Igor Popov wrote: >>>>>>> Hi! >>>>>>> >>>>>>> I'm new to XWiki (especially to new "Component" design). My question >>>>>>> is: can my component/plugin access the database >>>>>>> the same way XWiki does? I.e. if I write Hibernate mappings for my own >>>>>>> objects and reference them in XWiki hibernate.cfg.xml, >>>>>>> how can my plugin/component gain access to Hibernate session object? >>>>>>> >>>>>>> Previously I've written a plugin for XWiki and had to connect to >>>>>>> database separately from XWiki. >>>>>>> It was not convenient at all and I want to avoid this practice in >>>>>>> further development. >>>>>>> Moreover, I had some problems with using connection pool, so I think >>>>>>> it would be wiser to >>>>>>> use XWiki database connection. >>>>>>> _______________________________________________ >>>>>>> users mailing list >>>>>>> [email protected] >>>>>>> http://lists.xwiki.org/mailman/listinfo/users >>>>>>> >>>>>> _______________________________________________ >>>>>> users mailing list >>>>>> [email protected] >>>>>> http://lists.xwiki.org/mailman/listinfo/users >>>>>> >>>> _______________________________________________ >>>> users mailing list >>>> [email protected] >>>> http://lists.xwiki.org/mailman/listinfo/users >>>> >>> _______________________________________________ >>> users mailing list >>> [email protected] >>> http://lists.xwiki.org/mailman/listinfo/users >>> >> _______________________________________________ >> users mailing list >> [email protected] >> http://lists.xwiki.org/mailman/listinfo/users >> > > _______________________________________________ > users mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/users > _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
