You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by oguzhan tortop <og...@yahoo.com> on 2007/04/04 13:26:20 UTC
Struts 2 exception problem
hi all,
i am using struts2 with hibernate i have a basic form which inputs the given
data via hibernate. I get the hibernate session from my custom hibernate
interceptor and from that interceptor i call the action which creates the
hibernate transaction with data from its form and after that i return the
success case from action but there is a finally statement in my hibernate
interceptor which commits the transaction that's data filled in my action
class. But for ex. if the data is exist in db before which means duplicate
then it gives an error and when i get this error i return and ACTION.ERROR
from my hibernate interceptor but what i see on the page is the SUCCESS
result from the action class. What could be the problem ? :) Any help will
be usefull thanks for your support
Here is my default stack and action conf.
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="servlet-config"/>
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="hibernate"/>
</interceptor-stack>
<action name="CreateService"
class="tr.com.mkk.admin.action.CreateServiceAction">
<result name="input" >
<param name="location">/admin/createService.jsp</param>
</result>
<result name="success" >
<param
name="location">/admin/viewService.jsp</param>
</result>
<interceptor-ref name="validation"/>
<interceptor-ref name="validatorErrors"/>
<interceptor-ref name="defaultStack"/>
</action>
Here is my interceptor class :
public String intercept(ActionInvocation invocation) throws Exception {
Action action = (Action)invocation.getAction();
if ( !(action instanceof BaseActionSupport) ) return invocation.invoke();
if (null == factoryName || null == packageName)
throw new IllegalArgumentException("factoryName and packageName
parameters should be given \n" +
"check parameters in xml file <param name='factoryName'> \n" +
"and <param name='packageName'>\n");
// adds factory to cache if not available
HibernateSessionFactory.addFactory(factoryName, packageName,
extConfigFilePath);
HibernateSession hs = new HibernateSession();
hs.setFactoryName(factoryName);
((BaseActionSupport)action).setHibernateSession(hs);
try {
result = invocation.invoke();//calls the action here it creates
transaction data
}
// Note that all the cleanup is done
// after the view is rendered, so we
// have an open session in the view
catch (Exception e) {
hs.setRollBackOnly(true);
if (e instanceof HibernateException) {
LOG.error("HibernateException in execute()", e);
return Action.ERROR;
}
else {
LOG.error("Exception in execute()", e);
throw e;
}
}
finally {
try {
hs.disposeSession();//commits transaction , and closes hibernate session
return result;//expected result when an exception occurs with hibernate
operations
}
catch (HibernateException e) {
LOG.error("HibernateException in dispose()", e);
return Action.ERROR;
}
}
}
---------------------Action
Class----------------------------------------------------------
public class CreateServiceAction extends BaseActionSupport {
private Service service;
public CreateServiceAction() {
service = new Service();
}
public String execute() throws Exception {
ServiceManager.getInstance().createService(getSession(), service);//gets
the hibernate session and sends it to the serviceManager object which
creates transaction
set("service", service);
return SUCCESS;
}
public Service getService() {
return service;
}
}
*********
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9835135
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by jimski <ji...@gmail.com>.
Hi Oguzhan-
We've run into the *exact* same problem. Our interceptor is returning
"error" but that return value is not respected when the result is rendered.
It makes me wonder what the value of returning the invocation result is in
the first place...
Just stepping through the code and browsing the invocation context shows
that the resultCode is set to error just after our interceptor is invoked.
However, when I evaluated the resultCode handed to a PreResultListener I
found it had been set back to success.
I'm a little unsure at this point how to use the PreResultListener to solve
the problem.
I've tried adding it in catch block for the hibernate exception as an
Anonymous Inner Class:
invocation.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation invocation, String
resultCode) {
ActionContext.getContext().getActionInvocation().setResultCode("error");
}
});
But the beforeResult method is never called even though I can see the object
getting created. I created a separate interceptor to initialize the
listener and that does work but I'm now stuck on finding a method to signal
that listener to set the result code to error appropriately. It seems that
pushing something onto the value stack in my hibernate interceptor is not
useful since the value I put there is being popped off by someone else.
Have you managed to make any progress on this?
oguzhan tortop wrote:
>
> Of course it has a global result :) it returns "error" too but i think
> struts 2 working mech. makes this impossible to do after
> invocation.invoke() method only the result of the action works... :) i
> think this is not a common situation
>
> Dave Newton-4 wrote:
>>
>> --- oguzhan tortop <og...@yahoo.com> wrote:
>>> ... but how can i implement a PreResultListener.
>>
>> I don't think it'll help anyway; sorry.
>>
>> (Boy, I wish I had my regular machine right now :/
>>
>> How is an Action.ERROR normally handled with the stack
>> you have defined? Is there a global result?
>>
>> d.
>>
>>
>>
>>
>>
>> ____________________________________________________________________________________
>> Need Mail bonding?
>> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
>> http://answers.yahoo.com/dir/?link=list&sid=396546091
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tp9835135p16494148.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
Of course it has a global result :) it returns "error" too but i think struts
2 working mech. makes this impossible to do after invocation.invoke() method
only the result of the action works... :) i think this is not a common
situation
Dave Newton-4 wrote:
>
> --- oguzhan tortop <og...@yahoo.com> wrote:
>> ... but how can i implement a PreResultListener.
>
> I don't think it'll help anyway; sorry.
>
> (Boy, I wish I had my regular machine right now :/
>
> How is an Action.ERROR normally handled with the stack
> you have defined? Is there a global result?
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> http://answers.yahoo.com/dir/?link=list&sid=396546091
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9844540
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by Dave Newton <ne...@yahoo.com>.
--- oguzhan tortop <og...@yahoo.com> wrote:
> ... but how can i implement a PreResultListener.
I don't think it'll help anyway; sorry.
(Boy, I wish I had my regular machine right now :/
How is an Action.ERROR normally handled with the stack
you have defined? Is there a global result?
d.
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
yes that's where i get the exception :D but how can i implement a
PreResultListener. And also what i understand from the below writing is you
can not dispatch to another page after calling an invocation.invoke()
method. Am i wrong :) ?
Dave Newton-4 wrote:
>
> --- oguzhan tortop <og...@yahoo.com> wrote:
>> But if i get a commit error for example a duplivate
>> key it passes to the
>> catch statement in the final block and then it
>> returns Action.ERROR . And
>> also it returns error as a param i debugged the code
>> by attaching source but
>> the problem is it still dispatches to the success
>
> Whoops; obviously you're right--I mis-read the code.
>
> (I was even typing it in thinking OMG why can't he
> read his own code!)
>
> So you're seeing the "HibernateException in dispose()"
> message, correct?
>
> http://struts.apache.org/2.x/docs/writing-interceptors.html
>
> "Keep in mind that invoke will return after the result
> has been called (eg. after you JSP has been rendered),
> making it perfect for things like open-session-in-view
> patterns. If you want to do something before the
> result gets called, you should implement a
> PreResultListener."
>
> Is that the problem?
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Get your own web address.
> Have a HUGE year through Yahoo! Small Business.
> http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9842762
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by Dave Newton <ne...@yahoo.com>.
--- oguzhan tortop <og...@yahoo.com> wrote:
> But if i get a commit error for example a duplivate
> key it passes to the
> catch statement in the final block and then it
> returns Action.ERROR . And
> also it returns error as a param i debugged the code
> by attaching source but
> the problem is it still dispatches to the success
Whoops; obviously you're right--I mis-read the code.
(I was even typing it in thinking OMG why can't he
read his own code!)
So you're seeing the "HibernateException in dispose()"
message, correct?
http://struts.apache.org/2.x/docs/writing-interceptors.html
"Keep in mind that invoke will return after the result
has been called (eg. after you JSP has been rendered),
making it perfect for things like open-session-in-view
patterns. If you want to do something before the
result gets called, you should implement a
PreResultListener."
Is that the problem?
d.
____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
But if i get a commit error for example a duplivate key it passes to the
catch statement in the final block and then it returns Action.ERROR . And
also it returns error as a param i debugged the code by attaching source but
the problem is it still dispatches to the success
Dave Newton-4 wrote:
>
> --- oguzhan tortop <og...@yahoo.com> wrote:
>> but commit is in finally block. so it runs on every
>> condition even if you return any value before it.
>
> ...but a duplicate key exception would happen on the
> commit, because Hibernate queues up its work, right?
>
> Unless you're running a commit in the action itself
> it's not going to throw until you commit in the
> interceptor. And when you commit you're returning the
> result of the action invocation, not Action.ERROR.
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9841683
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by Dave Newton <ne...@yahoo.com>.
--- oguzhan tortop <og...@yahoo.com> wrote:
> but commit is in finally block. so it runs on every
> condition even if you return any value before it.
...but a duplicate key exception would happen on the
commit, because Hibernate queues up its work, right?
Unless you're running a commit in the action itself
it's not going to throw until you commit in the
interceptor. And when you commit you're returning the
result of the action invocation, not Action.ERROR.
d.
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
but commit is in finally block. so it runs on every condition even if you
return any value before it.
Dave Newton-4 wrote:
>
> --- oguzhan tortop <og...@yahoo.com> wrote:
>> At first catch i am expecting to handle exceptions
>> that could be arise while
>> creating the transaction and in the second try block
>> i am commiting the
>> transaction it gives error at the last final block
>> side while commiting.
>
> ...but if the exception is happening on the commit
> doesn't the code you have currently return the result
> of the invocation rather than Action.ERROR?
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> http://answers.yahoo.com/dir/?link=list&sid=396546091
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9838090
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by Dave Newton <ne...@yahoo.com>.
--- oguzhan tortop <og...@yahoo.com> wrote:
> At first catch i am expecting to handle exceptions
> that could be arise while
> creating the transaction and in the second try block
> i am commiting the
> transaction it gives error at the last final block
> side while commiting.
...but if the exception is happening on the commit
doesn't the code you have currently return the result
of the invocation rather than Action.ERROR?
d.
____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
At first catch i am expecting to handle exceptions that could be arise while
creating the transaction and in the second try block i am commiting the
transaction it gives error at the last final block side while commiting.
Dave Newton-4 wrote:
>
> --- oguzhan tortop <og...@yahoo.com> wrote:
>> Yes , i can see it clearly from console as far as i
>> guess when u call invocation.invoke() ; only the
>> result of action become target.
>
> Which HibernateException, the first one or the second
> one?
>
>> >> result = invocation.invoke();
>> >> [...]
>> >> catch (Exception e) {
>> >> hs.setRollBackOnly(true);
>> >> if (e instanceof HibernateException) {
>
> Just catch a HibernateException rather than doing an
> instanceof.
>
>> >> return Action.ERROR;
>> >> }
>> >> finally {
>> >> try {
>> >> hs.disposeSession();
>> >> return result;
>
> So will it return result (from the invocation) if
> *this* is the HibernateException being caught?
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Don't get soaked. Take a quick peek at the forecast
> with the Yahoo! Search weather shortcut.
> http://tools.search.yahoo.com/shortcuts/#loc_weather
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9837688
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by Dave Newton <ne...@yahoo.com>.
--- oguzhan tortop <og...@yahoo.com> wrote:
> Yes , i can see it clearly from console as far as i
> guess when u call invocation.invoke() ; only the
> result of action become target.
Which HibernateException, the first one or the second
one?
> >> result = invocation.invoke();
> >> [...]
> >> catch (Exception e) {
> >> hs.setRollBackOnly(true);
> >> if (e instanceof HibernateException) {
Just catch a HibernateException rather than doing an
instanceof.
> >> return Action.ERROR;
> >> }
> >> finally {
> >> try {
> >> hs.disposeSession();
> >> return result;
So will it return result (from the invocation) if
*this* is the HibernateException being caught?
d.
____________________________________________________________________________________
Don't get soaked. Take a quick peek at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by oguzhan tortop <og...@yahoo.com>.
Yes , i can see it clearly from console as far as i guess when u call
invocation.invoke() ; only the result of action become target.
joey-30 wrote:
>
> Are you sure you catch the HibernateException?
>
>
> On 4/4/07, oguzhan tortop <og...@yahoo.com> wrote:
>>
>>
>> hi all,
>> i am using struts2 with hibernate i have a basic form which inputs the
>> given
>> data via hibernate. I get the hibernate session from my custom hibernate
>> interceptor and from that interceptor i call the action which creates the
>> hibernate transaction with data from its form and after that i return the
>> success case from action but there is a finally statement in my hibernate
>> interceptor which commits the transaction that's data filled in my action
>> class. But for ex. if the data is exist in db before which means
>> duplicate
>> then it gives an error and when i get this error i return and
>> ACTION.ERROR
>> from my hibernate interceptor but what i see on the page is the SUCCESS
>> result from the action class. What could be the problem ? :) Any help
>> will
>> be usefull thanks for your support
>> Here is my default stack and action conf.
>> <interceptor-stack name="defaultStack">
>> <interceptor-ref name="exception"/>
>> <interceptor-ref name="servlet-config"/>
>> <interceptor-ref name="timer"/>
>> <interceptor-ref name="logger"/>
>> <interceptor-ref name="static-params"/>
>> <interceptor-ref name="params"/>
>> <interceptor-ref name="hibernate"/>
>> </interceptor-stack>
>>
>>
>> <action name="CreateService"
>> class="tr.com.mkk.admin.action.CreateServiceAction">
>> <result name="input" >
>> <param
>> name="location">/admin/createService.jsp</param>
>> </result>
>> <result name="success" >
>> <param
>> name="location">/admin/viewService.jsp</param>
>> </result>
>> <interceptor-ref name="validation"/>
>> <interceptor-ref name="validatorErrors"/>
>> <interceptor-ref name="defaultStack"/>
>> </action>
>> Here is my interceptor class :
>>
>> public String intercept(ActionInvocation invocation) throws Exception {
>> Action action = (Action)invocation.getAction();
>> if ( !(action instanceof BaseActionSupport) ) return
>> invocation.invoke();
>> if (null == factoryName || null == packageName)
>> throw new IllegalArgumentException("factoryName
>> and
>> packageName
>> parameters should be given \n" +
>> "check parameters in xml file
>> <param name='factoryName'> \n" +
>> "and <param
>> name='packageName'>\n");
>>
>> // adds factory to cache if not available
>> HibernateSessionFactory.addFactory(factoryName,
>> packageName,
>> extConfigFilePath);
>>
>> HibernateSession hs = new HibernateSession();
>> hs.setFactoryName(factoryName);
>> ((BaseActionSupport)action).setHibernateSession(hs);
>>
>> try {
>> result = invocation.invoke();//calls the action
>> here it creates
>> transaction data
>> }
>>
>> // Note that all the cleanup is done
>> // after the view is rendered, so we
>> // have an open session in the view
>>
>> catch (Exception e) {
>> hs.setRollBackOnly(true);
>> if (e instanceof HibernateException) {
>> LOG.error("HibernateException in
>> execute()", e);
>> return Action.ERROR;
>> }
>> else {
>> LOG.error("Exception in execute()", e);
>> throw e;
>> }
>> }
>>
>> finally {
>> try {
>> hs.disposeSession();//commits transaction
>> ,
>> and closes hibernate session
>> return result;//expected result when an
>> exception occurs with hibernate
>> operations
>> }
>> catch (HibernateException e) {
>> LOG.error("HibernateException in
>> dispose()", e);
>> return Action.ERROR;
>> }
>> }
>> }
>>
>> ---------------------Action
>> Class----------------------------------------------------------
>> public class CreateServiceAction extends BaseActionSupport {
>>
>> private Service service;
>>
>> public CreateServiceAction() {
>> service = new Service();
>> }
>>
>> public String execute() throws Exception {
>> ServiceManager.getInstance().createService(getSession(),
>> service);//gets
>> the hibernate session and sends it to the serviceManager object which
>> creates transaction
>> set("service", service);
>> return SUCCESS;
>> }
>>
>> public Service getService() {
>> return service;
>> }
>> }
>>
>> *********
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9835135
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9837507
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 exception problem
Posted by joey <re...@gmail.com>.
Are you sure you catch the HibernateException?
On 4/4/07, oguzhan tortop <og...@yahoo.com> wrote:
>
>
> hi all,
> i am using struts2 with hibernate i have a basic form which inputs the
> given
> data via hibernate. I get the hibernate session from my custom hibernate
> interceptor and from that interceptor i call the action which creates the
> hibernate transaction with data from its form and after that i return the
> success case from action but there is a finally statement in my hibernate
> interceptor which commits the transaction that's data filled in my action
> class. But for ex. if the data is exist in db before which means duplicate
> then it gives an error and when i get this error i return and ACTION.ERROR
> from my hibernate interceptor but what i see on the page is the SUCCESS
> result from the action class. What could be the problem ? :) Any help
> will
> be usefull thanks for your support
> Here is my default stack and action conf.
> <interceptor-stack name="defaultStack">
> <interceptor-ref name="exception"/>
> <interceptor-ref name="servlet-config"/>
> <interceptor-ref name="timer"/>
> <interceptor-ref name="logger"/>
> <interceptor-ref name="static-params"/>
> <interceptor-ref name="params"/>
> <interceptor-ref name="hibernate"/>
> </interceptor-stack>
>
>
> <action name="CreateService"
> class="tr.com.mkk.admin.action.CreateServiceAction">
> <result name="input" >
> <param
> name="location">/admin/createService.jsp</param>
> </result>
> <result name="success" >
> <param
> name="location">/admin/viewService.jsp</param>
> </result>
> <interceptor-ref name="validation"/>
> <interceptor-ref name="validatorErrors"/>
> <interceptor-ref name="defaultStack"/>
> </action>
> Here is my interceptor class :
>
> public String intercept(ActionInvocation invocation) throws Exception {
> Action action = (Action)invocation.getAction();
> if ( !(action instanceof BaseActionSupport) ) return
> invocation.invoke();
> if (null == factoryName || null == packageName)
> throw new IllegalArgumentException("factoryName and
> packageName
> parameters should be given \n" +
> "check parameters in xml file
> <param name='factoryName'> \n" +
> "and <param
> name='packageName'>\n");
>
> // adds factory to cache if not available
> HibernateSessionFactory.addFactory(factoryName,
> packageName,
> extConfigFilePath);
>
> HibernateSession hs = new HibernateSession();
> hs.setFactoryName(factoryName);
> ((BaseActionSupport)action).setHibernateSession(hs);
>
> try {
> result = invocation.invoke();//calls the action
> here it creates
> transaction data
> }
>
> // Note that all the cleanup is done
> // after the view is rendered, so we
> // have an open session in the view
>
> catch (Exception e) {
> hs.setRollBackOnly(true);
> if (e instanceof HibernateException) {
> LOG.error("HibernateException in
> execute()", e);
> return Action.ERROR;
> }
> else {
> LOG.error("Exception in execute()", e);
> throw e;
> }
> }
>
> finally {
> try {
> hs.disposeSession();//commits transaction ,
> and closes hibernate session
> return result;//expected result when an
> exception occurs with hibernate
> operations
> }
> catch (HibernateException e) {
> LOG.error("HibernateException in
> dispose()", e);
> return Action.ERROR;
> }
> }
> }
>
> ---------------------Action
> Class----------------------------------------------------------
> public class CreateServiceAction extends BaseActionSupport {
>
> private Service service;
>
> public CreateServiceAction() {
> service = new Service();
> }
>
> public String execute() throws Exception {
> ServiceManager.getInstance().createService(getSession(),
> service);//gets
> the hibernate session and sends it to the serviceManager object which
> creates transaction
> set("service", service);
> return SUCCESS;
> }
>
> public Service getService() {
> return service;
> }
> }
>
> *********
>
> --
> View this message in context:
> http://www.nabble.com/Struts-2-exception-problem-tf3525255.html#a9835135
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>