How to call a EJB method from Session bean method
Hi all,
I'm new to J2EE programming. I have a simple doubt .
I have already created a lookup method for EJB bean in Session bean .
My question is how to call a method of an ENTITY bean (say insertRow) from SESSION bean method(Say invoke_insertRow) .
Please provide me an example code .
Thanks in advance.
InitialContext ctx = new InitialContext();
GeneralEditor editor = (GeneralEditor) ctx
.lookup("GeneralEditorBean/remote");
GeneralService service = (GeneralService) ctx
.lookup("GeneralServiceBean/remote");
LanMu lm = new LanMu();
lm.setName("shdfkhsad");
editor.add(lm);
Similar Messages
-
How to call a Javascript function from backing bean without any event
Hi,
Someone knows how to call a Javascript function from backing bean without any event ?
thanksPlease review the following thread:
ADF Faces call javascript
Luis. -
Calling stored procedure from session bean method
I have a situation like this :
I have one method on a stateless session bean (and I mark this method as container managed transaction). For database related stuff, I am not using entity beans, I am using my own layer of OR mapping. This method does a lot of stuff and it involves many trips to the database, as a result of which the performance is very poor. I have identified certain pieces of functionality from this method which I think can be moved to stored procedures, while some of the functionality can still remain in the session bean method. So my scenario is like this :
session bean method start
store some data in tables(using my OR layer)
call the stored procedure
session bean method end
My question is :
Will the data that I am storing in tables from within the session bean method, be available to the code executing inside stored proc.
secondly, how do I sync the transcation which is being initiated by the container with the transaction under which the stored proc is executing or is it that the stored procedure code will also be executing under the container managed transcation.
Thanks
VimalHi Vimal,
Will the data that I am storing in tables from within
the session bean method, be available to the code
executing inside stored proc.There's only one way to find out (isn't there?)
secondly, how do I sync the transcation which is
being initiated by the container with the transaction
under which the stored proc is executing or is it
that the stored procedure code will also be executing
under the container managed transcation.Again, why not just "suck it and see!"
[Or is there some reason why you can't?]
As I interpret the EJB specification, if the transaction attribute for your session bean method is such that it starts a transaction, then that transaction will be terminated when the method completes -- and every operation that occurs within the framework of that method will be in the one transaction.
In other words, your database stored procedure should execute within the same transaction as your O/R mapping layer.
However, how OC4J behaves may not exactly follow what is written in the (EJB) specification. Hence I repeat, "try it and see for yourself".
Put it this way: as far as I know, the only way that your stored procedure would NOT see the changes made by your O/R mapping layer is if they both executed in separate transactions and the O/R mapping layer did not commit its changes before the stored procedure began its execution.
Hope this has helped.
Good Luck,
Avi. -
How to send message to MessageDrivenBean from Session bean in JDeveloper
HI I am trying to write a sample program using JDeveloper.
I am trying to do these steps
1) client class which gets Session bean and calls its method.
2) write Stateless Session bean with a method which gets MDB and sends message.
3) write Message Driven Bean ( which prints message recieved from Session bean )
Set up
=======
jms.xml
{JDevHome}\jdev\system9.0.5.2.1618\oc4j-config\jms.xml : changed jms.xml file and included
<topic name="Demo Topic" location="jms/theTopic">
<description>A dummy topic</description>
</topic>
<topic-connection-factory name="Demo Topic Connection Factory" location="jms/theTopicConnectionFactory">
<description>A dummy topic connection factory</description>
</topic-connection-factory>
orion-ejb-jar.xml:
edited MDB entry to
<message-driven-deployment name="MessageLogger"
destination-location="jms/theTopic" connection-factory-location="jms/theTopicConnectionFactory">
</message-driven-deployment>
Implementation
===============
In client class:
I am getting session bean like
Properties props = System.getProperties();
props.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY , "com.evermind.server.rmi.RMIInitialContextFactory");
props.put( javax.naming.Context.SECURITY_PRINCIPAL , "admin" );
props.put( javax.naming.Context.SECURITY_CREDENTIALS,"welcome");
props.put( javax.naming.Context.PROVIDER_URL ,"ormi://localhost:23891/current-workspace-app");
Context ctx = new InitialContext(props);
MySessionHome home = (MySessionHome)
javax.rmi.PortableRemoteObject.narrow(obj, MySessionHome.class);
This part works fine, and I am calling method on session bean created out of home.
In Session bean:
I want to get TopicConnectionFactory and tried these two ways:
a)
getting the context by setting new environemnt values like
Properties props = System.getProperties();
props.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY , "com.evermind.server.jms.EvermindConnectionFactory");
props.put( javax.naming.Context.SECURITY_PRINCIPAL , "admin" );
props.put( javax.naming.Context.SECURITY_CREDENTIALS,"welcome");
props.put( javax.naming.Context.PROVIDER_URL ,"ormi://localhost:9227/current-workspace-app");
Context ctx = new InitialContext( props);
When I try this,it is complaining that it cannot instantiate EvermindConnectionFactory.
I am not sure which factory class we have to use here.i tried all the Factory class in that package.but didn't worked.
next I used,
b)
tried to use default context in session bean to get MDB factory
String TOPIC_NAME="jms/theTopic";
String TOPIC_CONNECTION_FACTORY="jms/theTopicConnectionFactory";
TopicConnectionFactory connectionFactory = (TopicConnectionFactory)new InitialContext().lookup("java:comp/env/" + TOPIC_CONNECTION_FACTORY);
this gives
04/06/13 23:46:09 javax.naming.NameNotFoundException: jms/theTopicConnectionFactory not found in MySession
04/06/13 23:46:09 at com.oracle.naming.J2EEContext.getSubContext(J2EEContext.java:93)
this may be because JMS server runs on different port than other EJBs and have different namespaces.
Can any body give info,how we can make use of Message Driven bean from a Session Bean or from a JSP page or from a simple class inside JDeveloper.
Thanks in advance.
gopalHi,
There are some hints in this forum for how to do this.
I put together and make it working.
This example creates an MD Bean and have a simple message and a client class send messages to that bean.
Steps
=====
1)
a)in {JDev Home}\jdev\system9.0.5.2.1618\oc4j-config\jms.xml
<topic name="Demo Topic" location="jms/demoTopic">
<description>A dummy topic</description>
</topic>
<topic-connection-factory name="Demo Topic Connection Factory" location="jms/theTopicConnectionFactory">
<description>A dummy topic connection factory</description>
</topic-connection-factory>
b) in current project in orion-ejb-jar.xml
go to orion-ejb-jar properties and add these values there to MDB node
destination-location=jms/demoTopic
connection-factory-location=jms/theTopicConnectionFactory
2) create a dummy session bean and a dummy client for that session bean
This sets default configuration for the client application we write
doing so we do not need to set properties to get Initial context.It makes use of
{JDev Home}\jdev\system9.0.5.2.1618\oc4j-config\.client\jndi.properties
We can directly get Contexxt ctx = new InitialContext();
3) Create MDB and put this sample code in method
onMessage()
TextMessage tm = (TextMessage) msg;
try {
String text = tm.getText();
System.err.println("Received new message : " + text);
catch(JMSException e) {
e.printStackTrace();
4) go to properties for the MDB and set Destination to Topic
5) write Client code
Context ctx =new InitialContext();
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =
(TopicConnectionFactory) ctx.lookup("jms/theTopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
TopicConnection connection = factory.createTopicConnection();
// 3: Use Connection to create session
TopicSession session = connection.createTopicSession( false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
Topic topic = (Topic) ctx.lookup("jms/demoTopic");
// 5: Create a Message Producer
TopicPublisher publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
TextMessage msg = session.createTextMessage();
msg.setText("This is a test message from My Test Client!!! .");
publisher.publish(msg);
6) Run the server and run the client -
How to call a servlet in a Session Bean
Hi All
I have one servlet program.And i have One Sessionbean.
I want to call the servlet in the session bean.
I am using Runtime method in java to call the servlet by giving it's full
path as it's argument.
But it is not working fine.I don't know what is the Problem.
Bye
SatyamHi,
I don't know why you want to do that? You should be doing the other way round i.e. call your session bean from servlet.
I must say that servlets are presentation tier components and session beans are middleware components related to workflow.
HTH
VJ -
How to lookup a EJB 3.0 session bean which is deployed in WebLogic 10.3
Now Jdeveloper 11.1.1, is giving WebLogic server 10.3.
With internal WebLogic server, when I created a Sample client, it generated code as:
private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
return new InitialContext( env );
public static void main(String [] args) {
try {
final Context context = getInitialContext();
DefaultSession defaultSession = (DefaultSession)context.lookup("property-DefaultSession#com.vs.property.model.session.DefaultSession");
} catch (Exception ex) {
}How to update the above code to lookup the EJB 3.0 session beans with an external WebLogic server 10.3?
Is there any documentation available on how to install weblogic, troubleshoot, debug, WebLogic server 10.3?
regds
-rajuRaju,
Hi, to start, here is a tutorial on a quickstart web application using an EJB 3.0 stateless session bean that fronts a container managed EclipseLink JPA entity manager on WebLogic 10.3, you will find references there to other general WebLogic documentation.
[http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial]
using @EJB injection on the client instead of a JNDI lookup as below
[http://edocs.bea.com/wls/docs103/ejb30/annotations.html#wp1417411]
1) in your second env.put I noticed that your t3 port is 7101, I usually use the default 7001 - but It looks like this port is valid for the JDeveloper embedded version of WebLogic server runs - just verify that it matches the port of your server.
2) your name#qualified-name lookup looks ok. Verify that the jndi-name element is set in your weblogic-ejb-jar.xml for non injection clients like the following
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ApplicationService</ejb-name>
<jndi-name>ApplicationService</jndi-name>
3) as a test outside of your application - launch the WebLogic admin console and goto the testing tab of your bean in [Home > Summary of Deployments > "application" > "session bean name"
thank you
/michael : http://www.eclipselink.org -
Calling a web service from Session bean
Hi Experts,
Can anybody help in calling a web serivce frm a session bean's business method??
Hw do we do that?
I have one requirement where i want to send emails to set of users for which i have email sending web service ready.. How can i call it thru a session bean's business method???
Pls help,
Regards,
AmeyHi Amey,
This documents explains how to use an EJB as Web service endpoint: http://help.sap.com/saphelp_nwce10/helpdata/en/46/307a6c50094f09e10000000a114a6b/frameset.htm
I hope this helps.
Best regards,
Ekaterina -
How create EJB 2.1 Stateful Session Bean in a EJB 3.0 Session Bean
Hi All,
We have been developing on EJB 2.1. We are now adding a module on EJB 3.0.
How can we "create" a stateful session bean with create method signature similar to create(String id)?
We have tried
// this is the remote interface
@EJB AddressBean abean;
But not working
Any help will be appreciated.There is no explicit create() call for EJB 3.0 session beans. It doesn't really matter though
since you can accomplish the same thing by defining your own business method to act
as an initializer for whatever state you'd like. E.g.
@Remote
public interface FooInterface {
public void initialize(String id);
// ... other business methods
@EJB FooInterface fooRef;
fooRef.initialize("foo");
--ken -
How to call precedure in impl into java bean
Dear all,
i'm tried to call procedure at impl.java into java bean.
but, there is error which is it cannot find the root of this.getDBTranstation
any idea.
TQHi
Please tell me
How to call ethod in AppModuleImpl from other bean?
I have created method in AppModuleImpl
public String callFuncWithArgs(String p_company, String p_division, String p_user, String p_wrkord_type,
String p_service_type, String p_HOLD_CODE_TYPE) {
return (String)callStoredFunction(VARCHAR2, "WS_tran.Margin_TO_USER(?,?,?,?,?,?)",
new Object[] { p_company, p_division, p_user, p_wrkord_type, p_service_type,
p_HOLD_CODE_TYPE });
This method is working after run APPModule. But I want to call this method from SparesTEOImpl class and
public boolean validateUnitPrice(int unitprice) {
//want to call here AppModuleImpl
callFuncWithArgs(String p_company, String p_division, String p_user, String p_wrkord_type,
String p_service_type, String p_HOLD_CODE_TYPE) here
Please tell me how to call , I wrote in following ways but I got error...
public boolean validateUnitPrice(int unitprice) {
String margin=appImpl.callFuncWithArgs("00004","SDWSG", "S1","CSH", "SP","M");
System.out.println("Output"+margin);
return margin;
After that I got the following error.
Exception in thread "main" oracle.jbo.InvalidOwnerException: JBO-25301: Application module AppModuleImpl_0 is not a root app module but has no parent
at oracle.jbo.server.ComponentObjectImpl.getRootApplicationModule(ComponentObjectImpl.java:177)
at oracle.jbo.server.ApplicationModuleImpl.getDBTransaction(ApplicationModuleImpl.java:3656)
at model.AppModuleImpl.callStoredFunction(AppModuleImpl.java:128)
at model.AppModuleImpl.callFuncWithArgs(AppModuleImpl.java:160)
at model.SparesTEOImpl.validateUnitPrice(SparesTEOImpl.java:55)
at model.SparesTEOImpl.main(SparesTEOImpl.java:67)
Process exited with exit code 1.
Please tell me how to solve this problem... -
EjbHome method vs stateless bean method
Does the ejbHome<method> and stateless bean method share the same concept?
Hi,
Basically the ejbHome<Method> will be the call onto the home object and it inturn uses the bean to make a call where as the stateless session bean method will be a call onto the ejb object.
So in the client code making a call you just make a looup and call the ejbHome<method> whereas in case of stateless session bean , you need to make a lookup and create and then use the object.
Hope this helps...
Bhgaya -
NoSuchMethodException calling a session bean method from a web service
I am running on NetWeaver 6.40 SP10 on Windows.
I have a Java class (not a SessionBean) exposed as a web service where I invoke a session bean method with an argument that is another Java class (basically, just a JavaBean with some getters and setters). I am getting a strange reflection-related error when I invoke a session bean method. The exception I see is a 'java.lang.reflect.UndeclaredThrowableException', and if I unwrap it with 'ex.getCause()', I see 'java.lang.NoSuchMethodException: com.xx.ejb.PersistentObjectSBObjectImpl0.createR3Config(com.xx.common.R3Config)'
I have spent several days trying to come up with a testcase for this, but to no avail. The calling class is:
--- snip R3UpdateTest.java ---
package com.xx.server.webse;
import com.xx.ejb.*;
import com.xx.common.*;
import java.util.*;
import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
* @author william_woodward
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
public class R3UpdateTest {
public String createR3Config(String a, String b, String c,
String d, String e, String f) {
String retval = "success!";
try {
PersistentObjectSB poSB = getPersistentObjectSB();
R3Config r3cfg = new R3Config();
r3cfg.setR3HostName(a);
r3cfg.setR3SystemNumber(b);
r3cfg.setRfcUserName(c);
r3cfg.setRfcPassword(d);
r3cfg.setRfcClient(e);
r3cfg.setRfcLanguage(f);
poSB.createR3Config(r3cfg);
} catch (Exception ex) {
retval = "Exception: " + ex + ", Causing Exception : " + ex.getCause();
return retval;
* Private methods
private PersistentObjectSB getPersistentObjectSB() throws RemoteException, CreateException, NamingException {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
props.put(Context.PROVIDER_URL, "localhost:50004");
InitialContext ctx;
ctx = new InitialContext(props);
PersistentObjectSBHome poSBHome =
(PersistentObjectSBHome) javax.rmi.PortableRemoteObject.narrow(
ctx.lookup("xx.com/CMPOBEAR/PersistentObjectSBBean"),
PersistentObjectSBHome.class);
return poSBHome.create();
--- end R3UpdateTest.java ---
If I change the createR3Config() method to take an argument of class 'Object' instead of an argument of class 'R3Config', and then cast the object back into an R3Config in the method body, it all works fine.
Any clues, anyone?
Thanks,
- Bill
Message was edited by: Bill Woodward - Fixed some funky formattingSure, I can show them to you. They are very similar to a couple of non-DC classes/projects I put together to try and duplicate the problem.
First, the interface, PersistentObjectSB.java:
package com.xx.ejb;
import javax.ejb.EJBObject;
import com.xx.common.R3Config;
import java.rmi.RemoteException;
public interface PersistentObjectSB extends EJBObject {
* Business Method.
public void updateR3Config(R3Config r3Config) throws RemoteException;
* Business Method.
public void createR3Config(R3Config r3Config) throws RemoteException;
And the implementation, PersistentObjectSBBean.java:
package com.xx.ejb;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import com.xx.common.*;
import com.xx.interfaces.*;
* @ejbHome <{com.xx.ejb.PersistentObjectSBHome}>
* @ejbLocal <{com.xx.ejb.PersistentObjectSBLocal}>
* @ejbLocalHome <{com.xx.ejb.PersistentObjectSBLocalHome}>
* @ejbRemote <{com.xx.ejb.PersistentObjectSB}>
* @stateless
public class PersistentObjectSBBean implements SessionBean {
private R3ConfigEJBLocalHome _r3ConfigEJBLocalHomeIf = null;
public void ejbRemove() {
public void ejbActivate() {
try {
setEJBLocalHome();
} catch (NamingException e) {
throw new EJBException(e);
public void ejbPassivate() {
public void setSessionContext(SessionContext context) {
myContext = context;
private SessionContext myContext;
* Create Method.
public void ejbCreate() throws CreateException {
try {
setEJBLocalHome();
} catch (NamingException e) {
throw new CreateException();
* Business Method.
public void updateR3Config(R3Config r3Config) {
try {
R3ConfigPrimaryKey primKey = new R3ConfigPrimaryKey();
primKey.r3HostName = r3Config.getR3HostName();
primKey.r3SystemNumber = r3Config.getR3SystemNumber();
R3ConfigEJBLocal r3ConfigEJBLocal =
_r3ConfigEJBLocalHomeIf.findByPrimaryKey(primKey);
if (r3ConfigEJBLocal != null) {
r3ConfigEJBLocal.updateR3Config(r3Config);
} catch (Exception e) {
// What to do here?
* Business Method.
public void createR3Config(R3Config r3Config) {
try {
R3ConfigEJBLocal r3ConfigEJBLocal =
_r3ConfigEJBLocalHomeIf.create(r3Config);
} catch (Exception e) {
// What to do here?
private void setEJBLocalHome() throws NamingException {
Properties props = new Properties();
props.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sap.engine.services.jndi.InitialContextFactoryImpl");
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup("localejbs/R3ConfigEJB");
_r3ConfigEJBLocalHomeIf = (R3ConfigEJBLocalHome) (obj);
Thanks,
- Bill -
How do you call a java class from the main method in another class?
Hi all,
How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
Thanks
SI
Edited by: okun on May 16, 2010 8:40 PM
Edited by: okun on May 16, 2010 8:41 PM
Edited by: okun on May 16, 2010 8:47 PMgeorgemc wrote:
To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern. -
How to call one EJB in another EJB?
How to call one EJB in another EJB? Please explain with some example code.
To refer a Ejb from another Ejb include <ejb-ref> element in ejb-jar.xml
<session>
<ejb-name>EjbA</ejb-name>
<ejb-ref>
<ejb-ref-name>EjbB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.ejb.EjbBHome</home>
<remote>com.ejb.EjbB</remote>
</ejb-ref>
</session>
Include a <reference-descriptor> in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>EjbA</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>EjbB</ejb-ref-name>
<jndi-name>com.ejb.EjbBHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>
</weblogic-enterprise-bean>
In EjbA Bean class refer to EjbB with
a remote reference to EjbB.
InitialContext initialContext=new InitialContext();
EjbBHome EjbBHome=(EjbBHome)
initialContext.lookup("com.ejb.EjbBHome");
EjbB ejbB=EjbBHome.findByPrimaryKey(primarykey); -
Problem Calling Remote Session Bean Method
Need help. I am trying to call a method in a remote stateless session bean in an EJB in my web application from a stateless session bean in a different EJB in the web application. I am getting a run-time error that says,
"java.lang.NoClassDefFoundError: dtpitb.common.sb.reports.CommonReportsHome"
ref = ctx.lookup( jndiName );
// Cast to Local Home Interface using RMI-IIOP
commonReportsHome = (CommonReportsHome)
PortableRemoteObject.narrow(ref, CommonReportsHome.class);
If while in a session bean of an EJB, I want to call a public method in the session bean of a totally different EJB, is there something in particular I am missing. I can make the call from the web application code. I can make a remote call from this session bean to itself in the exact same fashion. I just can't call a session bean in another EJB. All thoughts are welcome.
Thanks,
PeteThanks for replying. That could very well be the case I suppose. I'm using JBuilder and WebLogic, and JBuilder pretty much does all of the deployment descriptor code for me. However, maybe this is something I need to incorporate manually.
One EJB is in the same project as the web application code. The other EJB (common_ejb) is in another project. The calling session bean is in the project with the web app, and the remote session bean method that I'm targeting is in the common EJB session bean. Both EJBs are included in the web app's WEB-INF\lib dir and in the war file.
So theoretically, this isn't an unconventional practice I assume?
Thanks,
Pete -
How to call two RFC in a single JAVA method.
Dear all,
I just want to know that how to call two RFC in a single java method which is defined in CRM implementation file. I'm using NWDS as the customization IDE & working on ISA 7.0.Hi Sunil,
In the Backend Implementation class, in any method you can call multiple RFCs.
It will be the same way as you do for the single RFC call.
Following syntax is for your reference.
Get the JCO connection
JCoConnection connection = getDefaultJCoConnection();
JCO.Function func = connection.getJCoFunction("ZXXXXXXX");
set the import parameters
Execute it.
connection.execute(func);
get the data from export / table parameters
Now call the second RFC
func = connection.getJCoFunction("ZYYYYYYYYYY");
set the import parameters
Execute it.
get the data from export / table parameters
close the connection
Hope this will help you.
-Chandra.
Edited by: Chandra Sekhar Seeli on Jan 13, 2011 2:04 PM
Maybe you are looking for
-
Unable to open query designer while able to access BI system
Hi Experts, I have problem while opening query designer, analyzer , WAD . I get the below error. But when i access the relevant BI system i am able to access it well , i dont get any RFC Error. Will there any port setting for query designer separa
-
How do i access iCloud from 4S?
how do i access iCloud from 4S?
-
At the end of a synch I am getting the following error message "iTunes could not back up the iPod because the backup could not be saved on the computer". Any ideas on how to resolve?
-
Yesterday I purchased the latest available 27inch iMac from my local Apple only dealer. ( It sure beats my very first Mac which was an LC520. ) The included in the box printed quick start guide named "Hello" was printed using a font size very clo
-
Creating a space between image and text
www.bristolequestrianservices.co.uk On my index page I have created another social media buttons on my page on my right side. Don't want to confuse people but the #social-media-icons2 are on my right side as I wanted to change the margins. I want a