Example of client/servelt calling an Entity Bean(EJB 2.0)
Hi !!
Can somebody give any code of servlet or client calling an entity bean...please give any sample code... I am getting error while calling an entity bean in Servlet....
It says that the Jndi name not found
SERVLET CODE----------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import sfms.mtk.*;
import sfms.sec.*;
import java.util.*;
public class TestServletExample extends HttpServlet
SecDbSecUserHome home;
public void init(ServletConfig config)throws ServletException{
//Look up home interface
try
Properties props = new Properties();
System.out.println("Looking for Jndi ----->>");
InitialContext ctx = new javax.naming.InitialContext();
home = (SecDbSecUserHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("SecUserJndi"), SecDbSecUserHome.class);
System.out.println("Lookup is over ----->>");
catch (Exception NamingException)
NamingException.printStackTrace();
public void doGet (HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
MTKDataObject objDataObject = null;
PrintWriter out;
response.setContentType("text/html");
String title = "EJB Example";
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
try
System.out.println("*************STARTING NOW*************");
Collection coll = home.findAllUsers();
Iterator i =coll.iterator();
while(i.hasNext())
SecDbSecUserRemote remote = (SecDbSecUserRemote)i.next();
System.out.println("User ID "+remote.getUserId());
System.out.println("FirstName "+remote.getFirstName());
catch(Exception CreateException)
CreateException.printStackTrace();
out.close();
public void destroy()
System.out.println("Destroy");
javax.naming.NameNotFoundException: SecUserJndi not found
<<no stack trace available>>
*************STARTING NOW*************
java.lang.NullPointerException
at TestServletExample.doGet(TestServletExample.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:197)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:368)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:484)
PLEASE DO REPLY ME BACK (ASAP)
Bhumika
There should be some error in looking up the Jndi..
In weblogic server I have been using the following code:
try
Context ctx = getContext.getInitialContext();
HelloHome home = (HelloHome)ctx.lookup("MyHello");
Hello hello = home.create();
System.out.println(hello.display());
catch(Exception e)
System.out.println("Error :");
e.printStackTrace();
static String user = null;
static String password = null;
static String url = "t3://localhost:7001";
* Gets an initial context.
* @return Context
* @exception java.lang.Exception if there is
* an error in getting a Context
static public Context getInitialContext() throws Exception
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, url);
if (user != null)
System.out.println ("user: " + user);
p.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
p.put(Context.SECURITY_CREDENTIALS, password);
return new InitialContext(p);
this works fine in weblogic..
also check if ur classpath is ok..
Similar Messages
-
Can CMT Session Bean call BMP Entity Bean in WebLogic 6.0?
Hi
Does anybody successfully use CMT Session Bean calling BMP +CMT Entity bean in
WebLogic6.0? I have the following problem.
Any idea will be appreciated.
--Winston
Let's say we have a Session bean SB, it uses container to manage the transaction.
A method of SB will call an Entity Bean EB which adopts bean-managed persistence.
Both SB and EB use CMT and all of their methods use "required" in the descriptor
file.
1. If the connection con.getAutoCommit() is true in the EB, then the transaction
within SB cannot be rolled back as the ejbCreate() has already commit into the
database.
2. On the other hand if Connecton of EB con.getAutoCommit() is false, then container
cannot successfully commit the transaction from SB's method, as EjbCreate and
EjbStore() in EB are likely using the different database connections, which causes
EbjStore() fail and the following error message will be sent to the Console:
============================================================
"<Jul 9, 2001 4:16:48 PM PDT> <Error> <EJB> <Exception during commit of transacti
on transaction=(IdHash=7738920,Name = [EJB TraderBeanImpl.buy()],Xid=105:5e6719a
ded42e332,Status=Rolled back. [Reason = weblogic.utils.NestedRuntimeException:
E
rror writing from beforeCompletion - with nested exception:
[java.rmi.NoSuchObjectException: Exception from ejbStore:javax.ejb.NoSuchEntityE
xception: ejbStore: AccountBean (4003) not updated]],numRepliesOwedMe=0,numRepli
esOwedOthers=0,seconds since begin=0,seconds left=30,SCInfo[examplesServer]=(sta
te=rolledback),properties=({weblogic.transaction.name=[EJB TraderBeanImpl.buy()]
})): java.rmi.NoSuchObjectException: Exception from ejbStore:javax.ejb.NoSuchEnt
ityException: ejbStore: AccountBean (4003) not updated
at weblogic.ejb20.internal.EJBRuntimeUtils.throwRemoteException(EJBRunti
meUtils.java:57)
at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:364)
at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManag
er.java:211)
at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(Serv
erSCInfo.java:511)
at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(Se
rverSCInfo.java:78)
at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAn
dChain(ServerTransactionImpl.java:893)
at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(
ServerTransactionImpl.java:1229)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTran
sactionImpl.java:168)
at weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:2
01)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl.buy(TraderBeanEOI
mpl.java:37)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl_WLSkel.invoke(Tra
derBeanEOImpl_WLSkel.java:76)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:373)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:237)
at weblogic.rmi.internal.BasicRequestHandler.handleRequest(BasicRequestH
andler.java:118)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:17)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
--------------- nested within: ------------------
weblogic.utils.NestedRuntimeException: Error writing from beforeCompletion - wit
h nested exception:
[java.rmi.NoSuchObjectException: Exception from ejbStore:javax.ejb.NoSuchEntityE
xception: ejbStore: AccountBean (4003) not updated]
at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManag
er.java:220)
at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(Serv
erSCInfo.java:511)
at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(Se
rverSCInfo.java:78)
at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAn
dChain(ServerTransactionImpl.java:893)
at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(
ServerTransactionImpl.java:1229)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTran
sactionImpl.java:168)
at weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:2
01)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl.buy(TraderBeanEOI
mpl.java:37)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl_WLSkel.invoke(Tra
derBeanEOImpl_WLSkel.java:76)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:373)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:237)
at weblogic.rmi.internal.BasicRequestHandler.handleRequest(BasicRequestH
andler.java:118)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:17)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
--------------- nested within: ------------------
weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion
: sync = weblogic.ejb20.internal.TxManager$TxListener@356eb0
Error writing from beforeCompletion - with nested exception:
[weblogic.utils.NestedRuntimeException: Error writing from beforeCompletion -
wi
th nested exception:
[java.rmi.NoSuchObjectException: Exception from ejbStore:javax.ejb.NoSuchEntityE
xception: ejbStore: AccountBean (4003) not updated]]
at weblogic.transaction.internal.TransactionImpl.throwRollbackException(
TransactionImpl.java:1261)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTran
sactionImpl.java:218)
at weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:2
01)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl.buy(TraderBeanEOI
mpl.java:37)
at examples.ejb.basic.statefulSession.TraderBeanEOImpl_WLSkel.invoke(Tra
derBeanEOImpl_WLSkel.java:76)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:373)
at weblogic.rmi.internal.BasicServerAdapter.invoke(BasicServerAdapter.ja
va:237)
at weblogic.rmi.internal.BasicRequestHandler.handleRequest(BasicRequestH
andler.java:118)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:17)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>"
We did receive a 4.5.1 / 5.1 interoperability patch - but it wasn't quite 'seamless'.
We never tried to use it.
SOAP? Isn't that around 50 times slower than RMI?
Mike
"Gary Mui" <[email protected]> wrote:
We ran into this issue last fall and got some feedback from weblogic
support. They originally said that it could be done (as well as different
versions talking to one another via JMS) but it turned out that they
were
incorrect and ended up saying that it is not possible. Before 6.0 went
GA,
BEA said that there would be a interoperability patch to do this, but
I've
never seen nor heard of anything regarding it. As a workaround, we
implemented 4.5.1 / 6.0 communication via SOAP.
Mike Reiche wrote in message <3b1bcaec$[email protected]>...
I have the same question - and more. Last year we were told that wecould
not use
RMI (and ejbs) between 4.5.1 and 5.1. Which seems kinda weird becauseI've
heard
of people using WL ejbs from Tomcat. This issue has caused us to avoidusing
WL ejbs in any future development which has any chance of ever beingused
by any
app server (WL included) that is not under the direct control of thedata
center.
I've been trying to convince the Architecture team here that we canuse WL
EJBs
and we can call them from other app servers - but can't seem to getany
supporting
statement from BEA (maybe I haven't tried hard enough).
Anyway, a response from BEA would be appreciated.
- Mike
"Madhu K" <[email protected]> wrote:
Is it possible to call a (stateless session) bean deployed in weblogic
6.0
from a bean in weblogic 5.1? I have two versions of weblogic running
on two
different hosts and I have to call a bean that is running in 6.0 from
5.1.
Are there any limitations?
Appreciate any feedback/suggestions.
Thanks,
Madhu -
Insert data into table from JSP page using Entity Beans(EJB 3.0)
I want to insert data into a database table from JSP page using Entity Beans(EJB 3.0).
1. I have a table 'FRIENDS', (in Oracle 10g database).
2. It has two columns, 'NAME' and 'CITY'. Both have datatype strings(varchar2).
3. Now from a JSP page, having two textfields, 'NAME' and 'CITY', I want to insert data into table 'FRIENDS'.
4. In between JSP and database is a Entity Bean(EJB 3.0) and a stateless session bean.
5. I am using JDev as editor.
Please provide me code ASAP or link with similar example.
Thank you.
AnuragHi,
I am also trying that scenario. So u can
Post the jsp form data to a Servlet which will act as a Controller.
In the servlet invoke the business method.
Similar kind of app is in www.roseindia.net
Hope this would help u.
Meanwhile if u get any optimal solution, pls post it.
Thanks,
Happy Java Coding. -
Entity Bean EJB 2.0 Deployment error
Hi !!!
I am new in EJB .
I have developed an Entity Bean (EJB 2.0) and using IDE MyEclipse and JBoss Server.
while I deploying the Application I getting the following Exceptions :
--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:service=EjbModule,module=EntityExample.jar
State: FAILED
Reason: org.jboss.deployment.DeploymentException: No abstract accessors for field named 'id' found in entity class account.AccountEJB
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.j2ee:service=EjbModule,module=EntityExample.jar
State: FAILED
Reason: org.jboss.deployment.DeploymentException: No abstract accessors for field named 'id' found in entity class account.AccountEJB
can any one give suggetion on it what i am doing incorrect.
thanks in AdvanceThere should be some error in looking up the Jndi..
In weblogic server I have been using the following code:
try
Context ctx = getContext.getInitialContext();
HelloHome home = (HelloHome)ctx.lookup("MyHello");
Hello hello = home.create();
System.out.println(hello.display());
catch(Exception e)
System.out.println("Error :");
e.printStackTrace();
static String user = null;
static String password = null;
static String url = "t3://localhost:7001";
* Gets an initial context.
* @return Context
* @exception java.lang.Exception if there is
* an error in getting a Context
static public Context getInitialContext() throws Exception
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, url);
if (user != null)
System.out.println ("user: " + user);
p.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
p.put(Context.SECURITY_CREDENTIALS, password);
return new InitialContext(p);
this works fine in weblogic..
also check if ur classpath is ok.. -
How to use same transaction when calling CMP entity beans and DAO (JDBC)
We are currently using Weblogic 8.1 SP2 with an Oracle 10g database (using XA thin and non-XA drivers).
We have a session bean that invokes an entity bean and a DAO (data access object pattern) in order to add data in 2 separate tables (account and history). Rows are added to the first (account) table using a CMP Entity bean while inserts are done in the 2nd (history) table using a DAO. Here is some pseudo code:
addHistorySessionBean (trans-attribute="Required")
begin
Step #1 - call addAccountEntityBean (trans- attribute="Required")
Step #2 - call addHistoryDAO (get datasource, connection)
end
The 2nd table (history) has a foreign key constraint to ensure that the corresponding key exists in the first (account) table. Unfortunately, DAO inserts on the 2nd (history) table fail with a foreign key constraint violation (INTEGRITY CONSTRAINT VIOLATION - PARENT KEY NOT FOUND!) since they cannot see the row added to the 1st (account) table in step #1 by the CMP entity bean.
How does one ensure that all this is done in a single transaction ? It appears that the app server creates two seperate transactions (one for the session bean facade and the entity bean and a 2nd transaction (when we retrieve a connection using the same data source JNDI name) for the DAO.
A post on server side suggested using a "<resource-ref>" in the session bean to tie the two potentially separate transactions together, but that does not work for us. However, I am not sure if we are doing that correctly. After we define the resource ref in the session facade bean, do we use the resource ref "name" attribute to lookup the datasource or do we still lookup the datasource by JNDI name ? Do we need to define the resource-ref tag in the entity bean also ?
Does Weblogic allow using a single transaction for this type of a scenario ? How does one specify within Weblogic that the same transaction should be utilized by the entity bean and any subsequent DAOs?
People have also suggested that we defer constraint checking until the transaction(s) are committed but that sounds like a work acount without addressing this issue. Would postponing the constraint checking in Oracle cause any additional overhead ?
Any suggestions with specific examples or documentation on how to address this issue will be gratefully appreciated.Thanks for your suggestion. Unfortunately, this does not work since it appears that there are 2 separate transactions going on here. One, the original one initiated by the session bean and used by the entity bean and the other initiated by the DAO. Any other ideas appreciated.
Hi,
Try setting the delay-database-inserts tag to
ejbCreate in RDBMS descriptor file.
http://bernal/stage/wls/docs81/ejb/DDreference-cmp-jar
.html#1113981
vasanthi ramesh -
Client Program accessing J2EE entity Bean
I have trouble find my Course J2EE bean from a client. (The client
runs on the same computer but a different VM from the bean.)
In Glassfish (Sun Application Server Nine), I set up a simple
Container-Managed Entity Bean. I tried to access it from an external
client as described in the glassfish EJB
FAQ https://glassfish.dev.java.net/javaee5/ejb/EJB-FAQ.html
Here is the client program:
package RS;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import org.apache.xml.serialize.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import RS.CourseHome;
import RS.CoursePK;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import javax.rmi.*;
import java.util.Properties;
import Debug.*;
public class Client {
public static void main (String arg[]) throws IOException {
try {
InitialContext jndiContext = new InitialContext ();
Debug.P("jndic ongtext" + jndiContext);
Object o = jndiContext.lookup("RS.CourseHome");
Debug.P("looked up object "+o + "|"+o.getClass().getName());
RS.CourseHome home =
(RS.CourseHome)PortableRemoteObject.narrow(o,RS.CourseHome.class);
Debug.P("got home "+home);
Course C = home.create(1);
C.setName("blah");
CoursePK PK = new CoursePK();
PK.number=1;
C = home.findByPrimaryKey(PK);
Debug.P(C.getName());
catch (java.rmi.RemoteException re) {Debug.P("Remote Exception" + re.getMessage());}
catch (javax.naming.NamingException ne){Debug.P("Naming Exception"+ne.getMessage());}
catch (javax.ejb.CreateException ce){Debug.P("Create Exception"+ce.getMessage());}
catch (javax.ejb.FinderException fe){Debug.P("Finder Exception"+fe.getMessage());}
}Here is the error message:
Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow
(PortableRemoteObject.java:294)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at RS.Client.main(Client.java:26)The debugging indicates that I got the Initial Context
and got the object but the PortableObject.narrow failed:
jndic ongtextjavax.naming.InitialContext@1d85f79
looked up object IOR: (huge number deleted)
com.sun.corba.ee.impl.corba.CORBAObjectImplEarlier, I tried the version below, but based on the suggestion by Mr. Ebbert
in the forum started "Error When running the Client Program" by sree_devi,
I checked
the following. I went to "Jndi Tree Browsing" from the Administrative Console
and I found a "RS.CourseHome" entry under "ejb" I found RS.CourseHome there
but did not see the "Course" tghat I expected to see
Thus, I tried the version above:
package RS;
--- imports deleted for conciseness
import Debug.*;
public class Client {
public static void main (String arg[]) throws IOException {
try {
InitialContext jndiContext = new InitialContext ();
Object o = jndiContext.lookup("Course");
CourseHome home =
(CourseHome)PortableRemoteObject.narrow(o,CourseHome.class);
Course C = home.create(1);
C.setName("blah");
CoursePK PK = new CoursePK();
PK.number=1;
C = home.findByPrimaryKey(PK);
Debug.P(C.getName());
catch (java.rmi.RemoteException re) {Debug.P("Remote Exception" + re.getMessage());}
catch (javax.naming.NamingException ne){Debug.P("Naming Exception"+ne.getMessage());}
catch (javax.ejb.CreateException ce){Debug.P("Create Exception"+ce.getMessage());}
catch (javax.ejb.FinderException fe){Debug.P("Finder Exception"+fe.getMessage());}
}When I run it, I get the following Naming Exception: Course not found
I confirmed at the administrative console, that I have "Course" listed
under Enterprise Applications:
As per the ejb FAQ, I set up my $CLASSPATH so it starts as follows:
/opt/j2ee/SUNWappserver/lib/appserv-rt.jar:
/opt/j2ee/SUNWappserver/lib/javaee.jar:I also verifed in my domain.xml that the orb-listener-1, the default
naming service port was at 3700.
Here is the info on the Bean that I have running for both of the tries
at my Client code.
ejb-jar.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version="2.1">
<enterprise-beans>
<entity>
<description>Course</description>
<display-name>CourseBean</display-name>
<ejb-name>CourseBean</ejb-name>
<home>RS.CourseHome</home>
<remote>RS.Course</remote>
<ejb-class>RS.CourseBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>RS.CoursePK</prim-key-class>
<reentrant>false</reentrant>
<abstract-schema-name>Course</abstract-schema-name>
<cmp-field><field-name>number</field-name></cmp-field>
<cmp-field><field-name>name</field-name></cmp-field>
</entity>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<description>Everyone</description>
<role-name>everyone</role-name>
</security-role>
<method-permission>
<unchecked/>
<method>
<ejb-name>CourseBean</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>CourseBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Sun-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN"
"http://www.sun.com/software/appserver/dtds/sun-ejb-jar_2_1-1.dtd">
<sun-ejb-jar>
<enterprise-beans>
<name>CourseBean</name>
<ejb>
<ejb-name>CourseBean</ejb-name>
<jndi-name>Course</jndi-name>
</ejb>
<cmp-resource>
<jndi-name>jdbc/__default</jndi-name>
<create-tables-at-deploy>true</create-tables-at-deploy>
<drop-tables-at-undeploy>true</drop-tables-at-undeploy>
</cmp-resource>
</enterprise-beans>
</sun-ejb-jar>
Course.java
package RS;
import java.rmi.RemoteException;
public interface Course extends javax.ejb.EJBObject {
public String getName() throws RemoteException;
public void setName (String Str) throws RemoteException;
public int getNumber() throws RemoteException;
public void setNumber (int n) throws RemoteException;
CourseHome.java
package RS;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
public interface CourseHome extends javax.ejb.EJBHome {
public Course create(int id) throws
CreateException,RemoteException;
public Course findByPrimaryKey(CoursePK pk)
throws FinderException,RemoteException;
CourseBean.java
package RS;
import javax.ejb.EntityContext;
public abstract class CourseBean implements javax.ejb.EntityBean {
public CoursePK ejbCreate (int number) throws javax.ejb.CreateException{
this.setNumber(number);
return null;
public void ejbPostCreate (int number) {
public abstract String getName();
public abstract void setName (String str);
public abstract int getNumber ();
public abstract void setNumber (int number);
public void setEntityContext (EntityContext ctx) {}
public void unsetEntityContext() {}
public void ejbActivate () {}
public void ejbPassivate () {}
public void ejbLoad () {}
public void ejbStore () {}
public void ejbRemove() {}
}Laurence L. Leff, Ph.D. Associate Professor of Computer Science
Western Illinois University, 1 University Circle 61455, Pager: 309 367 0787
FAX 309 298 2302hi s-mcgowan,
"some other processing" comprises of printing of debug lines and publishing to the message queue using JMS. I added more debug lines so that i could see whats really happening... here is the result
myTableHome.create(...); <----------- no exception was thrown and it returned LocalMyTable object
print out "Insert successful"
print out "publishing message"
... publish message to message queue using JMS...
print out "Publish done"
... after few milliseconds...
java.sql.BatchUpdateException: Data exception -- row already exist in index PK_MYTABLE on table MYTABLE.
From the exception it seems like its doing a batch insert. So that seems to explain why the java.sql.BatchUpdateException is thrown few milliseconds after my call to myTableHome.create(...);
Is it possible to disable batch update / insert? how?
thanks in advance,
leigh -
Problem in calling single entity bean from other beans
Hi,
I am implementing session facade with SUN's J2EE 1.3 deploy tool for JBoss server.
I have a entity bean UserBean which creates users in database ( create() )and tells if user exists or not ( findByPrimaryKey() ).
Initially, I had implemented UserBean with remote interfaces. So, any servlet ( my client ) which needed to use UserBean would make a remote call to it. It was used by 5 different servlets.
Now I am going for Local interfaces. So, I am packaging UserBean with other beans which need it.
Problem is, if I package UserBean with , say , ChatLogsBean ( Stateless bean ), it works fine. But when I package it with WebLogsBean ( Stateless bean ) also and deploy all beans together, JBoss gives error messages that instances of UserBean are already created.
How should structure my beans sothat I can avoid these duplication problem ?
Present flow is as follow:
Servlet Stateless Bean Other beans
ChatLogs Servlet --> ChatLogsWrapper --> ChatLogsBean ( Stateless bean ) & UserBean( Entity bean )
WebLogs servlet --> WebLogsWrapper --> WebLogsBean ( Stateless bean ) & UserBean
WordLogs servlet --> WordLogsWrapper --> WordLogsBean ( Stateless bean ) & UserBean
All servlets are packaged into corresponding WARs.
ChatLogsWrapper , ChatLogsBean ,UserBean are packaged into 'ChatWrapper' JAR.
WebLogsWrapper , WebLogsBean , UserBean are packaged into 'webWrapper' JAR
and similarly for WordLogs.
Any help ?
Regards,
SurajI suggest you post to one of the forums on jboss.org. There should not be a problem AFAIK having remote and local interfaces to the same EJB. I assume that you gave these unique names (FooHome/FooLocalHome..etc...) for the home and remote interfaces and declared both in the ejb DD.
-
Help with exception calling cmp entity bean from session bean
Hi,
I know someone else posted a very similar problem recently but I think the root of my problem may be different.
This is the exception that I receive:
javax.transaction.TransactionRolledbackException: CORBA TRANSACTION_ROLLEDBACK 9998 Maybe; nested exception is:
org.omg.CORBA.TRANSACTION_ROLLEDBACK: vmcid: 0x2000 minor code: 1806 completed: Maybe
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:114)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at itsthes.security._SecurityManager_Stub.findUserRoles(Unknown Source)
at itsthes.security._SecurityManager_Stub.findUserRoles(Unknown Source)
at itsthes.security.servlets.SecurityUserListView.processRequest(SecurityUserListView.java:80)
at itsthes.security.servlets.SecurityUserListView.doGet(SecurityUserListView.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
Caused by: org.omg.CORBA.TRANSACTION_ROLLEDBACK: vmcid: 0x2000 minor code: 1806 completed: Maybe
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:94)
at com.sun.corba.ee.internal.iiop.LocalClientResponseImpl.getSystemException(LocalClientResponseImpl.java:120)
at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.java:133)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
at itsthes.security._SecurityManager_Stub.findUserRoles(Unknown Source)
... 17 more
This is my primary key implementation:
public final class SecurityUserKey implements java.io.Serializable {
public java.lang.Integer userId;
public java.lang.Integer roleId;
public java.lang.String emailAddress;
* Creates an empty key for Entity Bean: SecurityUser
public SecurityUserKey() {
* @see java.lang.Object#equals(java.lang.Object)
public boolean equals(java.lang.Object otherOb) {
if (this == otherOb) {
return true;
if (!(otherOb instanceof itsthes.security.entitybeans.SecurityUserKey)) {
return false;
itsthes.security.entitybeans.SecurityUserKey other = (itsthes.security.entitybeans.SecurityUserKey) otherOb;
return (
(userId==null?other.userId==null:userId.equals(other.userId))
(roleId==null?other.roleId==null:roleId.equals(other.roleId))
(emailAddress==null?other.emailAddress==null:emailAddress.equals(other.emailAddress))
* @see java.lang.Object#hashCode()
public int hashCode() {
return (
(userId==null?0:userId.hashCode())
^
(roleId==null?0:roleId.hashCode())
^
(emailAddress==null?0:emailAddress.hashCode())
My entity method invocation is this:
public Collection findUserRoles() {
Vector userCollection=new Vector();
try {
Context jndiContext = new InitialContext();
LocalSecurityUserHome home = (LocalSecurityUserHome) jndiContext.lookup(this.securityUserBean);
Iterator i = home.findAll().iterator();
while ( i.hasNext() ) {
LocalSecurityUser securityUser = (LocalSecurityUser)i.next();
SecurityUser sessionBean=mapLocalSecurityUser(securityUser);
userCollection.add(sessionBean);
} catch (javax.naming.NamingException e) {
System.err.println(e);
} catch (javax.ejb.FinderException e) {
System.err.println(e);
return userCollection;
If anyone could point me in the right direction that would be great.
thanks,
WilliamHi,
The Transaction Rollback exception may be due to the SystemException thrown in your findUserRoles() code which force the container to rollback the transaction. catch the generic exception in your findUserRoles() code and veriy what went wrong.
i hope this helps.
-ram -
Calling Local Entity Beans from another Application
Hi,
I packaged all my Local entity Beans in 1 single Application (APP1.EAR).
I then I have another Application (APP2.EAR) which is made of Session Beans which require access to the APP1 application.
I'm using this code to achieve this:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "manager");
env.put(Context.PROVIDER_URL, "ormi://<host>/APP1");
context = new InitialContext(env);
... (BeanLocalHome)context.lookup("java:comp/env/ejb/BeanLocal");
I get the Following Exception:
javax.naming.NameNotFoundException: java:comp/env/ejb/BeanLocal not found
1) is there any problem with this code?
2) can local interfaces be accessed by another Application (or can they be accessed only by the same application) ?
Regards.
giuseppe.Hi ,
thank you for your answer.
I'm still in trouble:
these are the steps:
App1.jar entity beans.
App2.jar Session bean.
I embedded the App1.jar into the App2.ear
dir :
App1.jar
App2.jar
application.xml (added the App1.jar)
then I added this in the ejb-jar.xml deployment descriptor for App2.jar
<ejb-link>../App1.jar#BeanName</ejb-link>
for each entity bean.
But I still get :
javax.naming.NameNotFoundException: java:comp/env/ejb/BeanNameLocal not found
java.lang.Object com.evermind.server.ApplicationContext.lookup(java.lang.String, boolean)
ApplicationContext.java:110
java.lang.Object com.evermind.server.ApplicationContext.lookup(java.lang.String)
ApplicationContext.java:66
java.lang.Object javax.naming.InitialContext.lookup(java.lang.String)
What am I missing ??
Thanks.
giuseppe. -
Bean Managed Entity Beans(EJB) using Tangosol.
I am trying to use Bean Managed Entity Beans using Tangosol Coherence.
The entity bean is currently configured in the weblogic-ejb-jar.xml with:
<max-beans-in-cache>200</max-beans-in-cache>
In the public void ejbLoad() method, I am calling the Tangosol Cache to load the entity bean.
If we have have more that 200 request coming at the same time, we get an OutOfMemoryError exception.
Is there anyway to overcome this limitation by somehow having the ejb cache to use the tangosol cache?
Thanks for any help in advance.
KrishanSo far, it's not immediately obvious to us what the exact problem is that you are seeing. It sounds like the VM would be using at least 200MB just for the application server's own internal cache, for example, and that you are also using Coherence within the application server to provide additional caching.
If possible, we should set up a phone call with you and your team, and we could get an engineer from our end to walk through your specific use case with you, so that we could understand what the exact technical challenge(s) is(are) in this particular application.
Peace.
p.s. You can email [email protected] directly to schedule a call. -
Error while using sybase trigger with the CMP entity bean,ejb version 2.1
Hi All,
I am using ejb version 2.1 and using entity bean (Transaction required) ,i am trying to update data in sybase(ver 12.3) database table
I am using session bean(Transaction required) to update the multiple entity beans in a while loop.It is working fine .But when i am trying to run it with the trigger which updates multiple tables in different sybase databases on update of each entity.Then it throws NoSuchEntityException and it rollback the whole transaction.
My trigger has only few simple update statements and the trigger runs fine without my CMP entity bean.is the CMP does not support the update triggers in sybase or is it the problem with the transaction.
Please help
Thanks
AnshuIf you can have a look at a cmp example in the samples that ship with the server. My guess is that the weblogic-ejb-jar.xml file is missing the <persistence-use> element which for 810 would look like:
<persistence>
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>7.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-use>
</persistence>
I seem to recall that the elements might be slightly different in structure for the wls700 version of the DTD, so please check that (I cannot, I'm at home and don't have everything here).
Give that a try and see if it doesn't solve your compilation failure.
Also, the compilation should not be throwing a null pointer exception in a case like that, I consider that to be a bug.
-thorick -
Entity beans(EJB 3.0) replication in IAS 10.1.3
Hi,
I have a application with webservices, having a few stateless session beans and a few entity beans. The application has to be deployed in a grid environment, on 2 machines.
My problem is that a change in an entity needs to be replicated on both machines. Right now, with the application deployed on 2 machines, in a load balanced non-cluster environment, I have stale data. I have reviewed the option of cache coordination, but the toplink essentials don't have this feature.
As a temp solution, one of the machines was stopped. Another option is to disable the entity beans cache completely, but that's not what I'm looking for.
I have done some digging in the documentation, and it's clear that stateful beans can be replicated in a clustered environment. In this configuration, are the entity beans replicated too?Thanks for your reply. I'm actually interested in the entities, not the web session. I need to make sure that the entities cache stays synchronized between the nodes.
Example:
I have entity "customer" for example.. I do an update from one of the nodes, changing the customer name, and do commit. This happens in node 1. I want to make sure that the node 2 knows this happened. -
Entity bean (ejb 3.0) refactoring problem
I didn't find a better method than regenerating an entity bean after modifying the table definition and renaming the class after deleting the old one.
I'm not sure i can delete the old class representing the entity bean before regenerating it without any effects into the others entity beans.
It work fine but still a little problem. The refactoring process didn't change the name of the entity bean into the select clauses into queynamed injection.I am facing a similar problem. Does JDeveloper 10g (10.1.3.3.0) provide an automatic process to update an Entity Bean definition when the underlying database table definition changes?
I also noticed that for JDeveloper to create all the relationships (i.e. @OneToMany, @ManyToOne) between multiple Entity beans, I need to create all the Entity beans together in one pass using the wizard. If two entities depend on each other, and not created together, JDeveloper will not create the relationships between them. Is there a way around that?
Thank you -
Call stateless session bean EJB 2.0 from Webdynpro Java UI
Hello,
Can someone please tell me asto how to call a stateless session bean EJB 2.0 from Webdynpro Java UI?
The NWDS version is 7.0.
Thanks and Regards,
AryaHi Aryadipta
Please check this pdfs
https://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b00917dc-ead4-2910-3ebb-b0a63e49ef10&overridelayout=true
Steps for calling stateless session bean in Webdynpro java
Go to NWDS -> open perspective ->j2ee
select EJB Module Project ->create a project with name
Open the Project -->RC on ejb-jar.xml -> Select new --> EJB
Give name to EJB Bean (First letter should be in capital letters)
select the type of bean as Stateless session bean and give the package name to store that EJB bean.
After that Expand ejb-jar.xml and then select the <projectEJB>
Double click on this on method tab double click you will get business method where we will create the methods for business logic
Double click on projectEJB and then RC on bean tab and write required business logic in bean window as follows(based on requirement we will design a business logic).
After writing the business logic go to project -> rebuild
Till now we have created one EJB jar file
then go to File-->Enterprise Application Project -->create a project (projectEAR)
After creating a project click on next-> here we will have ear projects and then we select specific project required for our application.(here select projectEJB)
After that Calculate EAR project will be available on j2ee explorer.
Right click on <Bean> here
select New->Web Service->give a name to webservice and select Default configuration type as simple SOAP
-->click next -> Finish.
That webservice and related are created in ejb-jar.xml .
Expand the ejb-jar.xml.and double click on < webservice>
RC ProjectEJB -> Build EJB Archive RC on CalculateEAR ->Build applicationarchive.
Expand the projectEAR->RC on CalculateEAR.ear->Deploy to J2EE Engine
Double click on calculateEAR.ear ->Webservice navigator tab ->we eill servers expand the node
select the specific WebService
Here we test the webservice by click on Test and test it.
After that go to Web dynpro perspective ->create one webdynpro Project and one component
RC on model> Select import Web Service model(last)>give model name and package
and select radio button as local file system or URL
Go to WSnavigator->copy the WSDL path and paste it in model WSDL path and click on finish.
from here onwards steps are same as that adaptive RFC model
Hope it helps
Thanks
Tulasi Palnati
Edited by: Tulasi Palnati on Aug 26, 2009 12:15 PM
Edited by: Tulasi Palnati on Aug 26, 2009 12:43 PM -
Also if I call the insert query from within the servlet it works fine. I have disabled global transactions. Am I missing something out ? Please
any help would be greatly appreciated.May be your servlet is not able to lookup the EJB. You can use some print statements and see whether lookup ok or not.
Just a guess.
Plese get back, if any queries.
Thanks,
Rakesh.
Maybe you are looking for
-
How to loop and read repeating table data of infoPath form in Visual studio workflow.
Hi, I am trying to read info Path form repeating table data in Visual studio workflow. could anyone elaborate me in brief how to loop through repeating table and read all rows value one by one in workflow. any help would be more then welcome. Thanks
-
I'm not sure if it's coincidence that it updated itself to 37.0, but it must be... When I click on Firefox both on Taskbar and on Desktop icon, it opens on the task bar, when I highlight the task bar it even shows that Firefox loaded Google (my defau
-
Safari 5.1.2 and Juniper Infranet Controller
My work place provides wireless with Juniper Infranet Controller but Safari 5.1.2 doesn't work with it. Safari is initially redirected to the proxy web site address on the controller but never shows a web page. I managed to work around this by usin
-
External Hard Drive - Time Machine & Windows
I recently bought a Macbook Pro. However I still have another laptop (w/ Vindows XP) I would like to use. Is it possible for me to use the same external hard drive (Westrn Digital My Book 500 GB) for backing up my pc from time to time and also as the
-
File to file scenario...in PI7.1
Hiiii..... Its my first file to file scenario...i finished al my design and Integration Builder work... In my Runtime workbench...in communiction channel monitoring i have started my sender and receiver communication channel no errors found over thr.