-
1. Re: Entity not persisting from within a Servlet Filter
norman.richards Jan 7, 2007 3:00 PM (in response to brentgfox)Does it work if your start a transaction?
-
2. Re: Entity not persisting from within a Servlet Filter
brentgfox Jan 8, 2007 8:55 PM (in response to brentgfox)Thanks for the reply.
Now, after wrapping it in a transaction, when I attempt to get the transaction manager from the entity manager, I get the following exception:... java.lang.IllegalStateException: JTA EntityManager cannot access a transactions ...
I've hunted around the web, and found a few people that have seen this, but no solutions. Not sure what that means - any ideas? -
3. Re: Entity not persisting from within a Servlet Filter
norman.richards Jan 8, 2007 9:58 PM (in response to brentgfox)You'll probably need to look up the the the user transaction object in JNDI (java:/UserTransaction) and then explicitly call begin/commit.
As you can see, it's always preferable to be doing these things in a managed environment where you don't need to think about these things. :) -
4. Re: Entity not persisting from within a Servlet Filter
shane.bryzak Jan 8, 2007 11:02 PM (in response to brentgfox)I agree with Norman. I'd be inclined to put your business logic into a Seam component and then call that from your filter. SeamServletFilter is a good example of how to set up the Seam contexts for the request.
-
5. Re: Entity not persisting from within a Servlet Filter
brentgfox Jan 9, 2007 1:24 AM (in response to brentgfox)"sbryzak2" wrote:
I agree with Norman. I'd be inclined to put your business logic into a Seam component and then call that from your filter. SeamServletFilter is a good example of how to set up the Seam contexts for the request.
I've tried wrapping it in a transaction gathered from a context lookup - but it still doesn't seem to persist the entity.
The more I look at it - the suggestion that I put this into a seam component and call it from the filter seems like the right way to go. Managing it from outside defeats the purpose of using an application framework like seam. Old habits die hard. ;-)
I appreciate the quick responses.
Thanks again. -
6. Re: Entity not persisting from within a Servlet Filter
smokingapipe Jan 9, 2007 2:56 AM (in response to brentgfox)You can definitely do this from a filter. I have a servlet that gets an EntityManager. It must get a transaction to work! It can do queries without a transaction but it cannot do writes without one. As for why it can't find a transaction, I have no idea. Maybe post some of your persistence configuration stuff? With my setup it works no problem, and a Servlet is not very different from a Filter.
But in general, most things like that should happen in Seam components. -
7. Re: Entity not persisting from within a Servlet Filter
norman.richards Jan 9, 2007 9:44 AM (in response to brentgfox)Hmm... If you have the TX started then you really ought to be able to persist. I'm really curious what the issue is in this.