Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

private method in stateless session bean  RSS feed

 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all
I have a doubt.Can we have private method in state less session bean which will be called from other method of the same session bean.If this is possible, is it a good approach.
PLz suggest
candy
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Candy,
yes u can have a private method defined only in your class implementing your SessionBean interface. Remember u cannot define the same method in the Remote class defination as it will give you an error while compiling the java class ie.
package seettest.ejb.stateless;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Slayer extends EJBObject
{
public SlayerResult playbuy () throws RemoteException;
public SlayerResult playsell () throws RemoteException;
private void displayall() throws RemoteException; //this statement wont compile and will throw an error while compiling
}
This will have only one advantage of not allowing the client to know/view the business method defined in the implementation class where the developer can actually code the business logic. Somewhat acting as a Business Delegate pattern.
HTH,
Seetesh
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Seetesh
Thats ok but i was reading somewhere on net that if this private method will be called then transaction will not get propagated.Transaction context will only propagate if a method is fired using local or remote interface.
What do you say because i am not sure.
THanks
candy
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Candy,
Currently the example I had coded was having
<trans-attribute>Required</trans-attribute> for all methods
Will alter my code to include the transaction in both public and private business method and let you know shortly.
Meanwhile inputs from all is appreciated.
Rgds,
Seetesh
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Candy,
i think you are right, that the transaction is not propagated to the private method, but to the call to the business method. So if you throw an exception in your private method back to the business method you still can
roll back the Transaction in which your stateless bean runs.
Hope that helps
Originally posted by candy varma:
HI Seetesh
Thats ok but i was reading somewhere on net that if this private method will be called then transaction will not get propagated.Transaction context will only propagate if a method is fired using local or remote interface.
What do you say because i am not sure.
THanks
candy
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!