When to use ejb-ref?
if i do not write <ejb-ref> in ejb-jar.xml,what will happen?the application
can not run or performance is low?
and is there any difference between bmp and cmp?i mean "does cmp need
<ejb-ref>?"
Ciao,
zhxt
In WLS you can have either global JNDI names that are visible throughout
the server or JNDI names that are local to your application.
The recommended best practice these days is to use ejb-refs and/or
ejb-links to lookup your EJBs. For local EJBs, you don't need to have a
global JNDI name since they are not visible to other applications.
-- Rob
scratchback wrote:
hi, I asked this last week but nobody answered it.
i am really curious about it and i checked some docs it said " it is useful
coz beans can look each other up without needing to initialize JNDI to any
particular driver".
i wonder what means particular driver and when there will be great
difference between using and not using.
thanx in advance
Ciao,
zhxt
Similar Messages
-
Have to ask again:when to use ejb-ref ?
hi, I asked this last week but nobody answered it.
i am really curious about it and i checked some docs it said " it is useful
coz beans can look each other up without needing to initialize JNDI to any
particular driver".
i wonder what means particular driver and when there will be great
difference between using and not using.
thanx in advance
Ciao,
zhxtIn WLS you can have either global JNDI names that are visible throughout
the server or JNDI names that are local to your application.
The recommended best practice these days is to use ejb-refs and/or
ejb-links to lookup your EJBs. For local EJBs, you don't need to have a
global JNDI name since they are not visible to other applications.
-- Rob
scratchback wrote:
hi, I asked this last week but nobody answered it.
i am really curious about it and i checked some docs it said " it is useful
coz beans can look each other up without needing to initialize JNDI to any
particular driver".
i wonder what means particular driver and when there will be great
difference between using and not using.
thanx in advance
Ciao,
zhxt -
When not using EJBs can I make BD a Singleton and cache facade instances?
Hi,
In an application which does not use EJBs can I make BD(Business Delegate) a singleton?
I was very sure about doing this but when I tried Google on the same subject the answers were'nt supportive of this but that was in the context of applications which used EJBs. And also item 4 in Effective Java isnt very supportive of caching Objects at the drop of a hat.
When not using EJBs would it be an unnecessary thing to make BD a singleton and cahce Facade instances in a BD and DAO instances in a Facade? I am planning to use a array based blocking bounded buffer for the purposes of caching. Or would it be better to make both BD and a facade as SIngletons and just cache DAOs in a Facade?
Any suggestion would be of good help to me.
Thanks a lot.Not sure I understand all your design, but you seem
to describe an architecture where requests are queued
and handled serially.Sorry if I messed up while explaining it. No, it will not be handled serially. Since the BD is a singleton multiple threads can pass messages to it simulteanously, a bit like an object of the Action class in Struts. Since I dont see having any synchronized methods in a BD requests will be handled simulteanously.
The impact on throughput of handling requests
serially (as opposed to parallelizing them) probably
outweights by far the cost of instantiating one more
object per request...Yes, I understand that but as I explained above the reqests wont be handled serially.
To be more clear, I am thinking of using any one of these two things:
1) BD(Singleton)-->Facade(Singleton, caches DAOs in a thread safe data structure)
2)1) BD(Singleton, caches Facade instances in a thread safe data structure)-->Facade(caches DAOs in a thread safe data structure).
the thread safe data structure I am planning to have is a array based bounded buffer which blocks using wait and notify mechanism.
Thank you for the reply. -
Hi !
I made an Entity bean for a master table, make its local interfaces and deploy it in a seperate jar.
Then i want to call this Entity bean thru any session bean using local interfaces and this session bean
is in a seperate jar file.
Right now its not working - i heard it can be used using <ejb-ref> tag.
Can anyone tell me what all entries do i need to make for this :
Do i need to write some code also for ti or only entries in deployment descriptor files will do ?
and what all entries do i need to make in deplyment descriptors or entity and deployment descriptors of session beans.
If somone has sample code then do please send across...
Thanks in advance !!I tried the thing :
I made an Entity Bean and a session bean in seperate jar files
The ejb-ref entries in session beans deployment descriptor files are ::
<ejb-local-ref>
<ejb-ref-name>ejb/EmpLocal</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>EmpHomeLocal</local-home>
<local>EmpLocal</local>
</ejb-local-ref>
Now, the code in session bean from where i am calling Entity bean is ::
InitialContext initialcontext = new InitialContext();
System.out.println("Initial Context created ");
home = (EmpHomeLocal)initialcontext.lookup("java:comp/env/EmpLocal");
System.out.println("After getting Local Home");
But its giving me the following error in Session Bean
Initial Context created
java.lang.ClassCastException: EmpEJB_1huw_LocalHomeImpl
Can, anyone help me to call an Entity bean's local methods from a Session bean - bith in seperate jar files -
Client using ejb-ref to lookup
Hi,
I read the docs, I searched for answers but there are still some things I don't
understand regarding a stand alone client application to a weblogic server 8.1
that could look up a bean using ejb-ref. I don't want to use the JNDI name.
There is the client-application.xml and the MyClientJar.runtime.xml but i'm not
sure I understand where to put them. I have the client-application.xml in my
client jar, the runtime.xml one in the same directory like specified in the
documentation, I tried to put the xml and the jar in my classpath and running
the client, no success the client cannot lookup using ejb-ref
I read that MyClientJar.jar should go in my ServerModule.ear so I did that too,
still doesn't work.
Something I'm not doing right or something I don't understand.
Any help or comments appreciated
Thank You
MaxHi,
I read the docs, I searched for answers but there are still some things I don't
understand regarding a stand alone client application to a weblogic server 8.1
that could look up a bean using ejb-ref. I don't want to use the JNDI name.
There is the client-application.xml and the MyClientJar.runtime.xml but i'm not
sure I understand where to put them. I have the client-application.xml in my
client jar, the runtime.xml one in the same directory like specified in the
documentation, I tried to put the xml and the jar in my classpath and running
the client, no success the client cannot lookup using ejb-ref
I read that MyClientJar.jar should go in my ServerModule.ear so I did that too,
still doesn't work.
Something I'm not doing right or something I don't understand.
Any help or comments appreciated
Thank You
Max -
Help needed - why we use ejb-ref element in ejb-jar.xml
hi all
can anyone tell me what is the purpose of this element in the ejb deploy descriptor? thanksSuppose u have bean A, which needs to look up another bean B. Normally you wud need to use the jndi lookup using the initial context to access the bean B's home interface. If you use ejb-ref element you dont need to know the JNDI name of bean B. You can use ejb-ref-name instead. So you can say this is a short cut method of looking up and getting a reference to a bean's home object.
-
Using ejb-ref tag for EJB toEJB reference
Hello all respected members,
I am using weblogic 5.1 (sp 9).
I have two Session EJBs - a client and another is the referenced by
the client.
The client is using services of the referenced EJB.
The two EJBs are in two very different packages.
Now say I am trying to deploy the client EJB first, without deploying
the referenced EJB.
What I expect (rather, want)is, when the client EJB is being deloyed,
it should give a notification somehow (let's say, by throwing an
exception) that the referenced EJB is not yet deployed.
First of all, is this possible ?
Secondly, I am aware of the of the <ejb-ref> tag. In order to meet my
requirement, I have added the same tag in the client's ejb-jar.xml and
corresponding <ejb-reference-description> tag in the
weblogic-ejb-jar.xml file.
When I start the weblogic server, I can see that the referenced EJB is
not deployed. But the client EJB is being deployed, it does not give
any notification that the referenced EJB is not yet deployed and gets
deployed successfully.
In other words, I expect <ejb-ref> tag to let me know that the
referenced EJB is not yet deployed. Is my understanding of <ejb-ref>
tag correct ?
It is clear to me that when the client EJB tries to instantiate the
referenced EJB to use its services, it would throw an exception
(during the lookup) since the referenced EJB is not deployed. But I
want to avoid this exception at this stage. I want to get a
notification of this, much before i.e. when the weblogic is deploying
my client EJB. I think the <ejb-ref> tag does this. Hence I am using
it.
If I am going in wrong direction, is there any other way to fulfil my
requirement ?
Please advise.
Neelesh.The <ejb-ref> element is used at deployment to map the bean references.
The beans referred to should already be deployed.
Neelesh wrote:
Hello all respected members,
I am using weblogic 5.1 (sp 9).
I have two Session EJBs - a client and another is the referenced by
the client.
The client is using services of the referenced EJB.
The two EJBs are in two very different packages.
Now say I am trying to deploy the client EJB first, without deploying
the referenced EJB.
What I expect (rather, want)is, when the client EJB is being deloyed,
it should give a notification somehow (let's say, by throwing an
exception) that the referenced EJB is not yet deployed.
First of all, is this possible ?
Secondly, I am aware of the of the <ejb-ref> tag. In order to meet my
requirement, I have added the same tag in the client's ejb-jar.xml and
corresponding <ejb-reference-description> tag in the
weblogic-ejb-jar.xml file.
When I start the weblogic server, I can see that the referenced EJB is
not deployed. But the client EJB is being deployed, it does not give
any notification that the referenced EJB is not yet deployed and gets
deployed successfully.
In other words, I expect <ejb-ref> tag to let me know that the
referenced EJB is not yet deployed. Is my understanding of <ejb-ref>
tag correct ?
It is clear to me that when the client EJB tries to instantiate the
referenced EJB to use its services, it would throw an exception
(during the lookup) since the referenced EJB is not deployed. But I
want to avoid this exception at this stage. I want to get a
notification of this, much before i.e. when the weblogic is deploying
my client EJB. I think the <ejb-ref> tag does this. Hence I am using
it.
If I am going in wrong direction, is there any other way to fulfil my
requirement ?
Please advise.
Neelesh. -
Question about when to use EJB
Hello All,
Right now, I am tasked with taking data out of the database and storing it on the mid-tier. We will be storing this static data in an XML file. We were hoping to read it in when starting the server and then persisting the data for the life of the server. Is this a good time to user EJB? All I have seen is examples using a database. We would like to take the database hit out of the equation when it comes to retrieving this data, but would also like to avoid parsing the XML doc every time someone logs in to the application. Is EJB a good answer here, or is it overkill?If this is for use as a read-only dictionary for supporting an EJB application, by all means.
But to use EJB just to do this - I think that would be overkill.
A singleton would do the job fine - especially if the XML doesn't change - actually even if it does that doesn't matter. -
When to use @Resource and when to use @EJB for dependency injection
Hi,
When do you use
@Resource and when do you use @EJB for dependency injection?
ThanksCaptain obvious: Use @EJB for injection of EJBs, and @Resource for everything else.
There was a discussion about this very topic quite recently, perhaps you can find it through the search. -
1) Does any one know where can I find documents that describe when EJBs should be used in an application? If I use a J2EE server like WebLogic, should I always try to use EJBS an my applications?
2)Once I have decided to use EJBs in an application, should there be an entity bean corresponding to every table in the database??
thanksHi
Well documentation can be found on sun's site and for EJB regarding the number based on table is not required.
I have a project which had around 30 Tables in it and we were using EJB's for it and had grouped EJB's based on table or functionality.
You could also make EJB's based on the tables logical grouping and can work it out.
Based on that you can define ur Interface.
Bye -
EJB3 newbie - when to use EJB?
If I just want to build a reusable module that does not have any business critical actions, such as a login module, or a blog module, should I use EJB?
Also, am I correct that only EJBs can run on distributed servers, and that all other non-EJB components in a web applications can only run on a single server?If I just want to build a reusable module that does
not have any business critical actions, such as a
login module, or a blog module, should I use EJB?
No. Any Java module can be made to be reusable, if designed to be so. Actually, by using EJBs, you'll be limiting the reusability of your modules, since those would need to run inside an EJB container.
Also, am I correct that only EJBs can run on
distributed servers, No, they can run in distributed as well as non-distributed environments.
and that all other non-EJB
components in a web applications can only run on a
single server?No. Not sure where you got that idea from. I think you're confusing multiple server environment (clusters) with distributed[i] business objects. You can cluster applications that collocate all their components in a single JVM.
There are actually very few cases where the use of EJB is to be considered (roughly 10% of cases):
- if you really need object distribution - this is not the norm
- if you need to use IIOP as the protocol for communication
- MDBs are a good solution for some applications heavily based on messaging -
Hi there
I just have the following question?
What requirement would make you use ejb's?Hi there
I just have the following question?
What requirement would make you use ejb's?A single requirement? "Requirement 5. The system must use ejbs."
(And I have seen a requirement that was basically like this.)
Other than that it certainly can't be done with a single requirement. -
Why string has an extra blank when I use EJB business method to get it
I have the following code:
Person bean = home.create("Jon", 10, "Huge", 1.0);
java.util.Enumeration result = home.findAll();
if (result.hasMoreElements()) {
Person bean1 =(Person) javax.rmi.PortableRemoteObject.narrow(result.nextElement(), Person.class);
getTraceWriter().println(" ** name = " + bean1.getName() + ", rank = " + bean1.getRank() +
", power = " + bean1.getPower() + ", rating = " + bean1.getRating());
bean1.remove();
I found the bean1.getName is "Jon " instead of "Jon". why???? Does sb. have a clue?
Thanks,
JSTHere is the code. Thanks very much!
import javax.ejb.*;
import java.sql.*;
import javax.sql.DataSource;
import java.util.Vector;
import java.util.Enumeration;
import javax.naming.Context;
public class PersonBean implements EntityBean {
public String name;
public int rank;
public String power;
public double rating;
public EntityContext context;
private DataSource ds = null;
private String user = "db2admin";
private String password = "db2admin";
* ejbCreate method
* @param name String The person name
* @exception javax.ejb.CreateException
public PersonKey ejbCreate(String name)
throws CreateException {
return ejbCreate(name, 0, "default", 0.0);
* ejbCreate method
* @param name String The person name
* @param rank int The person rank
* @param power String The person power
* @param rating double Rating of the person
* @exception javax.ejb.CreateException
public PersonKey ejbCreate(String name, int rank, String power, double rating)
throws CreateException {
if (name == null || name.length() == 0) {
throw new CreateException("Invalid parameter: name cannot be null");
else if (power == null || power.length() == 0) {
throw new CreateException("Invalid parameter: power cannot be null");
this.name = name;
this.rank = rank;
this.power = power;
this.rating = rating;
Connection con = null;
PreparedStatement ps = null;
try {
System.err.println("before getconnection");
con = this.getConnection();
System.err.println("after getconnection");
ps = con.prepareStatement("insert into TESTMEN values (?,?,?,?)");
ps.setString(1, name);
ps.setInt(2, rank);
ps.setString(3, power);
ps.setDouble(4, rating);
if (ps.executeUpdate() != 1) {
throw new CreateException("Failed to add (" + name + "," + rank + "," +
power + "," + rating + ") to database.");
PersonKey pk = new PersonKey(name);
return pk;
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
public void ejbPostCreate(String name, int rank, String power, double rating) {
// empty for now
public void ejbPostCreate(String name) {
// empty for now
* ejbFindPrimaryKey
* Find bean by primary key
* @return PersonKey Primary key object for the bean
* @exception FinderException
* @exception ObjectNotFoundException
public PersonKey ejbFindByPrimaryKey(PersonKey key)
throws FinderException, ObjectNotFoundException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
boolean found = false;
boolean multipleFound = false;
try {
con = this.getConnection();
ps = con.prepareStatement("select name from TESTMEN where name = ?");
ps.setString(1, key.name);
rs = ps.executeQuery();
found = rs.next();
if (found) {
multipleFound = rs.next();
if (!multipleFound) {
return key;
else {
throw new FinderException("Multiple objects found with name = " + name);
else {
throw new ObjectNotFoundException("Cannot find object with name = " + name);
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* setEntityContext method
public void setEntityContext(EntityContext context) {
this.context = context;
* unsetEntityContext method
public void unsetEntityContext() {
context = null;
* ejbFindAll method
* Find all the beans.
* @return java.util.Enumeration Enumeration of all beans
public Enumeration ejbFindAll(){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = this.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery("select * from TESTMEN");
Vector keys = new Vector();
while (rs.next()) {
keys.addElement(new PersonKey(rs.getString("name")));
return keys.elements();
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbActivate() method
public void ejbActivate() {}
* ejbPassivate method
public void ejbPassivate() {}
* ejbLoad method
public void ejbLoad() {
PersonKey pk = (PersonKey) context.getPrimaryKey();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = this.getConnection();
ps = con.prepareStatement("select * from TESTMEN where name = ?");
ps.setString(1, pk.name);
rs = ps.executeQuery();
if (rs.next()) {
name = pk.name;
rank = rs.getInt("rank");
power = rs.getString("power");
rating = rs.getDouble("rating");
else {
throw new EJBException("No record found in ejbLoad()");
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbStore method
public void ejbStore() {
Connection con = null;
PreparedStatement ps = null;
try {
con = this.getConnection();
ps = con.prepareStatement("update TESTMEN set " +
"name = ?, rank = ?, power =?, rating = ? where name = ?");
ps.setString(1, name);
ps.setInt(2, rank);
ps.setString(3, power);
ps.setDouble(4, rating);
ps.setString(5, name);
if (ps.executeUpdate() != 1) {
throw new EJBException("Failed in updating database in ejbSotre().");
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbRemove method
public void ejbRemove() {
Connection con = null;
PreparedStatement ps = null;
try {
con = this.getConnection();
ps = con.prepareStatement("delete from TESTMEN where name = ?");
ps.setString(1, name);
if (ps.executeUpdate() != 1) {
throw new EJBException("cannot remove by name = " + name);
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace(); -
When to use the EJB tier?
Could someone explain in simple and general terms when, say for a brand new application, you should or should not use the EJB tier over retaining everything in the web tier? Obviously it will depend on what the application is, but how so?
I generally use EJBs when i want propper transactional support in my webapps as you get lots of stuff thrown in ejbs thats saves me having to write code.
There are loads of reasons why you should / shouldnt use ejbs though so have a look at these for a bit more info.
When to use EJBs :
http://www.jguru.com/faq/view.jsp?EID=126400
or alternatively .....
When not to use EJBs
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=11&t=006707
Hope thats helps.
Gaz. -
Ejb-ref-mapping in orion-ejb.jar missing location attribute after deployment
I have noticed that on several of my entity beans that after deployment the <ebj-ref-mapping location="JNDIName" name="LocalName"/> is missing the location attribute. This causes any attempts to lookup the EJBHome for that EJB to fail because the path to the EJBHome in JNDI cannot be found (obviously!). The problem is that this causes me to manually edit the application-deployment/<app>/<ejb.jar>/orion-ejb.zml after each deployment via the admin.jar. This seems like a bug with OC4J and I am wondering if Oracle is aware/doing something to fix this?
I have noticed that the same problem exists for session beans, however, for some strange reason the EJBHomes can still be resolved in JNDI. In all cases the location in JNDI is different then the <ejb-ref-name> I used in the client EJB.
Example being I have an entity bean at com.foo.Foo and the session bean uses lookup("java:comp/env/ejb/Foo") it is still able to find the EJB even though the orion-ejb.xml looses the location attribute. If the case is an entity bean referencing another entity bean in the same fashion I get an error because the location attribute is missing.If the 'location' value is same as the 'name' value, then even though the location attribute is missing, it is ok and should work. If they are not the same, then you should have defined the ejb-link element in your ejb-jar.xml when defining this ejb-ref and that would make the location attribute appear in the generated orion-ejb-jar.xml.
If the referenced bean is from a different application (EAR), then you should have used the -parent option when deploying the application.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Kris Trujillo ([email protected]):
I have noticed that on several of my entity beans that after deployment the <ebj-ref-mapping location="JNDIName" name="LocalName"/> is missing the location attribute. This causes any attempts to lookup the EJBHome for that EJB to fail because the path to the EJBHome in JNDI cannot be found (obviously!). The problem is that this causes me to manually edit the application-deployment/<app>/<ejb.jar>/orion-ejb.zml after each deployment via the admin.jar. This seems like a bug with OC4J and I am wondering if Oracle is aware/doing something to fix this?
I have noticed that the same problem exists for session beans, however, for some strange reason the EJBHomes can still be resolved in JNDI. In all cases the location in JNDI is different then the <ejb-ref-name> I used in the client EJB.
Example being I have an entity bean at com.foo.Foo and the session bean uses lookup("java:comp/env/ejb/Foo") it is still able to find the EJB even though the orion-ejb.xml looses the location attribute. If the case is an entity bean referencing another entity bean in the same fashion I get an error because the location attribute is missing.<HR></BLOCKQUOTE>
null
Maybe you are looking for
-
We have a problem with our Java Web Start Application regarding the TLS certificate revocation check: The application is running on a server within a wide area network which is separated from the internet. The application users have access to the WAN
-
How many iOS devices can I use with my iTunes Store account?
Question about the number of devices i can add to an account Family of four - 1 desk top 3 macbook pros 3 ipads 4 iphones I am well over the number of devices i can add to my I Tunes account - how can i share movies and music with my family on all th
-
Mail doesn't send - javax.mail.MessagingException: 250
Hello all, I'm new to JavaMail. I actually started with it last night. I've successfully sent a number of messages, but I randomly get a strange exception for no apparent reason. If I run the exact same code several times, it will produce this error
-
Updated Web Services and Pageflow design view available via eclipse update
All, An eclipse update to Workshop for WebLogic Platform 9.2 is now available. The new features available in this update are listed below <b>Web Service Design View:</b> The web service Design View lets you design all of the major features of a web s
-
HT201364 Can I install Marvericks on a 2007 MacPro Tower running 10.7.5?
I'm trying to update the OS on my 2007 MacPro Tower to Marvericks. I'm running 10.7.5, but I can't seem to get the App Store to allow me to download Marvericks. Any suggestions?