This content has been marked as final.
Show 2 replies
-
1. Re: Question regarding JbpmContext
hosierdm Jun 9, 2006 4:44 PM (in response to nomad)I have code running inside an app server, and what I do is create a context in every method and close at the end. For example, I might have something like this:
public void deleteUser(String user) { JbpmContext jbpmContext = _jbpmConfig.createJbpmContext(); try { // do some stuff } finally { jbpmContext.close(); } public void deleteGroup(String group) { JbpmContext jbpmContext = _jbpmConfig.createJbpmContext(); try { // do some other stuff } finally { jbpmContext.close(); }
Where _jbpmConfig is just a cached instance of the JbpmConfiguration object. I haven't noticed any problems doing things this way. I haven't messed with it too much, but I imagine that if in one of my methods above, I called another method and needed a reference to the context, I could call getCurrentJbpmContext() and I would get the one that I created at the start of the calling method. I'm sure someone like Ronald can offer more insight (and hopefully set me straight if I'm way off base here...especially since I have an application going into system test on Monday using code like that above!) -
2. Re: Question regarding JbpmContext
nomad Jun 10, 2006 12:22 AM (in response to nomad)Yeah, actually I write my code the same way as you do hosierdm. I haven't tested the code inside appserver, only tested it using a swing base client. What I notice is after I close the jbpmcontext object I can no longer use my hibernate session because it already closed inside JbpmContext.close() method. Even creating a new JbpmContext object again will still use the same hibernate session that has been closed previously. So this code will not work :
public void deleteUser(String user) { JbpmContext jbpmContext = _jbpmConfig.createJbpmContext(); try { // do some stuff } finally { jbpmContext.close(); } // access persistence layer using hibernate session will throw error // indicating that the hibernate session is already closed //even creating a new JbpmContext like this will not help jbpmContext = _jbpmConfig.createJbpmContext(); try { // do some stuff } finally { jbpmContext.close(); } }
May be I made a mistake somewhere, but not sure where. I use spring + jbpm based on the code by criess which you can find here :
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=78052&start=0&postdays=postDays&postorder=postOrder&highlight=highlight
Basically I let spring to manage my Hibernate session, the JbpmConfiguration and the JbpmContext object creation.
By the way, thx for your response hosierdm, well , at least I'm quite sure now that I've used jbpm api quite correctly :p
Regards,
Martin