Professional Documents
Culture Documents
Location: http://www.jguru.com/faq/EJB
Ownership: http://www.jguru.com/misc/user-agree.jsp#ownership.
EJB 1.1 is currently in Public Release 2, a non-final preliminary draft. Final release of
the specification is expect by the end of the 4th quarter.
EJB 1.1 requires support for entity beans, which ensures a more consistent
programming model across vendors. In addition, EJB 1.1 addresses many of the
ambiguities and loopholes found in the previous specification. Specific differences
between EJB 1.1 and EJB 1.0 are addressed in the FAQ entry What's different in
Enterprise JavaBeans 1.1.
EJB 1.0 was released as a final specification in March 1997 at JavaOne '97 in San
Francisco.
Several servers will avoid supporting EJB 1.1 until the new specification is finalized.
Those that do support EJB 1.1 are in beta or were just released. This make EJB 1.0
servers attractive, especially those that have been around a while. For this reason,
EJB 1.0 remains a viable choice for some EJB projects, but make sure you have a
transition plan to upgrade to EJB 1.1 servers when necessary.
Forward compatibly (going from EJB 1.0 to EJB 1.1) is a problem with EJB 1.0 which
is addressed in the FAQ entry Java:API:EJB:1.1: Does the new specification impact
forward compatibility
In Plain English:
Enterprise JavaBeans (EJB) is Sun Microsystems' specification for a distributed object
system similar to CORBA and Microsoft Transaction Server, but based on the Java
platform. EJB specifies how developers should build components that can be
accessed remotely and how EJB vendors should support those components. EJB
components, called enterprise beans, automatically handle transactions, persistence,
and authorization security, so that the developer can focus on the business logic.
EJB has two basic types of enterprise beans: Session and Entity. Depending on the
type of enterprise bean used, features like persistence, transactions, security, and
multiple concurrent access can be managed automatically.
The new type of JavaBeans introduced in EJB 2.0 are Message Driven Beans (MDB)
Enterprise JavaBeans has been adopted by most distributed object vendors and is
considered a standard for developing distributed object systems in Java. All EJB
vendors must implement the same EJB specification which guarantees a consistent
programming model across servers. In addition, because EJB is widely supported by
many vendors, corporations do not have to worry about vendor lock-in; enterprise
beans will run in any EJB compliant server.
Session beans can act as agents modeling workflow or provide access to special
transient business services. As an agent, a stateful session bean might represent a
customer's session at an online shopping site. As a transitive service, a stateless
session bean might provide access to validate and process credit card orders.
Session beans do not normally represent persistent business concepts like Employee
or Order. This is the domain of a different component type called an entity bean.
A stateful session bean is an enterprise bean (EJB component) that acts as a server-
side extension of the client that uses it. The stateful session bean is created by a
client and will work for only that client until the client connection is dropped or the
bean is explicitly removed.
Stateful session beans are usually developed to act as agents for the client,
managing the interaction of other beans and performing work on behalf of the client
application. An example is a shopping cart stateful session bean that tracks a client's
product choices and can execute a sale when requested. Below is partial example of
a stateful session bean that is used as a shopping cart.
In the example above the ShoppingCartBean keeps track of the Customer and the
items chosen by the client application. This is the bean's conversational state. Once
the client application is ready to execute a sale, the ShoppingCartBean manages the
interactions of the Customer, Product, CreditServer, and Order beans in a
workflow that results in a charge against the customers credit card and the creation
of a shipping order. The ShoppingCartBean behaves as an agent for the client
managing the interaction of these other beans, tracking chosen items, and executing
the sale. The below table identifies the beans types used in the ShoppingCartBean
example above.
Bean Name Bean Type
ShoppingCartBean Stateful Session
CreditService Stateless Session
Customer Entity
Product Entity
Order Entity
From the clients perspective only the Customer and ShoppingCart beans are visible,
because the client application works with the bean's remote interface while the bean
itself resides on the server. This means that the client need only be concerned with
the business methods made public by the ShoppingCartBean. Below is an example
of the client applications view of the ShoppingCartBean. (Note: The client interacts
with the beans remote interface not the bean itself. The remote interface is called the
ShoppingCart.)
Session beans like the shoppingCartBean only live as long as the client maintains a
connection. In other words, they represent some aspect of the client's current
session with the system and die when the client ends that session. Session beans are
generally not fault tolerant. A system failure or shut down will result in the death of
session bean and a loss of any conversation state it maintained prior to the failure.
(This is a conceptual lifecycle of a session bean. Some vendors can make them more
fault tolerant and longer lasting).
Stateless session beans are usually developed as a set of related and simple
services. Think of a session bean as a functional API where each business method
represents an isolated independent service. An example is a CreditService bean that
provides methods for making charges against different types of credit cards (MC,
Visa, Discovery, etc).
// persistent fields
public long customerNumber;
public Date lastActive;
public String lastName;
public String firstName;
// business methods
public PersonName getName( ){
return new PersonName(firstName, lastName);
}
public void setName(PersonName name){
lastName = name.getLastName();
fistName = name.getFirstName();
}
public Date lastActive( ){
return lastActive;
}
...
}
Note: Only a subset of the bean code normally implemented is shown here
for brevity. Ordinarily the bean would also implement special EJB specific
callback methods that are not important to this FAQ entry.
The ejbCreate( ) method is used only once in the life type of a bean identity when
its first created. In this case we initialize the bean with the customer's id number and
name. The lastActive value is set within the method. The ejbCreate( ) creates
and returns the customer bean's identity, which is called a primary key in EJB. A
primary key is a object that represents a unique identifier for a bean. In the case of
the Customer bean the primary key is the CustomerKey which is an object that
wrappers the customer's id. Primary keys can be as simple as a String value or more
be more complicated like a key that wraps several values that together represent a
unique index to the bean identity. Below is the definition of the CustomerKey object.
public CustomerKey(long l)
{
id = l;
}
public int hashCode( ) {
return (int)id;
}
public boolean equals(Object otherKey){
if(otherKey instanceof CustomerKey)
return ((CustomerKey)otherKey).id == this.id;
else
return false;
}
}
You will notice that the business methods do not exactly match the persistent fields.
This illustrates that the persistent state of the bean need not map exactly to the
business methods, which provides more flexibility in how components are designed.
For example, instead of having an accessor for lastName and firstName, the
Customer bean uses a serializable PersonName to pass this information to and from
the bean's client. In addition, you will have noticed that the lastActive can only be
read by a bean client. The bean itself is responsible for updating this value.
In addition to the business methods and the ejbCreate( ) methods there are a
number of notification methods that the bean container (EJB server) uses to alert
that bean that some significant event in its lifecycle is about to, or just has, occurred.
Of particular importance are the two notification methods (ejbLoad( ) and
ejbStore( )) used to alert the bean when its being synchronized with the database.
The behavior of these methods changes depending on whether the bean is designed
for BMP or CMP. This is investigated in more detail under the FAQ entries
Java:API:EJB:EntityBean:BMP and Java:API:EJB:EntityBean:CMP.
Something that has bothered me all along about Session and Entity beans is that
Entity beans are referred to as representing data. Rather, Entity beans should represent
concepts in my business domain (e.g. TradingCommunity or TradingHub), with the
database merely providing persistence for the business domain objects' state.
I could see Session beans being useful in the case of fat clients, but since our project
is all thin web clients I'm not even sure when I'd use a Session bean. E.g., in our
model a TradingHub "holds" TradingCommunities and can use findByXxx() methods
on the TradingCommunityHome as needed (e.g. if not already instantiated or not kept
in memory due to large #s of instances).
So, why would I pull business functionality out of these classes (e.g.
TradingHub.addCommunity() ) and put them into a Session bean? What have I gained
besides another class to maintain (and, which is bad, separation of behavior from the
class that should be responsible for it)?
Mark Lorenz...
Author: Chetan Gadgil (http://www.jguru.com/guru/viewbio.jsp?EID=435319),
Jun 7, 2001
This has annoyed me also. Entities should not be used as just "struct"s. Actually
putting the business logic in the entities solve many of management issues. The
new "EJBLocal" interface will also help avoiding fine grained objects on the
client side. This can still be achieved with the older spec by simply NOT returning
fine grained Entity beans to the client. The main business entity "knows" how to
hide contained entities when needed, anyway.
Re: Thx Richard; also thx for your EJB book. Something...
Author: Ed Page (http://www.jguru.com/guru/viewbio.jsp?EID=786586), Mar 7,
2002
Mark: I just read your book-OO SWD, A PG; I am a novice in your world and am
sincerely trying to learn. It is unusually and immensely readable! I wonder if you
could please compare/contrast for me your method with RUP, XP and the "agile"
methods?
When a CMP bean is deployed, the deployer uses the EJB tools provided by the
vendor to map the persistent fields in the bean to the database. The persistence
fields will be a subset of the instance fields, called container-managed fields, as
identified by the bean developer in the deployment descriptor.
In the case of a relational database, for example, each persistent field will be
associated with a column in a table. A bean may map all its fields to one table or, in
the case of more sophisticated EJB servers, to several tables. CMP are not limited to
relational database. CMP beans can be mapped to object databases, files, and other
data stores including legacy systems.
With CMP, the bean developer doesn't need to write any database access logic into
the bean, but bean is notified by the container when its state is synchronized with
the database. The container notifies the bean using the ejbLoad( ) and
ejbStore( ) methods.
The ejbLoad( ) method alerts the bean that its container-managed fields have just
been populated with data from the database. This gives the bean an opportunity to
do any post processing before the data can be used by the business methods. The
ejbStore( ) method alerts the bean that its data is about to be written to the
database. This give the bean an opportunity to do any pre-processing to the fields
before they are written to the database. The below bean code demonstrates how
these method might be employed on a Customer CMP entity bean.
// container-managed fields
public long customerNumber;
public String lastName;
public String firstName;
// business methods
public PersonName getName( ){
return name;
}
public void setName(PersonName name){
name = name;
}
// called just after container-managed fields are updated from
database
public void ejbLoad( ){
name = PersonName(firstName, lastName);
}
// called just before container-managed fields are written to
database
public void ejbStore( ){
lastName = name.getLastName( );
firstName = name.getFirstName( );
}
...
}
In the case of the Customer bean the ejbLoad( ) and ejbStore( ) are used to
wrapper the name fields (lastName and firstName) in a PersonName object which is
more user friendly for the bean client. The ejbLoad( ) method wrappers the fields
so that the getName( ) method access an up-to-date copy of the name data. The
ejbStore( ) method unwraps the name data and places them back into the
container-managed fields so that the database is updated with the most recent
changes.
The ejbLoad( ) and ejbStore( ) methods are typically called just before a
transaction begins and when a transaction is about to commit. This ensures that the
container-managed fields are synchronized with the database when the bean is in
use. Some EJB servers will optimize the container so that data is not written to the
database unless its dirty; that container-managed fields have been changed.
CMP is the most difficult EJB feature for vendors to support. It requires very
sophisticated tools for mapping bean fields to a data source and generating the
underlying stubs and skeletons to support this mapping. CMP, however, provide a
unique opporutnity for organizations developing distributed object systems. With
CMP, a shrink-wrapped bean ( a bean developed by a third party) can be deployed
and mapped into an organization's existing database. Obviously, this is an idyllic
scenario, but not unreasonable. CMP entity beans exemplify the spirit of component
technology; the reuse of components across projects, organizations, and industries.
Note: CMP beans use the ejbLoad( ) and ejbStore( ) callback methods differently than the Bean-
Managed Persistence (BMP) beans. See Java:API:EJB:EntityBean:BMP for details on how BMP beans use
these methods.
The ability to code an entity bean's persistence logic explicitly is important when the
EJB container's CMP features are insufficient to meet the needs of the entity bean.
Entity beans that need to synchronize their state with several data sources are
excellent candidates for BMP. So are beans that need to access to data sources
(possibly legacy systems) that are not supported by CMP. In addition, BMP bean are
often employed when a vendors CMP facilities are not sophisticated enough to handle
complex Object-to-Relational mapping.
The BMP bean manages its own persistence, but relies on the container to coordinate
its reads and writes so that persistence is accomplished in a transactional safe
manner. Coordination with the container is accomplished through two mechanisms:
The persistence callback methods (ejbLoad( ) and ejbStore( )); and the
Environment Naming Context (EJB).
The ejbLoad( ) and ejbStore( ) methods notify a bean that its time to read and
write data to the database respectively. In a BMP entity bean the code for reading
and writing data to the database is done within these methods. The ejbLoad( ) is
called at the beginning of a transaction, just before any business methods are
executed, and the ejbStore( ) is called at the end of a transaction just before its
committed. This keeps the bean state in perfect synchronization with transactions
being executed, without the bean developer having to explicitly manage the
transactional operations.
When JDBC is used to for persistence, the Environment Naming Context (ENC) is a
JNDI namespace that provides the bean with access to database connections (among
other things). The database connections obtained from the JNDI ENC are managed
by the container, so that they are automatically enrolled in transactions and pooled.
(The extent to which this is supported depends largely on the EJB vendor.) The
container may also manage other data source APIs, but JDBC is standard.
Below is an example of an entity bean, the Customer bean that is designed to use
BMP to synchronize its own state with a CUSTOMER table in the database.
// business methods
public PersonName getName( ){
return new PersonName(firstName, lastName);
}
public void setName(PersonName name){
firstName = name.getFirstName( );
lastName = name.getLastName( );
}
// called just before a business method can be invoked at the
beginning of a transaction
public void ejbLoad( ){
try{
javax.sql.DataSource ds =
(DataSource)jndiContext.lookup("java:comp/env/jdbc/Database");
java.sql.Connection con = ds.getConneciton( );
PreparedStatement ps =
con.prepareStatement("select lastname, firstname
from CUSTOMER where id = ?");
CustomerKey key = (CustomerKey)ejbContext.getPrimaryKey(
);
customerNumber = key.id;
ps.setLong(1, customerNumber);
java.sql.ResultSet result = ps.executeQuery( );
while(result.next()){
lastName = result.getString("lastname");
firstName = result.getString("firstname");
}
con.close();
}catch(Exception e){
throw new EJBException(e);
}
}
}catch(Exception e){
throw new EJBException(e);
}
}
...
}
Note: BMP beans use the ejbLoad( ) and ejbStore( ) callback methods differently than the
Container-Managed Persistence (CMP) beans. See Java:API:EJB:EntityBean:CMP for details on how CMP
beans use these methods.
Comments and alternative answers
Enterprise JavaBeans and JavaBeans are not the same thing; nor is one an extension
of the other. They are both component models, based on Java, and created by Sun
Microsystems, but their purpose and packages (base types and interfaces) are
completely different.
JavaBeans
The original JavaBeans specification is based on the java.beans package which is a
standard package in the JDK. Components built on the JavaBeans specification are
intraprocess components that live in one address space and are typically used for
Graphical User Interface (GUI) as visual widgets like buttons, tables, HTML viewers,
etc.
Enterprise JavaBeans
The EJB specification is based on the javax.ejb package, which is a standard
extension package. Components built on the EJB specification are interprocess
components that live in multiple address spaces as distributed object. These
components are used as transactional business objects that are accessed as remote
objects.
JavaBeans components are small-grained application bits. You can use JavaBeans to
assemble larger-grained components or to build entire applications. JavaBeans,
however, are development components and are not deployable components. You
typically do not deploy a JavaBean because a JavaBean is not a complete application;
rather, JavaBeans help you construct larger software that is deployable. And because
they cannot be deployed, JavaBeans do not need a runtime environment in which to
live. JavaBeans do not need a container to instantiate them, to destroy them, and to
provide other services to them because the application itself is made up of JavaBeans.
By way of comparison, the Enterprise JavaBeans (EJB) standard defines a component
architecture for deployable components called enterprise beans. Enterprise beans are
larger, coarser-grained application components that are ready to be deployed. They
can be deployed as is, or they can be assembled with other components into larger
application systems. Deployable components must be deployed in a container that
provides runtime services to the components, such as services to instantiate
components as needed.
I disagrre
Author: Iain Kerr (http://www.jguru.com/guru/viewbio.jsp?EID=981384), Nov 27,
2002
I think the former paragraph illustrates better. The key piece of understanding is
that a JavaBean runs in its own address spaces. I think its vital that this is
understood to fully understand JavaBeans.
Re: I disagrre
Author: capsvikas sharma
(http://www.jguru.com/guru/viewbio.jsp?EID=1110954), Aug 26, 2003
well guys its a comparision between Client side javabeans and EJB. Can we
compare server side javabeans with EJB
thanks
Vikas
coarser-grained
Author: praveen chandra (http://www.jguru.com/guru/viewbio.jsp?EID=1237281),
Apr 8, 2005
Hi,
Can you please exaplain what is coarser-grained and fine grained in detail with
examples? Thanks, Chandra
What is passivation and activation?
Location: http://www.jguru.com/faq/view.jsp?EID=1195
Created: Nov 22, 1999
Author: Richard Monson-Haefel (http://www.jguru.com/guru/viewbio.jsp?EID=16)
Passivation and activation are two phases of a resource management technique that
reduces the number of bean instances needed to service all clients. Passivation is the
process of disassociating a bean instance from its EJB object so that the instance can
be reused or evicted to conserve memory. Activation is the process of associating a
bean instance with an EJB object so that it can service a request. Beans are
passivated when there is a lull in their use and activated when the EJB object
receives a client request.
Unlike entity beans and stateless session beans, stateful session bean are usually
evicted from memory when they are passivated. This is not true of all vendors but
this view serves as good model for understanding the concepts of passivation in
session beans.
When a stateful bean experiences a lull in use -- between client invocations and
transactions -- the container may choose to passivate the stateful bean instance. To
conserve resources the bean instance is evicted from memory (dereferenced and
garbage collected). When the EJB object receives a new client request, a new
stateful instance is instantiated and associate with the EJB object to handle the
request.
Stateful beans maintain a conversational state, which must be preserved before the
bean instance is evicted from memory. To accomplish this, the container will write
the conversational state of the bean instance to a secondary storage (usually disk).
Only the non-transient serializable instance fields are preserved. When the bean is
activated the new instance is populated with the preserved state. References to live
resources like the EJBContext, DataSource, JNDI ENC, and other beans must also be
maintained somehow -- usually in memory -- by the container.
The javax.ejb.SessionBean interface provides two callback methods that notify the
bean instance it is about to passivated or was just activated. The ejbPassivate( )
method notifies the bean instance that it is about have its conversational state
written to disk and be evicted from memory. Within this method the bean developer
can perform operations just prior to passivation like closing open resources. The
ejbActivate( ) method is executed just after a new bean instance has been
instantiated and populated with conversational state from disk. The bean developer
can use the ejbActivate( ) method to perform operations just prior to servicing
client request, like opening resources.
excellent description..
Author: puru naktode (http://www.jguru.com/guru/viewbio.jsp?EID=36717), Apr 18,
2000
excellent description..
Even worse, if I do have some fields that are not serializable by design (say, from
security or performance reasons) - again, according to specifications "The container
may destroy an instance if the instance is not serializable after ejbPassivate."
Because serialization is checked dynamically we can have stateful instances just
simply destroyed by container if some instance variables happened not to be
serializable.
So, for transient by design fields instead of declaring them transient, we have to
assign them null in ejbPassivate() (to prevent EJB instance from being destroyed
when attempting to serialize), and in ejbActivate() we need to recreate these transient
fields ourselves.
EJB STATEFUL SESSION PASSIVATION
Author: bhanu kiran (http://www.jguru.com/guru/viewbio.jsp?EID=1039587), Dec
19, 2002
Since the state is stored in Hard disk if system/server crashes can we maintain the
state once it restored
How you gain access to UserTransaction objects varies depending on the type of
client. Enterprise JavaBeans provides two types of transaction management:
In other environments, for example, a web server that supports servlets and/or
JavaServer Pages (JSP), a JMS server, and others, you obtain a UserTransaction
object via JNDI. Of course, for a servlet to obtain a UserTransaction object, there
must be a JTS-capable server to deliver the object.
Typically, the server provides the JNDI look-up name either directly or via a system
or server property. For example, with the WebLogic server, you would use a code
segment similar to the following:
...
Context c = new InitialContext();
UserTransaction ut = (UserTransaction)
c.lookup("javax.jts.UserTransaction");
ut.begin();
// perform multiple operations...
ut.commit()
...
With J2EE implementations, you obtain the UserTransaction object with a code
segment similar to the following:
...
Context c = new InitialContext();
UserTransaction ut = (UserTransaction)
c.lookup("java:comp/UserTransaction");
ut.begin();
// perform multiple operations...
ut.commit()
...
If the environment provides the UserTransaction object via a system property, you
would use a code segment similar to the following:
...
String transName = System.getProperty("jta.UserTransaction");
Context c = new InitialContext();
UserTransaction ut = (UserTransaction) c.lookup(transName);
ut.begin();
// perform multiple operations...
ut.commit()
...
JNDI remote look-up names and property names vary, of course, across
servers/environment.
WebSphere 5.0
Author: Christoph Ernst (http://www.jguru.com/guru/viewbio.jsp?EID=1106402),
Aug 6, 2003
In WebSphere 5.0 the JNDI-Lookup works like
UserTransaction ut = (UserTransaction)
ctx.lookup("jta/usertransaction");
See e.g. http://www-
3.ibm.com/software/webservers/appserv/doc/v30/ae/web/doc/ent_beans/atswpgec.htm
The link above is a bit outdated (from WAS 3.0 documentation). Check the current Infocenter for detai
support in WAS 5.0:
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.websphere.base.doc/info/a
The lookup "jta/usertransaction" is still supported for J2EE apps with a spec level of 1.2 or lower. But
1.3 or later "java:comp/UserTransaction" is demanded.
From J2EE 1.3 specs: "The J2EE platform must provide an object
implementing the javax.transaction.UserTransaction interface to all web
components. The platform must publish the UserTransaction object in the
Java™ Naming and Directory Interface (JNDI) name space available to
web components under the name java:comp/UserTransaction."
Can I use the J2EE JNDI lookup even within a EJB container?
...thanks in advance
Keep in mind that even if the JTS implementation supports nested transactions, this
transaction manager-level support does not guarantee support for nested
transactions in an application. For example, the EJB 1.1 specification does not
support nested transactions.
One possible example would be a scenario in which a client needs to employ two (or
more) session beans, where each session bean is deployed on a different EJB server
and each bean performs operations against external resources (for example, a
database) and/or is managing one or more entity beans. In this scenario, the client's
logic could required an all-or-nothing guarantee for the operations performed by the
session beans; hence, the session bean usage could be bundled together with a JTA
UserTransaction object.
In the previous scenario, however, the client application developer should address
the question of whether or not it would be better to encapsulate these operations in
yet another session bean, and allow the session bean to handle the transactions via
the EJB container. In general, lightweight clients are easier to maintain than
heavyweight clients. Also, EJB environments are ideally suited for transaction
management.
In some situations, it's necessary for a (stateful) session bean to selectively control
which methods participate in transactions, and then take over the bundling of
operations that form a logical unit of work.
Good explanation
Author: Santosh Malpekar (http://www.jguru.com/guru/viewbio.jsp?EID=30121),
Mar 30, 2000
Good explanation
Comments
Author: Suresh S (http://www.jguru.com/guru/viewbio.jsp?EID=320716), Apr 10,
2001
If some scenarios would have given, it would be better to understand. Thanks
Yes, but with restrictions. By definition, a stateless session bean has no state; hence,
each method invocation must be independent. (The bean can be "swapped out"
between method invocations.) Thus, a stateless session bean can obtain a
UserTransaction object via the EJBContext using the getUserTransaction()
method, but it must start and finish each transaction within the scope of a method
invocation.
Bean Managed
Author: Rajeev Sharma (http://www.jguru.com/guru/viewbio.jsp?EID=334960), Feb
23, 2001
Bean Managed
How do you configure the transaction characteristics for a session bean with
container-managed transactions?
Location: http://www.jguru.com/faq/view.jsp?EID=2582
Created: Dec 14, 1999 Modified: 2000-08-24 18:55:27.106
Author: Jerry Smith (http://www.jguru.com/guru/viewbio.jsp?EID=9)
Re: Set it to what? Can we have some sample code for the...
Author: Damodara Rao (http://www.jguru.com/guru/viewbio.jsp?EID=428922),
May 26, 2001
Within one transaction one row has to be inserted in oracle database throuh CMP
EntityBean and the visibility of that row has to be made for inserting some other
row in some other table because of constraints.How to make it visible within the
transaction?
Re[2]: Set it to what? Can we have some sample code for the...
Author: selva raju (http://www.jguru.com/guru/viewbio.jsp?EID=594229),
Dec 23, 2001
I am not how you have the Entity Bean Design for that.But I think the
following will be the Solution for you. Create one Method in Session Bean
with the transaction Attribute as "Required" and call the Both the Entity Beans
from that method.Here I have assumed that you two different entity beans to
represent the two different tables.And specity the transaction attribute for the
create method of the Entity Beans as "Supports" or "Required".
It doesn't. Entity beans do not employ JTA transactions; that is, entity beans always
employ declarative, container-managed transaction demarcation. Entity beans, by
definition, are somewhat tightly coupled (via the EJB container and server) to a
datastore; hence, the EJB container is in the best position to manage transaction
processing.
Comments and alternative answers
No. One of the motivations for using a distributed component architecture such as
Enterprise JavaBeans is to free the business logic programmer from the burdens that
arise in multiprogramming scenarios.
It is true that calls to the bean instance's methods are serialized, however calls to the
entity
object are not. That means from the client's perspective calls to the methods can
occur concurrently.
The bean provider also has to be aware of and code for that.
For example, suppose you have a bean that has a qty field and a method called
updateQuantity.
Then you could define updateQuantity in the bean class as
However this could lead to incorrect behavior because the container is free to create
several
instances of the bean to process method requests. Calls to these methods (on two
different beans) can occur
concurrently and that is the problem. So for example each instance gets the qty from
the database
and could start out with the same qty. When the qty is decreased in each of two calls
in two
transactions each bean would decrease it's qty and store it back to the database. Here
is a better picture,
This of course is the wrong answer. I should store -1 into the db.
There is a common misconception that since the container serializes calls to the bean
instance that calls to the bean object are serialized. Hence the programmer must
either serialize calls to the object or must use features of the database to handle the
above situation. Serializing calls to the entity and session objects does not happen
automatically. For session objects the container will throw an exception if the calls
happen concurrently. Even many companies that develop ejb servers hold these
misconceptions.
While EJB 1.1 provides the JNDI ENC for managing standard resources like URL,
JDBC, JavaMail and JMS, connections to other types of resources are not addressed
by EJB 1.0 or EJB 1.1, but there are solutions. Below is a list of some strategies that
can provide access to "back-ends" besides relational databases.
This strategy works in stateless session beans and entity beans in EJB servers that
pool and reuse these bean types. In stateless beans you can simply reference the
resources using the instance fields -- stateless beans are not passivated in EJB. In
entity beans you can also reference the connections using instance fields but the field
used must not be declared as a container-managed field in the deployment
descriptor.
In both stateless and entity beans there are methods can be used safely to open and
close resource connections at the beginning and end of the beans life.
With stateless and entity beans the above strategy, Leveraging the instance fields
works well with this strategy.
JNDI references:
It may be possible to access a JNDI service directly from the bean and to attach live
resources to the JNDI service. This depends on the JNDI service provider and your
EJB vendor.
Re: this is also a good idea but i want to know how you...
Author: sridhar yeragorla (http://www.jguru.com/guru/viewbio.jsp?EID=507726),
Oct 1, 2001
Hi chkraborty, now javatlb is outdated. we got a separate integration toll jactivex.
you can enter the name jactivex in msdn search and get the step by step procedure.
Re[2]: this is also a good idea but i want to know how you...
Author: Sarit Seal (http://www.jguru.com/guru/viewbio.jsp?EID=1005041),
Sep 27, 2002
You can have a Com Client a C++ program and then connect to java class
using JNI.
CMP in beans depends a lot on the EJB vendor implementation and utilities. With
some implementations container-managed entity beans can only by mapped to one
table, while other implemenations offer Multiple table mappings to a single bean. The
bottom line,It depends on the container provider being used.
Comments and alternative answers
Depends on what you mean by "persisted". Data that is part of a transaction like
database rows are persisted depending on the success of the transaction. If the
transaction manager determines that the transaction was successful or there were no
problems during any of the steps invoved in it, the data is committed, or otherwise
rolled back.
The container, on the other hand, invokes certain state transition lifecycle methods to
conserve resources. This involves passivation and activation of the bean or instance
swapping. This happens independent of the transaction since the client never
interacts directly with the bean instance but with the server's implementation of the
EJBObject.
Comments and alternative answers
The data is written to the database after every change (which means potentially after
every method call), but in a state determined by the transaction level. Later, when the
transaction is complete, the data may be committed or rolled back.
The following is a code snippet that demonstrates how a JSP page can interact with
an EJB session bean:
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//declare a "global" reference to an instance of the home interface of
the session bean
AccountHome accHome=null;
this all is very exiting ...can you just give the ...
Author: pinak vedalankar (http://www.jguru.com/guru/viewbio.jsp?EID=269419),
Mar 15, 2001
this all is very exiting ...can you just give the example of the above case... any one ex
...in which jsp page calls java bean and which in turn called EJB
What are all the different kinds of servers? (Such as Web Servers,
Application Servers, etc)
Location: http://www.jguru.com/faq/view.jsp?EID=5917
Created: Jan 20, 2000 Modified: 2000-12-20 10:06:49.031
Author: Paul Danckaert (http://www.jguru.com/guru/viewbio.jsp?EID=5801)
The servers involved in handling and processing a user's request break down into a
few basic types, each of which may have one or more tasks it solves. This flexibility
gives developers a great deal of power over how applications will be created and
deployed, but also leads to confusion over what server is able to, or should, perform
a specific task.
The web server may need to execute an application in response to the users request.
It may be generating a list of news items, or handling a form submission to a guest
book. If the server application is written as a Java Servlet, it will need a place to
execute, and this place is typically called a Servlet Engine. Depending on the web
server, this engine may be internal, external, or a completely different product. This
engine is continually running, unlike a traditional CGI environment where a CGI
script is started upon each request to the server. This persistance gives a servlet
connection and thread pooling, as well as an easy way to maintain state between
each HTTP request. JSP pages are usually tied in with the servlet engine, and would
execute within the same space/application as the servlets.
There are many products that handle the web serving and the servlet engine in
different manners. Netscape/iPlanet Enterprise Server builds the servlet engine
directly into the web server and runs within the same process space. Apache requires
that a servlet engine run in an external process, and will communicate to the engine
via TCP/IP sockets. Other servers, such as MS IIS don't officially support servlets,
and require add-on products to add that capability.
When you move on to Enterprise JavaBeans (and other J2EE components like JMS
and CORBA) you move into the application server space. An Application Server is
any server that supplies additional functionality related to enterprise computing -- for
instance, load balancing, database access classes, transaction processing,
messaging, and so on.
EJB Application Servers provide an EJB container, which is the environment that
beans will execute in, and this container will manage transactions, thread pools, and
other issues as necessary. These application servers are usually stand-alone
products, and developers would tie their servlets/JSP pages to the EJB components
via remote object access APIs. Depending on the application server, programmers
may use CORBA or RMI to talk to their beans, but the baseline standard is to use
JNDI to locate and create EJB references as necessary.
Now, one thing that confuses the issue is that many application server providers
include some or all of these components in their product. If you look at WebLogic
(http://www.beasys.com/) you will find that WebLogic contains a web server, servlet
engine, JSP processor, JMS facility, as well as an EJB container. Theoretically a
product like this could be used to handle all aspects of site development. In practice,
you would most likely use this type of product to manage/serve EJB instances, while
dedicated web servers handle the specific HTTP requests.
See also: What is the difference between an Application Server and a Web Server?
http://serverwatch.internet.com/webservers.html
how to decide up on the which servlet enebled web server to use for developing a web
based application ?
The EJB 1.1 Specification, section 18.1.2 (Programming Restrictions) lists some
things that enterprise beans cannot do. In particular:
This function is reserved for the EJB Container. Allowing the enterprise bean to load
native code would create a security hole.
They cannot access JNI portably. Basically, given comments recently made by Mark
Hapner, it seems that the "must not" is not a hard constraint but rather a "must not do
if you want the EJB to be portable."
Certainly, IMHO, the security issue trumps the portability issue so it's a moot point.
:-)
Also, not that it's relevant to security but, I was planning on having my EJB call out to
other java classes which contained the static loading and native method calls. Any
reason why this wouldn't work?
Thanks.
The reason why the EJB spec does not supports this...
Author: harish ganesan (http://www.jguru.com/guru/viewbio.jsp?EID=347623), Mar
8, 2001
The reason why the EJB spec does not supports this interface to native libraries is
that: 1.The EJB compoenents we develop should be in intention of true distribution
2.the application developers should not develop bean components that are not
resuable and portable to different EJb containers because it ties u up to single ejb
vendor
I have to create an EJB for a system that's accessible through a C library. My initial
reaction was to create a JNI implementation of the client interface, called by the EJB.
But this means it won't be portable, though from the comments here it might still
work.
I was faced with the issue of calling a native application from an EJB on a recent
project. In the process of investigating various alternatives, we attempted using JNI
(under WebLogic 5.1 running on Solaris 2.7). It worked, at least in that WebLogic
allowed it to happen and the calls worked. However, in testing the robustness of the
solution we had the native code perform a divide-by-zero. The resulting exception
crashed WebLogic.
So even if your particular application server allows the EJB to load and call a native
library, and even if you don't care about portability or security (and I'm not sure I
understand the security issue here), you better really trust your C code 'cause it's not
just going to take down a single transaction.
Also, an earlier response asked about having a non-EJB class do the loading of the
native library. The EJB spec states that the restrictions on EJBs apply to all classes
running in the EJB container. So it's all the same.
BTW, we solved our issue by modifying the native application to run as a persistent
service and then communicated with it through a socket. If you do this, the native app
has to be the socket listener as EJBs aren't allowed to listen to ports (for obvious
reasons).
The file system APIs are not well-suited for business components to access data.
Business components should use a resource manager API, such as JDBC API, to
store data.
Alternative Solutions
To perform logging operations you must you a resource connection supported by the
EJB programming model. EJB servers may support several resource connection
options, which can be used to log events as shown below:
I think the reasoning behind the restriction is that there's an assumption that the file
access storage/retrieval must be transactionable and the file system isn't. Writing the
System.out isn't really the same as storing data, so you could argue that it doesn't
violate the restriction.
You could argue this one either way and I'd like to see Sun clarify it. I have noticed
that several of Sun's example EJB's make use of System.out, though, which leads me
to believe that it's legal.
• Logging to System.out is not forbidden by the ejb spec so at least for that
log4j is usable.
• I will also log to files. I know this does violate the EJB spec, but certain
parts of EJB spec can be broken without too many problems. And I can
always switch off logging to files if it turns out to mess things up.
i.e. I want to have a sessionid in every log entry, but dont want to have to make this a
parameter of every call. One option may be to use the caller principal, since I dont
actually require the use of this for security.
http://jakarta.apache.org/commons/logging/
java.util.logging
http://java.sun.com/j2se/1.4/docs/guide/util/logging/
Protomatter Syslog
http://protomatter.sourceforge.net/
What is a container?
Location: http://www.jguru.com/faq/view.jsp?EID=9876
Created: Jan 29, 2000
Author: Richard Monson-Haefel (http://www.jguru.com/guru/viewbio.jsp?EID=16)
Enterprise beans are software components that run in a special environment called
an EJB container. The container hosts and manages an enterprise bean in the same
manner that a Java WebServer hosts a Servlet or an HTML browser hosts a Java
applet. An enterprise bean cannot function outside of an EJB container. The EJB
container manages every aspect of an enterprise bean at run time including remote
access to the bean, security, persistence, transactions, concurrency, and access to
and pooling of resources.
The container isolates the enterprise bean from direct access by client applications.
When a client application invokes a remote method on an enterprise bean, the
container first intercepts the invocation to ensure persistence, transactions, and
security are applied properly to every operation a client performs on the bean. The
container manages security, transactions, and persistence automatically for the bean,
so the bean developer doesn't have to write this type of logic into the bean code
itself. The enterprise bean can focus on encapsulating business rules, while the
container takes care of everything else.
Containers will manage many beans simultaneously in the same fashion that a Java
WebServer manages many Servlets. To reduce memory consumption and processing,
containers pool resources and manage the lifecycles of all the beans very carefully.
When a bean is not being used a container will place it in a pool to be reused by
another client, or possibly evict it from memory and only bring it back when its
needed. Because client applications don't have direct access to the beans -- the
container lies between the client and bean -- the client application is completely
unaware of the containers resource management activities. A bean that is not in use,
for example, might be evicted from memory on the server, while its remote reference
on the client remains intact. When the client invokes a method on the remote
reference, the container simply re-incarnates the bean to service the request. The
client application is unaware of the entire process.
In addition to portability, the simplicity of the EJB programming model makes EJB
valuable. Because the container takes care of managing complex tasks like security,
transactions, persistence, concurrency and resource management the bean
developer is free to focus attention on business rules and a very simple programming
model. A simple programming model means that beans can be developed faster
without requiring a Ph.D. in distributed objects, transactions and other enterprise
systems. EJB brings transaction processing and distributed objects development into
the mainstream.
How do I introspect a bean at run time to discover its type(s) and available
methods?
Location: http://www.jguru.com/faq/view.jsp?EID=10610
Created: Feb 1, 2000 Modified: 2000-02-01 07:11:58.411
Author: Richard Monson-Haefel (http://www.jguru.com/guru/viewbio.jsp?EID=16)
Question originally posed by Srilekha Mudumbai
(http://www.jguru.com/guru/viewbio.jsp?EID=5112
Client applications or beans can access meta data about a bean from its
EJBMetaData object. The EJBMetaData object is obtained from the bean's EJB home
reference using the EJBHome.getEJBMetaData( ) method as shown below:
package javax.ejb;
Once a client application has a reference to bean's remote and home interface
classes, normal Java reflection can be used to introspect the methods avaiable to
client. Below is an example:
There are no mechanisms a client can use to introspect on a the bean class itself.
This makes sense since a bean, as a component, is represented by its remote and
home interfaces. The bean class itself should not be visible to the client.
The EJBMetaData is designed to be used by IDEs and other builder tools that may
need generic methods for obtaining information about a bean at runtime.
An enterprise bean is composed of many parts, not just a single class. Essentially, an
enterprise bean is constructed with a bean class, remote interface, home interface
and deployment descriptor. These constituents are discussed below.
A bean class is the implementation class of the bean that defines its business,
persistence, and passivation logic. The bean class implements either the
javax.ejb.EntityBean or javax.ejb.SessionBean interface and runs inside the
EJB container. Instances of the bean class service client request indirectly; instances
of the bean class are not visible to the client.
The remote interface defines the business methods that will be visible to the
client's that use the enterprise bean. The remote interface extends the
javax.ejb.EJBObject interface and is implemented by a remote (distributed object)
reference. Client applications interact with the enterprise bean through its remote
interface.
The home interface defines the create, delete (remove), and query methods for
an enterprise bean type. The home interface extends the javax.ejb.EJBHome
interface and is implemented by a remote (distributed object) reference. The client
application will use the home interface to create beans, find existing beans, and
remove specific beans.
The deployment descriptor is used to describe the enterprise bean's runtime
behavior to the container. Among other things the deployment descriptor allows the
transaction, persistence, and authorization security behavior of a bean to be defined
using declarative attributes. This greatly simplifies the programming model when
developing beans.
An enterprise bean represents the sum of all these parts (remote, home, bean class,
and deployment descriptor) as one component. An enterprise bean is not an
enterprise bean if any one of these parts is missing. A change to anyone of these
parts -- changing even one attribute in the deployment descriptor for example --
creates an entirely new enterprise bean.
EJB
Author: Anitha Rathanam (http://www.jguru.com/guru/viewbio.jsp?EID=448785), Jul
3, 2001
The implementation of Session bean or the Entity bean interfaces makes the plain
java class an Enerprise bean.
Message Driven Bean does neither have remote nor home interfaces. Even then
how does we say that it is still an EJB?
Author: Navin Sidhaye (http://www.jguru.com/guru/viewbio.jsp?EID=720474), Jan
15, 2002
According to the explaination given above and ejb has to have home, remote and bean
class. In addition to that it also need to have a deployment descriptor which will
dectate the bean's behavior at run time. But the Message Driven Bean does neither
have remote nor home interfaces. Even then how does we say that it is still an EJB?
Re: Message Driven Bean does neither have remote nor home interfaces.
Even then how does we say that it is still an EJB?
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727), Jan 15, 2002
Navin,
When this FAQ was created, the Message Driven Bean wasn't part of the standard
EJB specifications.
The MDB has, in fact, appeared with EJB 2.0
Re[2]: Message Driven Bean does neither have remote nor home
interfaces. Even then how does we say that it is still an EJB?
Author: Seetesh H (http://www.jguru.com/guru/viewbio.jsp?EID=1038574),
Dec 17, 2002
MDB implements MessageDrivenBean and so it does become a part of your
Enterprise bean and not a simple java class. Seetesh
While deploying CMP entity beans, which fields in the bean are container-
managed and how are they identified?
Location: http://www.jguru.com/faq/view.jsp?EID=11096
Created: Feb 3, 2000 Modified: 2000-08-24 18:55:46.998
Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question
originally posed by M J Thatipamala
(http://www.jguru.com/guru/viewbio.jsp?EID=4718
<enterprise-beans>
<entity>
<description>This entity bean models an audio compact
disc.</description>
<ejb-name>MusicCDBean</ejb-name>
<home>musicstore.MusicCDHome</home>
<remote>musicstore.MusicCD</remote>
<ejb-class>musicstore.MusicCDBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>musicstore.MusicCDPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-field><field-name>upc</field-name></cmp-field>
<cmp-field><field-name>title</field-name></cmp-field>
<cmp-field><field-name>artist</field-name></cmp-field>
<cmp-field><field-name>type</field-name></cmp-field>
<cmp-field><field-name>price</field-name></cmp-field>
</entity>
</enterprise-beans>
In the above deployment descriptor, the container-managed fields are specified to be
upc, title, artist, type, and price.
What newsgroups and mailing lists are available to learn more about EJBs?
Location: http://www.jguru.com/faq/view.jsp?EID=11099
Created: Feb 3, 2000 Modified: 2000-02-03 12:47:08.327
Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question
originally posed by John Mitchell PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=4
The J2EE-INTEREST mailing list is for discussion of Sun's Java 2 Enterprise Edition
platform and for users of Sun's J2EE Reference Implementation. A searchable archive
of this list can be found at http://archives.java.sun.com/archives/j2ee-interest.html.
You may subscribe or unsubscribe to either of these lists by following the links on the
above archive pages.
Currently the EJB security model supports authorization level security. Authorization
security or access control allows control over which users can invoke what methods
on a bean. Access control in EJB is declarative, which simplifies the programming
model.
Its possible that authentication security, which validates the identities of users
accessing the system, will be defined in EJB 2.0. Its likely that the Java
Authentication and Authorization security service will be used, but this is not definite.
If this authentication is added to EJB, it will provide a standard and portable model
for authenticating (login) of users.
The release date for EJB 2.0 (as of this writing) has not been determined. It seems
likely that EJB 2.0 will become final sometime in late 2001 or 2002.
Because an enterprise bean is not one object -- its the composition of several parts
-- traditional OO inheritance is not possible. The constituent Java parts (remote,
home, bean class) of an enterprise bean may themselves subtype or serve as super-
type, but the bean as a whole (the sum of its parts) doesn't support inheritance.
The file system APIs are not well-suited for business components to access data.
Business components should use a resource manager API, such as JDBC API, to
store data.
The EJB 1.1 specification is available for download from
http://java.sun.com/products/ejb/docs.html
Alternative Solutions
To perform I/O operations you must use a resource connection supported by the EJB
programming model. EJB servers may support several resource connection options,
which can be used to log events as shown below:
With container-managed persistence (CMP) its more difficult because you are
dependent on the versatility of the EJB vendor. In other words, if the vendor does not
support sophisticated find operations or syntax, its more difficult to declare complex
find operations at deployment time. With CMP you have a couple options:
• Convert the CMP bean to a BMP bean and hand code the ejbFind
methods yourself. This is a classic scenario for using BMP over CMP; when
the EJB vendor is not sophisticated enough to support a bean's data access
needs.
• Use a session bean to obtain the data you need. When a search
operation becomes to complex to implement in a single bean its a good
indication that the search operation is not appropriate for a find method.
Search operations that span the data encapsulated by several different entity
beans should be placed in a session bean with the emphasis on returning only
the data needed, not necessarily bean references. Data can be returned in
tabular format instead of bean references.
NOTE:
A common design error is to implement search operations that filter results of multi-
entity find requests implemented by other entity beans. This should be avoided. If
you can not find the entity beans in one find request, then you should use a search
method in a session bean.
No. The EJB specification specifically states that the enterprise bean is not allowed to
use thread primitives. The container is responsible for managing concurrent access
to beans at runtime.
Can I use Threads in a enterprise bean?
Location: http://www.jguru.com/faq/view.jsp?EID=14648
Created: Feb 15, 2000 Modified: 2000-05-22 12:57:17.2
Author: Aravind Naidu (http://www.jguru.com/guru/viewbio.jsp?EID=12326)
Question originally posed by sanath sarma
(http://www.jguru.com/guru/viewbio.jsp?EID=13815
No. The thread management is done by the container for you. As a bean developer
you are not allowed to use threads.
• The enterprise bean must not attempt to manage threads. The enterprise
bean must not attempt to start, stop, suspend, or resume a thread; or to
change a thread’s priority or name. The enter-prise bean must not attempt to
manage thread groups.
These functions are reserved for the EJB Container. Allowing the enterprise bean to
manage threads would decrease the Container’s ability to properly manage the
runtime environment.
Related FAQs:
• http://www.jguru.com/jguru/faq/view.jsp?EID=15893
Enterprise beans exist inside a container at run time. The container is responsible for
managing every aspect of the enterprise bean's life including: transactions, access
control, persistence, resource pooling, etc. In order for the container to manage the
runtime environment of a bean, it must have complete control over the threads that
access and run within a bean. This means that beans can not start or manage their
own threads. Containers deny enterprise beans the privilege to manage threads for
three basic reasons: Resource management, security, and thread-sensitive storage.
Resource Management
Containers manage every aspect of the runtime environment used by enterprise
beans including transactions, access control, life cycle, resource connections, VM
security, class loading, and threads. This allows the container to conserve as many
resources as possible, which is important when there are hundreds of enterprise
beans servicing thousands of clients. Without strict management of resources like
memory and threads, EJB systems might consume to many resources (memory and
cycles), which would result in a slow system, a prospect that is untenable in a high-
transaction environment. Threads started and managed by enterprise beans would
not be managed by the container, which would make it difficult to conserve
resources.
Security
There is no way for a container system to know in advance that a bean's use of
threads is benign. While intentions may be sincere it is possible -- probably inevitable
-- that developers would create malignant beans that spawn so many threads that
the entire system slows down. One bean instance's misuse of threads or the
commutative effect of many instances could cause a system slowdown. This is an
insurgent denial of service, where the beans themselves sabotage a system's ability
to respond to client requests. Security is a very good reason for denying bean's the
privilege of starting and managing their own threads.
Thread-Specific Storage
Thread-Specific Storage (TSS) is an established and common technique employed by
vendors to propagate and track client requests through the container system. It
involves associating data with a thread. The data may be information about the
client's identity, the transaction context, and other information, which can be
accessed by any part of the container without having to pass the data explicitly. This
is especially useful when enterprise beans invoke other enterprise beans or access
resources, because it provides a convenient and transparent mechanism for
transferring information about the who is making the request and under what
circumstances. Each vendor will use the TSS technique differently according to the
mechanics of their server. Threads started and managed by the enterprise bean
explicitly would not have the proper TSS -- that would require intimate knowledge
and access to the vendors container system. Without the right TSS the enterprise
bean's threads can not operate within the container system properly. This is another
reason why bean are not allowed to start and manage their own threads, it would
short-circuit the vendor's use of TSS.
Related FAQs:
"Although conflict with the container is one of the reasons why EJBs are not allowed
to create threads, there is a more important reason.
The goal is to delegate all responsibility for managing concurrency to a container and
its resources (DBMSs, etc). EJB 1.1 succeeds in doing this for many types of
applications. EJB 2.0 will significantly expand the EJB app domain by adding support
for asynchronous invocation (JMS integration).
So, the question is not what you can do within your container it is what your container
can do for you :>). Why should you be worrying about creating threads if you can get
the container to handle all of that complexity?"
-- Mark Hapner, EJB-INTEREST mailing list post "Re: Threads question (Concrete
examples?)"
I knew I could create a queue and write another bean/ process to do the job.But for
my scenario, I thought, it is too much overhead.
I went ahead with Threads. Any thoughts on how I should have proceeded.?
We will use an example to show how it's done. Say, there are 2 session beans, Tiger
and Lion, that share some method signatures but provide different implementations
of the methods.
• AnimalHome and Animal are the home and remote interfaces. The signatures
of the polymorphic methods are in Animal.
• AnimalBean is the base implementation bean.
• TigerBean and LionBean extend from AnimalBean. They may override the
methods of AnimalBean, implementing different behaviors.
• Deploy Tiger and Lion beans, specifying AnimalHome and Animal as their
home and remote interfaces. Note that Tiger and Lion should have different
JNDI lookup names.
Thanks in advance
It is worthwhile to note that the client never directly interacts with the bean object
but interacts with distributed object stubs or proxies that provide a network
connection to the EJB container system.
1. The client uses the JNDI context to get a remote reference (stub) to the home
object ( the EJBHome).
2. It uses the home to get a remote reference (stub) to the EJBs remote object
(the EJBObject)
3. It then invokes business methods on this remote object.
The client needs the remote interface, the home interface, the primary key( if it is an
entity bean).
In addition to these, the client would need the JNDI factory implementation, and the
remote and home stubs. In some EJB servers the Factory and/or stubs can be
dynamically loaded at run time. In other EJB servers they must be in the classpath of
the client application.
See also:
• Which, if any, of the automatically generated stub & skeleton class files does
one need to include in a JAR file to be used when creating stand-alone clients?
A primary key is an object that uniquely identifies the entity bean. According to the
specification, the primary key must be unique for each entity bean within a container.
Hence the bean's primary key usually maps to the PK in the database (provided its
persisted to a database).
You may need to create a primary key in the database for the sake of referential
integrity. This does not, however, mean you NEED a primary key in the database. As
long as the bean's primary key (which maps to a column or set of columns) can
uniquely identify the bean it should work.
See also:
What I mean here is, let's say that a table has columns Name and Balance and we
made a primary key by combining both of these columns. What happens if I have a
set method that changes the Balance column. Am I not changing the EB (since an EB
is identified by its primary key). Does this mean I am creating a new instance of the
EB? Thank you Sesh
An .ear file is an "Enterprise Archive" file. The file has the same format as a regular
.jar file (which is the same as ZIP, incidentally). The .ear file contains everything
necessary to deploy an enterprise application on an application server. It contains
both the .war (Web Archive) file containing the web component of the application as
well as the .jar file. In addition there are some deployment descriptor files in XML.
http://java.sun.com/j2ee/j2sdkee/techdocs/guides/ejb/html/Overview.fm.html
contains additional information.
Comments and alternative answers
" Currently, the J2EE 1.3 specification defines an enterprise application packaging
unit to be a JAR file with an .ear extension. EAR files can contain one or more:
Since most web-based J2EE applications are composed of web and EJB
applications, the EAR file meets the basic requirements for packaging an
application. However, it is lacking in capability for packaging complicated J2EE
applications. For example, the following components are often used in a J2EE
application, but cannot be declared in an EAR file:
- JMX MBeans
WebLogic is one server that does not support deployment of .ear files.
Orion is another EJB container that does support .ear files. I have found Orion to be
very true to the specification, and very similar to the reference implementation.
Stored procedures can be used by session beans that access the database using
JDBC and bean-managed entity beans that use JDBC to manage their own
persistence. JDBC provides a call interface for using stored procedures. An example
is provided below:
InitialContext cntx = new InitialContext( );
DataSource dataSource = (DataSource)
cntx.lookup("java:comp/env/jdbc/mydatabase");
Connection con = dataSource.getConnection( );
Tq
Neo
The same as any client would use JMS. At this point there is no integration, but it is
planned for a future release of the EJB spec.
Comments and alternative answers
Yes, a primary key can have as many fields as the developer feels is necessary, just
make sure that each field you specify as the primary key, you also specify a
matching field in the bean class. A primary key is simply one or more attributes
which uniquely identify a specific element in a database. Also, remember to account
for all fields in the equals() and hashCode() methods.
Comments and alternative answers
In the Deployment Descriptor, map the normal fields appropriately, but don't specify
the auto-id field as one of the container managed fields.
Comments and alternative answers
How can one have non-client specific state in stateless session beans?
Location: http://www.jguru.com/faq/view.jsp?EID=33182
Created: Apr 6, 2000 Modified: 2000-04-10 10:36:43.271
Author: sachin mahishi (http://www.jguru.com/guru/viewbio.jsp?EID=4437)
Question originally posed by Alex Stouffs
(http://www.jguru.com/guru/viewbio.jsp?EID=23864
You can use the Environment to get a pointer to a somewhat global state, that's
shared among all EJBs:
public class test implements SessionBean
{
private transient SessionContext ctx;
static final float PIE=3.14 ;
private transient Properties myprops;
Let's assume I use a JavaBean as a go-between a JSP and an EJB, and have,
say, 50 concurrent clients that need to access the EJB functionality. Will the
JSP container actually instantiate 50 instances of the bean, or can it reuse a
single instance to access the EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=35052
Created: Apr 11, 2000 Modified: 2000-08-14 11:26:53.146
Author: Govind Seshadri (http://www.jguru.com/guru/viewbio.jsp?EID=14) Question
originally posed by Garth Dyck
(http://www.jguru.com/guru/viewbio.jsp?EID=34850
It depends on the scope you associate with the JavaBean. If you assign the bean
with page (which is the default) scope or request scope, a new bean will be
instantiated for each incoming request.
If you assign the bean with session scope, you will still have 50 instances loaded in
memory (assuming each incoming request is triggered by a distinct client), although
some may have been instantiated from an earlier request from the same client.
However, you may not want to use the session scope for a high-volume site as these
beans will continue to reside in memory, long after the request has been serviced,
consuming valuable resources until they are invalidated either explicitly or due to a
session timeout.
You can also assign the bean with application scope, in which case it is instantiated
just once before being placed into the servlet context of the container. It can then be
accessed at a later time, as long as the server is up and running. Although this may
sound like an attractive proposition, do note that you will have to contend with
significant multithreading issues. For instance, you'll have to ensure that the bean is
accessed in a thread-safe manner from each of the JSP files. While you can do this
using explicit synchronization from within the JSP file, do note that your application
may take a significant performance hit because of this - especially if you expect tens
or hundreds of concurrent clients accessing your pages.
So, in short, your best bet may be to assign the bean with request scope.
So, to answer your question, two users will never access an Entity Bean concurrently.
If you wish to know more about this issue, I would suggest downloading and reading
the white paper from Sun: http://java.sun.com/products/ejb/docs.html . Some entity
beans may require loopback calls, where bean A is invoked, in turn invoking bean B,
which then invokes a method call on bean A. This kind of concurrency is tricky and is
best avoided.
As a side note, the use of 'synchronized' is not permitted in EJB. (You must leave all
that up to the server.)
Referring to the section 9.1.11 of the EJB 1.1 specification - "Concurrent access from
mulitple transactions" states that the container can allow for concurrent access to an
Entity Bean. This functionality is extremely vital for high transactional systems.
Having serialized access to an Entity Bean can cause deadlocks and hanging clients.
A high end EJB container, such as the Inprise Application Server supports this
enterprise level functionality. In this case, the transactional synchronization is left up
to the database and JDBC connection specified by the transaction isolation.
This can provide many benefits, consider Client A that accesses a Customer Entity
Bean - CBean. Client A is in a transaction but doesnt change CBean, Client B can
access and change CBean and does not have to wait for Client A to finish reading.
You may now ask "well then Client B is seeing an out of date CBean", This is exactly
how transaction isolation on a database works and is dependent on the transaction
isolation specified on the JDBC connection.
What's the reason for having two interfaces -- EJBHome for creating, finding
& removing and EJBObject for implementing business methods. Why not
have an single interface which supports both areas of functionality?
Location: http://www.jguru.com/faq/view.jsp?EID=35558
Created: Apr 12, 2000 Modified: 2000-04-14 08:44:05.104
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by rajesh kkkkkkkkk
(http://www.jguru.com/guru/viewbio.jsp?EID=16780
This design reflects the common "Factory" Design pattern. The EJBHome interface is
the Factory that creates EJBObjects. EJBObject instances are the product of the
factory. The reason for having two interfaces is because they are both responsible for
different tasks. The EJBHome is responsible for creating and finding EJBObjects,
whilst the EJBObject is responsible for the functionality of the EJB.
Comments and alternative answers
myIface.operation1(...);
Like in the code above client can call the biz methods with out really creating the
Object. This will certainly increase programming bugs.
For the above to work properly, ejbhome implementor should have a default ejb in it
to redirect the call to( current implementation allows to crete the ejb on demand) .
Initializing the default ejb poses many problems. It can be intialized with a standard
set of arguments (removes the current flexibility of overloaded create methods). Some
entity beans can have only finder methods with out creation methods, what to do in
those cases ( ???)
Having single interface for both the purposes promotes programatical errors, and
removes current ambiguities.
By careful look of the problems encountered above we get the answer that interface
and it's creation are two different abstractions. By using creation abstraction just to
create & find and the interface to do biz methods we get cleaner code, and flexibility
to create, find ejb's with multiple types of arguments. for a good pattern for this
design see Robert's answer above
No, You cannot implement a Singleton in EJB. A way to do this could be to implement
an RMI or CORBA object.
Comments and alternative answers
EntityBean as Singleton?
Author: Ravi Shankar (http://www.jguru.com/guru/viewbio.jsp?EID=560697), Nov
26, 2001
Wouldn't the following scheme work like a singleton? Define a read-only BMP
EntityBean with <prim-key-class> as String. In the ejbFindByPrimaryKey() method,
always return a hard-coded string (irrespective of the primary key value passed in).
Wouldn't all clients then get a reference to the same EJB instance? Regards Ravi
Does it work? Did you try?
Author: Chris Duerr (http://www.jguru.com/guru/viewbio.jsp?EID=1234080),
Mar 22, 2005
The ejb specification states: at any time, there is only one client thread per bean
instance active. Therefore I expect that there might more than one instance of an
entity bean, even if there is only one data set to represent.
Setting the entitiy bean read-only means that there is no call to the (unneseccary)
ejbStore(). A read-only bean still may be represented by more than one instance.
But this is blank theory, so does it in practice work? Did you try?
Ejb 1.1 spec section 9.4.1 - "The fields must be defined in the entity bean class as
public, and must not be defined as transient."
If your client is an EJB, it can pass a reference to itself to the method of the bean
that it is calling. The EJB can then call methods directly on that interface.
If your client is a Java client, your client requires some sort of object that will "listen"
for call-backs. This could be either a CORBA or RMI object. Again, you could pass
references to these objects to the EJB, which could then invoke methods on the
references.
Case 2: The client contains an RMI object that listens for callbacks. Do you have to
register this client RMI object with an RMI registry running on the client machine for
the EJB to find the object?
Wrong answers !!
Author: Raees Uzhunnan (http://www.jguru.com/guru/viewbio.jsp?EID=281081), Feb
14, 2002
An enterprise bean should not pass its reference to any callback methods. It should
first obtain a remote refernce to itself using contect object and then pass this to the
callback method. This is for container to have a track of who all accessing the
specified enterprise bean - based on spec 1.1
Hi Hari,
Although beans with container-managed transactions require less coding, they have
one limitation: When a method is executing, it can be associated with either a single
transaction or no transaction at all. If this limitation will make coding your session
bean difficult, you should consider using bean-managed transactions.
The following pseudo-code illustrates the kind of fine-grained control you can obtain
with bean-managed transactions. By checking various conditions, the pseudo-code
decides whether to start and stop different transactions within the business method.
begin transaction
...
update table-a
...
if (condition-x)
commit transaction
else if (condition-y)
update table-b
commit transaction
else
rollback transaction
begin transaction
update table-c
commit transaction
...
I think what it means is there are some limitations in j2ee transaction support. In a
container managed situation, nested or multiple transactions are not allowed within a
method. if a biz method needs those features you need to go for bean managed
transactions.
It turns out that nested transactions are not currently supported by Java TP
implementations. Or has that changed?
A common way to do it is to use a stateless session bean to retrieve the ID that you
wish to use as the primary key. This stateless session bean can then execute an
Oracle sequencer or procedure etc. to retrieve the ID value used as the primary key.
Comments and alternative answers
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.
v_seq_num NUMBER(10);
BEGIN
show errors
This Oracle trigger does not work. You are always ...
Author: Srihari Bathini (http://www.jguru.com/guru/viewbio.jsp?EID=54760), Sep 8,
2000
This Oracle trigger does not work. You are always giving 0 (Zero) to sequence
number, it will say, duplicate key. I tested this.
private SequenceGen() {
try{
jndiCtx = new InitialContext(ht) ;
ds = (javax.sql.DataSource)
jndiCtx.lookup("weblogic.jdbc.jts.EJBThin");
System.out.println("############# SequenceGen.constructor()
called ###############");
}
catch(NamingException ex) { ex.printStackTrace() ;
}
finally {
try{
jndiCtx.close() ;
}
catch(NamingException ex) { ex.printStackTrace() ; }
}
}
long nextVal = -1 ;
Connection conn = null ;
PreparedStatement pst = null ;
ResultSet rs = null ;
try{
conn = getConnection();
pst = conn.prepareStatement("Select RMH_SEQ.nextval from
DUAL");
rs = pst.executeQuery();
if(rs.next()) nextVal = rs.getLong(1);
}
catch(SQLException ex) {
ex.printStackTrace() ;
}
finally {
try{
if(rs != null) rs.close();
if(pst != null) pst.close() ;
freeConnection(conn);
}catch(SQLException ex) {
ex.printStackTrace() ;
}
return nextVal ;
}
}
int id ;
.
.
.
}
This should be faster and is definitelly simpler than the Session context approach. No
need for <ejb-ref> in all your Entity Beans
Also it hides from the Client the creation of the PKs. I don't want the EJB client
Application to have control over the creation of PK values. The advantage of the
Session bean approach is that it is accessible from remote Entity Beans (residing in
external JVMs).
How do you model for a JOIN operation in a relational database using entity
bean(s)? Do you have to have separate entity beans for each table in the
database?
Location: http://www.jguru.com/faq/view.jsp?EID=37219
Created: Apr 17, 2000 Modified: 2000-04-18 15:06:30.614
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Benjamin Ghofrani
(http://www.jguru.com/guru/viewbio.jsp?EID=28085
This depends on the granularity and the design of your Entity beans.
A way to do it is to model an Entity for each table and for the join specify a reference
to Entity Bean 2 (from table2 ) from Entity Bean 1 (from table 1). If this is a one-to-
one relationship then you could easily place these into the same Entity bean - this is
a design issue and has other factors involved.
If you're using CMP, the above information will be very much reliant on the EJB CMP
tool that you are using. Each tool has its strengths. I am basing this response on the
Inprise Application Server 4.0.
1. You can pull an address across the wire/process boundary in one shot, which is
nice since you usually use most of the fields of an address.
2. It's simpler to construct good transactions, since you get a big chunk of data,
which you can call accessors on locally, therefore out of transaction scope.
3. It allows you to define an optimistic locking mechanism at the Customer level,
so that you can detect when possibly conficting changes are made to any of
the Customer's dependents
test
Author: henry lee (http://www.jguru.com/guru/viewbio.jsp?EID=489761), Sep 24,
2001
test
There is no such thing as a Singleton EJB. This design pattern cannot be achieved
with EJB, an alternative solution to the problem using J2EE standards includes
implementation using RMI or CORBA.
Comments and alternative answers
I have to somewhat disagree with the answer regarding,...
Author: Shaun Childers (http://www.jguru.com/guru/viewbio.jsp?EID=30243), Jun
21, 2000
I have to somewhat disagree with the answer regarding, "...This design pattern cannot
be achieved with EJB," and just make the suggestion that you could set your bean up
so that there is only one istance of it in the EJB pool controlled by the container. In
this case, if a client had a connection to this "Singleton"-like EJB bean, then any other
client would have to wait. Use the maxBeansInFreePool and maxBeansInCache fields
in the deployment descriptor.
Another flaw is that not all EJB containers allow you to control the pool at such a fine
level and those that do provide minimums that are larger than 1.
I think you can use reference storing to JNDI (or the Handle), but then all the requests
for that EJB would be pointed at the same server, which might not be efficient. The
only resources that are shown to all servers in a cluster are the JNDI tree and normally
the database. Also the information between entity bean's that represent the same data
is shared, so entity bean's are the first place where I would store 'singleton'
information.
Yes, there still issues to be solved (what happens if two EJB clients want to change
the same data), but this way you can provide similar behaviour as in the singleton
pattern.
How do I connect to SQL Server 6.5 from J2EE for Windows? What changes
should I have to do in the properties file? Can I use the JDBC-ODBC bridge?
Location: http://www.jguru.com/faq/view.jsp?EID=37845
Created: Apr 19, 2000 Modified: 2000-04-24 19:56:01.653
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question
originally posed by Sathya Narayanan
(http://www.jguru.com/guru/viewbio.jsp?EID=31789
If you insist on initially using a database other than Cloudscape, you should carefully
read and follow the instructions in the following J2EE RI documentation:
• Configuration Guide
• Release Notes
There are two ways for transitioning an entity bean from the ready to the pooled
state, by using the ejbPassivate() or ejbRemove() method. The container uses
ejbPassivate() to disassociate the bean instance from the entity object identity, and
uses ejbRemove() to remove the entity object.
When the instance is put back into the pool, it is no longer associated with an entity
object identity. The container can now assign the instance to any entity object within
the same entity bean home.
A more thorough discussion can be found in the EJB 1.1 specification by Sun.
Passivation for an entity bean means "the container is done with this instance and it is
going back to being an anonymous member of the free pool". There is no saving of
state here. With BMP you save the state in ejbStore; with CMP the container does it
right after ejbStore.
Take a look at the EJB spec 1.1 on page 102. Figure 23 shows this is a pseudo Harel
state diagram. Also look at Figure 28, page 138 and Figure 29, page 139 for object
interaction diagrams.
[For example, I have a method transfer which transfers funds from one account to
another account.]
Vague question. Is the Session bean doing the DB work? I'll assume no.
Let's say AtmEJB is a Session bean with the transfer method. Let's say AccountEJB is
an Entity bean.
Step 1:
When the client invokes the transfer method you want that to be the transaction; i.e.
"the transfer transaction". therefore you need to set the tx attribute of transfer to
something that will make the container start a tx at the beginning of transfer and
terminate it at the end of transfer. RequiresNew might be a good choice but you need
to look at all your use cases not just this one.
Step 2:
The AccountEJB methods invoked from the transfer method need to have a tx
attribute that allows them to be part of an ongoing tx. That means that deposit and
withdraw cannot be RequiresNew! (that would suspend the transfer tx and run in its
own tx). Look at the spec for these: there are 3 that meets the criteria for deposit
and withdraw in the transfer use case. Which one to use? What are the other use
cases in which deposit and withdraw will be called? Find one that works for each one.
Re: Yes we can all read p 177-178 of the EJB spec. Where...
Author: Kalpeshkumar Soni
(http://www.jguru.com/guru/viewbio.jsp?EID=916018), Jul 2, 2002
Nobody seems to paying attention to isolation levels !
Re: Yes we can all read p 177-178 of the EJB spec. Where...
Author: sesha venkat (http://www.jguru.com/guru/viewbio.jsp?EID=1245960),
May 26, 2005
Hi
Thanks in advance.
Re[2]: Yes we can all read p 177-178 of the EJB spec. Where...
Author: Giri B (http://www.jguru.com/guru/viewbio.jsp?EID=1248402), Jun
13, 2005
TX_REQUIRED A bean is going to participate in TX or a client call a Bean
then that method should executed in the TX if client doesnot have the TX then
Container will create the TX for that TX_SUPPORTS The client supports the
TX to the method execution.If the client doesnot have any TX then the method
will execute without TX
The EJB spec does not specify how to deal with relationships. You'll have to develop
your own Java classes to handle these design patterns.
Which IDEs are available that support EJB development? And are any free or
low-cost?
Location: http://www.jguru.com/faq/view.jsp?EID=40579
Created: Apr 26, 2000 Modified: 2000-04-26 10:57:05.156
Author: Keir Hansen (http://www.jguru.com/guru/viewbio.jsp?EID=38387) Question
originally posed by DINESH DEWAN
(http://www.jguru.com/guru/viewbio.jsp?EID=37190
We've been doing some review of WebGain's StructureBuilder 3.3, which supports a
UML-to-Javacode cyclical development, and with its new "ejbCreate" facility, supports
1.0 and 1.1 EJB development. So far, we're thoroughly impressed. A little
clunky/slow, but definitely worth investigating for lower cost (standard $395,
enterprise $695) bean development.
What is the most efficient approach for integrating EJB with JSP? Should the
EJBs be invoked directly from within JSP scriptlets? Should the access take
place from within Java beans? Or is it best to use custom tags for this
purpose?
Location: http://www.jguru.com/faq/view.jsp?EID=42963
Created: May 1, 2000 Modified: 2000-05-02 23:22:15.212
Author: Christopher Longo (http://www.jguru.com/guru/viewbio.jsp?EID=2166)
Question originally posed by Sanjay Mistry
(http://www.jguru.com/guru/viewbio.jsp?EID=17764
JSP scriptlet code should be minimal. Invoking EJB code directly on a JSP page
results in many lines of code on your JSP page, including try...catch blocks to catch
naming and finding exceptions.
Using a standard JavaBean as an intermediary between the JSP page and EJB server
cuts down on the amount of code needed to add to a JSP page, and promotes reuse.
The JavaBean should be a simple wrapper around the EJB you are accessing.
If you use a standard JavaBean you could also use the jsp:useBean tag to setup EJB
parameters, such as the server URL and server security parameters.
Custom tags are also an option. However, they require a lot more coding than a
simple JavaBean wrapper. The point should be to rewrite as little code as possible
while at the same time keeping the JSP scriptlet content as light as possible.
There is no "stopUsingBean" tag. You cannot rely on the finalizer. So, do you just
wait for the session timeout?
How do you get a JDBC database registered with a JNDI name so that it can
be accessed from an EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=42968
Created: May 1, 2000 Modified: 2000-08-24 18:58:56.376
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by David Bosschaert
(http://www.jguru.com/guru/viewbio.jsp?EID=40641
The short answer is that it depends on which container you're using to some extent.
The one thing that (should be) common in EJB 1.1 containers is that the ejb-jar.xml
file's entry for that bean needs to contain a 'resource-ref' stanza, like so:
<resource-ref>
<res-ref-name>jdbc/LocalDB2<res-ref-name>
<res-type>javax.sql.DataSource<res-type>
<res-auth>Container<res-auth>
<resource-ref>
The res-ref-name is the most interesting part. This is the JNDI name relative to the
java:comp/env namespace. Hence, to get this connection you'd do (in your bean):
Context context = new InitialContext();
DataSource source = context.lookup("java:comp/env/jdbc/LocalDB2");
which gives you a DataSource that you can call getConnection on.
The other half of this is container specific and done at deployment time by a
'Deployer' or 'Assembler' (to use the rolenames specified by the EJB spec.) This can
work very differently from one container to the next, but here are a couple of
(abbreviated) examples.
With Weblogic 5.1, you must define a connection pool in weblogic.properties, then
edit the weblogic specific deployment descriptor (using the EJB Deployment tool) to
associate the resource-ref specified in ejb-jar.xml with that connection pool.
With Inprise Application Server 4.0, all of the parameters for the connection (JDBC
driver, connection URL, etc.) are specified in the inprise specific deployment
descriptor (also editable via their deployment tool).
Other servers will have other ways of associating the resource-ref with a pre-defined
connection pool.
To give an example: I use the open source database InstantDB. Normally I would
connect to it with:
Class.forName("idbDriver");
Connection con =
DriverManager.getConnection("jdbc:idb:c:\temp.prp");
How and where do I register my JDBC database in order to use it with EJB's through
the JNDI?
I would like to know how I get my existing JDBC database registered with JNDI.
You are developing a product which allows a bank to sign up new customers online.
You have done analysis and design and settled on having two tables: 'users' and
'account' (let's keep it simple). Each "user" will have a corresponding "account". The
foreign key between the two will be the "account number".
So, for the 'users' table, you have the following fields: firstName, lastName, userId,
password, and acctNum. When this table is created in the database, it is empty. Now
you must relate your EJB code to this table for persistence. For simplicity sake I will
leave out the Session bean (which I would use to talk to my Entity bean), the Entity
bean primary key class, and the home and remote interfaces.
/**
* Called by the container after the UserHome.create() is called
*/
public void ejbCreate(String userId, String password, long acctNum) {
this.userId = userId;
this.password = password;
this.acctNum = acctNum;
}
...
...
public void setUserData(UserData data) throws RemoteExeption,
UserDataException {
this.firstName = data.getFirstName();
this.lastName = data.getLastName();
}
...
...
}
Now, assuming you have the User (remote interface class), UserHome (home
interface class), UserPK (primary key class) already done, you need to create the
bean's deployment descriptor. Inside the deployment descriptor, you must specify the
database table, 'users', which this bean will map to. Also, you must specify which
fields from your bean map to which fields in the 'users' database table. (This is how
the container knows which fields to persist between your bean and the database
table.) Now assuming all code compiles and you have an EJB server up and running
and you have deployed your bean, all you need to do is write a client (I would use a
client to access a session bean, say 'CustomerSession', which would talk to my entity
bean) to create a new user and pass in the userId, password and acctNum values,
which will create the new user in the database.
Notice the fields in the UserBean will now be set, but the firstName and lastName
fields will still be set to null. These fields will still be empty in the database and will
not change until these fields are set in the bean, since it is persisted. Now, call the
setUserData(UserData data) method for setting the firstName and lastName, and
these fields will now be set in the database and no longer be null. The container will
handle the persistence of any fields which are set to null, just as it will handle any
fields which are set to some meaningful value.
NOT NULL
Author: pei wang (http://www.jguru.com/guru/viewbio.jsp?EID=424597), May 18,
2001
How about if the lastname, firstname are defined as NOT NULL in user table? What
will happen when the EJB try to persist itself the first time?
Borland's JBuilder 3.5, Foundation Edition allows you to debug any Java 2
application, including the Inprise Application Server, WebLogic Server and J2EE
Reference implementation. You can download it free from www.borland.com/jbuilder.
To debug you compile your EJB source files with the metamata compiler 'mjavac' and
deploy the class files including the automatically generated debuginfo class file in a
JAR as you would normally do with your EJB application. When you start the
Application Server, you can attach to the process of the server/container from the
remote debug console and perform all standard debug actions as setting breakpoints,
defining watches, stepping through your EJB code expression by expression etc.
My impression is that this remote debugger is easy to use and improves our
development process for EJB applications very much - b.t.w. we used mainly
'System.out.println' - debugging before.
An applet must use the same procedure as any other Java class: it must use JNDI to
locate the EJB Home Interface, then use RMI to talk with the Home Interface as well
as the EJB itself.
This means that the J2EE and/or JNDI and/or RMI classes need to be present in the
applet's Java Virtual Machine. The easiest way to assure this is to use the latest Java
Plug-in. Netscape 6, aka Mozilla, ships with the Java Plug-in. Other browsers have
various problems with RMI and JNDI classes that are beyond the scope of this
answer.
Note, however, that it is not recommended to use EJB directly from applets, in part
due to compatibility issues. Instead, you can use Servlets inside the application
server to provide an HTML front-end that is assured to work on a much larger base
of clients.
Comments and alternative answers
What is the best way of implementing a web application that uses JSP,
servlet and EJB technologies all together following a Model View Controller
(MVC) architecture?
Location: http://www.jguru.com/faq/view.jsp?EID=48001
Created: May 11, 2000 Modified: 2000-06-21 11:05:30.729
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by christophe hillegeer
(http://www.jguru.com/guru/viewbio.jsp?EID=43669
[See the Sun J2EE Blueprints for "an integrated set of documentation and examples
that describe and illustrate 'best practices' for developing and deploying component-
based enterprise applications using the J2EE platform" including some good
architecture whitepapers and source code. -Alex]
Hmm, 'Best Way' is a bit rough - there are several 'good' ways, and the usual set of
trade-offs between them. (I'm a consultant - I have to start any answer with "It
depends...", otherwise they revoke my whiteboard privileges)
The main thing you need to keep in mind as you design this sort of a system is that
you want the interface into the EJB's to be rather narrow: in any flow, the ideal is to
call one EJB method (hopefully on a stateless session bean), and let it make calls to
entities on your behalf, then hand back the data you need to display.
How you display it depends: you can either embed beans on your JSPs and let the
beans make that hopefully-one EJB call, or you can post to a servlet, let that make
the call, then forward to the JSP for display. The second of these is more flexible and
gives you more leverage to hide, change, and enforce your site's structure. The first,
however, will be easier for developers new to this web thing to follow.
Essentially, I'm saying that Entity beans are your model, your controller is Session
beans (maybe with a bit of help from servlets or beans), and your JSPs, beans and
servlets are your View.
One thing to note here: this discussion strongly implies that your EJBs are capable of
externalizing their state as some number of very simple 'value objects' (not EJBs
themselves, just something we can pass back and forth). These value objects are
probably tuned tightly to a workflow, and will be produced by that session bean. This
way the traffic between the EJB (server) and the JSP/Servlet (client) is tuned to what
the client needs, while the transaction load on the server is minimized.
The architecure involves a MVC with the controllers being entity and session beans.
We are moving away from using entity beans unless there are many transactions
involved. These ejbs pass back value objects as specified in the blueprints by sun.
We also use bulk accessor session beans which go directly to the database and also
call some other session or entity beans.
Check out the blueprints from sun for some good analysis!
J2EE architecture
Author: Mindy Couleur (http://www.jguru.com/guru/viewbio.jsp?EID=1175354), Jun
1, 2004
I am new to J2EE and am wondering if you can expand on your answer a bit. I've
noticed that much of the logic that I see in Servlets could go in EJB's. I'm wondering
just how thin the servlet layer should be. I also would like to confirm some RMI logic
flow. As far as I understand..... JSP calls Servlet Remote interface then Servlet call
EJB remote interface....reply goes back to servlet then servlet forwards to JSP for
display. Is that considered the best way to separate the layers?
Yes, check out The JNDI Tutorial online and/or buy a copy of it here.
Check out The JNDI Tutorial. It's also available on the web.
For other books that are relevant to JNDI, check out Are ther any books that provide
decent JNDI coverage?.
The lifecycle of an enterprise bean is the heart of the EJB system. Your bean is
basically implemented as a set of callback methods. There are a lot of these
methods, which can be confusing; however, the implementation of each one is
actually quite straightforward. Most of the time you can get away with implementing
only a few of them.
Using Bean-Managed Persistence, each callback method ejbX means the obvious
thing (usually "you must do X").
The following table is based on the EJB Spec 1.1, chapter 9, section 5. Section 9.4
and 9.5 has detailed descriptions of each of the callbacks; you should definitely read
the spec, and use the table as a quick reference only.
Initialization:
Let say i need to run a stored procedure calls inside a EJB (regardless CMP or
BMP), should I just create a method call that fired the stored procedure or which
area of the lifecycle?
import java.io.Serializable;
import java.ejb.*;
import java.sql.*;
import java.naming.*;
import java.util.*;
import weblogic.db.jdbc.*;
import NTConn.ConnSetup;
import db.UpdMainLedgIE;
// Initializes variables
private EntityContext ctx;
private int iMainLedgPrin;
private int iMainLedgInt;
private int iMainLedgLPI;
private int iMainLedgOC1;
private int iMainLedgOC2;
private int iMainLedgUappAmt;
private int iMainLedgIISInt;
private int iMainLedgIISLP1;
private int iMainLedgIntClw;
private int iMainLedgLPIClw;
private int iTotUnchrgPrin;
private int iPrpdUduePrin;
private String iLastUpdUsrId;
private String iLastUpdBrchCd;
// Updates data
public void ejbStore()
{
log("ejbStore called: " + id());
}
try {
TestSetupConn = new ConnSetup;
conn = TestSetupConn.MBSConn();
local_UpdMainLedgIE = new
UpdMainLedgIE(iMainLedgPrin, iMainLedgInt,
iMainLedgLPI, iMainLedgOC1,
iMainLedgOC2,
iMainLedgUappAmt, iMainLedgIISInt,
iMainLedgIISLP1,
iMainLedgIntClw, iMainLedgLPIClw,
iTotUnchrgPrin,
iPrpdUduePrin, iLastUpdUsrId,
iLastUpdBrchCd, conn);
} catch (SQLException sqle) {
log("One update transaction failed: " +
id());
throw new EJBException(ejbE)
} finally {
cleanup(conn);
}
}
}
Thanks
Neo
What's the difference between EJBHome, EJB Home, EJB Object, EJBObject
and EJB (not to mention Home Interface and Remote Interface)?
Location: http://www.jguru.com/faq/view.jsp?EID=51578
Created: May 18, 2000 Modified: 2000-05-18 20:36:36.409
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3)
First, an Enterprise JavaBean is not a JavaBean (but you already knew that).
When you write the source code for the EJB Home Interface, you must extend the
interface EJBHome, and provide method signatures for all the desired create()
and find() methods. An object that implements the Home Interface is automatically
generated by the EJB Server tools.
The "EJB Object", or Remote Object, is actually a Wrapper. It sits somewhere inside
the container, between the client and your code. It is responsible for performing all
the setup and shutdown tasks (like opening transactions, or restoring data state)
immediately before and after your enterprise bean is called.
The "EJB Object" is generated by the EJB Server tools -- you don't have to write any
part of it. However, you do have to write another interface, called the "Remote
Interface" or the "EJBObject Interface," that extends interface
EJBObject, and provides method signatures for all the business methods. The
server automatically generates a Java class that implements the Remote Interface; it
is this object that is registered with RMI, and a reference to it is returned by the
Home Interface (which we now know is actually a Factory Object).
The "EJB," or Enterprise Bean, ironically, is not the EJB Object (even though it is an
EJB and it is an object). It doesn't even implement the EJBObject interface, nor
does it implement the Remote Interface. Instead, it implements either the
EntityBean interface or the SessionBean interface. It also must implement all the
methods defined in the Remote Interface -- but it doesn't actually implement the
interface (in the Java sense). This is unfortunate, since we cannot rely on the Java
compiler to make sure we've implemented all the right methods. It must also
implement one ejbCreate() method for each create() method in the Home Interface
(as well as ejbFind()/find()).
EJB Bean the class, which implements these methods, when the user calls the
methods in the remote Interface the corresponding methods will be called. The calling
of the methods is taken care by the container which is residing in the EJB Server.
Note: Even though you do not extend any of the interface which we have created
previously we have to implement the methods of the interface, yes it looks amazing
but it is EJB specification.
Thanks in advance.
Sorry to say Hari that u have got the home and remote...
Author: kishore_k_v k (http://www.jguru.com/guru/viewbio.jsp?EID=202022), Sep
10, 2000
Sorry to say Hari that u have got the home and remote mixed up.I for one rely on
online help a lot to get more info.Please change it before someone new to ejb goes. Of
Course I'm sure it was just another typographical error.
The whole issue of propagation of authentication context from client to the EJB
server is still evolving - both in terms of the specification as well as vendor offerings.
According to the current Java 2 specification (page 224):
"the container is the authentication boundary between callers and components
hosted by the caller. For inbound calls it is the container's responsibility to make an
authentic representation of the caller identity available to the component".
The JAAS 1.0 specification extends the types of principals and credentials that can be
associated with the client but it is also evolving.
Thus given the container implementation that is required to drive this whole thing,
the answer depends on your app vendor - some like Weblogic (WLE), Websphere
provide security plug-ins/SDKs that can enable the propagation. Other vendors are
close behind. Check your vendor plug-in.
Can we pass security context from resin to weblogic?. Can JAAS help use
here?.
I installed Weblogic (4.5.1 and 5.1.0) in my computer with Win98 and it works
perfectly (the only changes with respect to NT are that it doesn't use the Native
interface for I/O connections and uses the standard socket implementation)...
The only recommendation is that you must have a "powerful" machine with at least
128MB of RAM (better 192MB for 5.1.0) and a 400MHz processor (or above)...
[Short answer: with bean-managed persistence, you can optimize your queries and
improve performance over the generalized container-managed heuristics. But
container-managed persistence is very convenient, and vendors will be working to
improve its performance as time goes on. -Alex]
There is of course a difference as many CMPs use O-R mapping using metadata,
which is slower than hardcoded queries (except vendors like GemStone that use a
OODB which is slow anyway!) As always, a lot depends on the database schema.
Given that CMP is still evolving, complex relationships (e.g.inheritance) and
distributed transactions are not even supported by most EJB server vendors, leave
alone performance.
Having said that however, it does not seem right to compare BMP and CMP on
performance because the motivation of CMP is precisely to relieve bean providers
from thinking about this! In (J2EE) theory, a good CMP implementation should
perform well in a production environment; in practice, except for a couple of vendors
who have traditionally been strong in persistent storage space (e.g. Persistence
Software, GemStone) you will not find great CMP support at this very moment.
BMP offers a tactical approach while CMP is more strategic. Which implies that if you
can work-around some (perhaps severe) limitations for near-term, there may be
much to gain with CMP as the vendor offering matures.
Given that RMI-IIOP does not support distributed garbage collection (unlike
RMI-JRMP), do I need to do something explicitly to GC beans, or is it
magically handled by the EJB framework?
Location: http://www.jguru.com/faq/view.jsp?EID=60460
Created: May 31, 2000 Modified: 2000-05-31 10:21:02.894
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Alex McManus
(http://www.jguru.com/guru/viewbio.jsp?EID=45888
(The lack of distributed GC was noted in the article "EJBs from a critical
perspective".)
Whilst this article does take a hit at EJB, I believe that it is misleading in some sense
and is outdated. Most of the pot shots that it takes about EJB products not
supporting latest standards etc. are now obsolete as vendors such as Inprise, BEA,
GemStone etc. have updated there products, it's a shame that he didn't get to
review the beta products...
The article also mentions the importance of "Dynamic Glue" which is not using
statically generated stubs and skeletons. This is in fact possible with RMI-IIOP using
DII (Dynamic Invoacation Interface), but he fails mention how this technology is
used in building systems and why it is important. He says that it is why CORBA has
failed, which is wrong. EJB is a logical extension of and most Containers are built on
top of CORBA.
He also mentions the overheads of intra-vm calls. This is something that most
products provide optimizations for and something he clearly hasn't researched as this
is a feature that CORBA ORB's have supported for quite a while.
If your EJB does not need to know about the results of the aynch calls, then you can
use JMS to send an asynch. message to another part of the system.
Another alternative is to place the multithreaded code inside a CORBA or RMI server
and call this from your EJB. Always keep site of the big picture, RMI and CORBA are
part of J2EE and can be used as part of a 'J2EE' solution.
There are some things that these technologies can do that EJB at this present time
cannot.
This depends on the J2EE Application Server that you are using, but for all of them
you will at least require all of the J2EE classes, which are downloadable as part of the
J2EE Reference Implementation.
Basically, take the JAR file from your implmentation and add it to your CLASSPATH.
The easiest way is to just copy the file to the jre\lib\ext directory under your JDK
directory.
if you are using weblogic server you can set the e...
Author: ravindra ch (http://www.jguru.com/guru/viewbio.jsp?EID=63594), Jun 3,
2000
if you are using weblogic server you can set the environmental variables by calling
the "setenv" command at the command prompt.
Now, to do the compiling etc. you at least want your CLASSPATH to include the path
to the Java compiler (javac), the path to the JAR utility, and the path to the EJB
compiler (should come with your EJB server - weblogic.ejbc for Weblogic).
Of course you don't even have to set your CLASSPATH if you want to do each step at
a command line - you will just have to give the full path to the compiler(s).
My session beans call other bean methods within a transaction. Using bean-
managed transactions, how should I take care of commit and rollback ?
Location: http://www.jguru.com/faq/view.jsp?EID=62121
Created: Jun 2, 2000 Modified: 2000-09-12 15:55:36.874
Author: Siva Visveswaran (http://www.jguru.com/guru/viewbio.jsp?EID=46210)
Question originally posed by Shalabh Nigam
(http://www.jguru.com/guru/viewbio.jsp?EID=47481
1. Coding step:
Note you have to begin a txn before opening dB connections and close connections
before committing.
2. Deployment step:
- Your app server must support a JTS for distributed txns. Most do.
- Verify there is no conflict with the bean transaction properties in calling beans.
You are right about the JDBC-ODBC bridge. Since it does not support multi-threading
it is not of much use. But you can find 3rd-party drivers in the market that will allow
you to work with MS Access from EJBs.
For a list of those drivers search for MS Access drivers from the following page:
http://industry.java.sun.com/products/jdbc/drivers.
First of all, you have to create a javax.mail.Session like you would in accessing other
resources such as JDBC connections:
Can I deploy a new EJB without restarting my server? (I'm using Weblogic.)
Location: http://www.jguru.com/faq/view.jsp?EID=75637
Created: Jun 14, 2000 Modified: 2000-06-14 15:51:26.555
Author: Suja Rao (http://www.jguru.com/guru/viewbio.jsp?EID=62310) Question
originally posed by Dakshinamurthy Ramachandran
(http://www.jguru.com/guru/viewbio.jsp?EID=57231
Sure. WebLogic Server4.5 includes "hot deploy" feature that allow you to deploy,
redeploy or undeploy EJBs while the Server is running, from the Weblogic Console.
Deployment of EJBs made through the console are however lost when you restart the
WebLogic Server.
Comments and alternative answers
http://www.weblogic.com/docs45/techdeploy/hotdeplo...
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3), Jun 21, 2000
http://www.weblogic.com/docs45/techdeploy/hotdeploy.html#deploy
See: http://www.weblogic.com/docs45/techdeploy/hot...
Author: Keith Schwartz (http://www.jguru.com/guru/viewbio.jsp?EID=27189), Jun
21, 2000
See:
http://www.weblogic.com/docs45/techdeploy/hotdeploy.html
http://www.weblogic.com/docs51/techdeploy/hotdeploy.html
if you're using weblogic 5.1.
[Basically, you have to cheat. Make a custom data class that is not an EJB. Create a
Vector or List containing objects of this type, one per EJB; fill the data objects with
the same values as are in the EJBs. Then you can return this List, and it will be
serialized through RMI, and magically reconsituted on the client side. -Alex]
In your bean:
return vector;
}
In your bean's remote interface:
public Vector getCustomerData()
throws RemoteException;
In both client and server:
public class CustomerData implements java.io.Serializable
{
private long id;
private String name;
On the client side, one needs to call the findAllRecords method from the home
interface. Then iterate over the Collection returned that contains refernce to rhe
Remote interface. You can get the Primary keys from the individual items in the
Collections. One can pass this Primary key to a Session bean to get the list of all the
records.
Is this way OK. I have not tried this myself, but I am sure this can work...
[I'm confused: are you talking about returning a list of primary keys, or a list of
remote references? -Alex]
In weblogic...
Author: samson su (http://www.jguru.com/guru/viewbio.jsp?EID=232778), Apr 7,
2001
I don't know how this works in other environment... but in weblogic, when you
declare the return type of findXXX() as "Enumeration", the deployer tool will auto
generate an implementation that returns a couple of records. For example:
public interface IBookHome extends EJBHome {
public IBook findByPrimaryKey(CBookPK key)
throws RemoteException, FinderException;
public Enumeration findByAuthor(String name)
throws RemoteException, FinderException;
}
...
......
}
JDBC 2 alternatives
Author: ian pojman (http://www.jguru.com/guru/viewbio.jsp?EID=383696), Apr 20,
2001
Now that JDBC 2 is out, why create a CustomerData class? You can just use a
connectionless ResultSet (RowSet or CachedResultSet). This way you can access
your SQL data just as if you had just gotten the ResultSet from a hard-coded SQL
query!
How to setup access control in an EJB such that different application clients
have different rights to invoke different methods in one EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=74503
Created: Jun 17, 2000 Modified: 2000-08-24 18:58:32.114
Author: Shaun Childers (http://www.jguru.com/guru/viewbio.jsp?EID=30243)
Question originally posed by Wai MOK
(http://www.jguru.com/guru/viewbio.jsp?EID=51540
1) Set up the different users/groups and the methods each can have access to in
your deployment descriptor. Note: You don't have to specify different methods for
each user, you could also just specify different users to your entire bean - for
example if you only wanted another component of your application talking to your
bean.
2) Inside your client code, whenever you make your connection to the EJB server (to
look up the bean) you need to specify the user and password, in order to set the
Identity of the client:
...
Properties p = new Properties();
..
p.put(Context.SECURITY_PRINCIPAL, "user");
p.put(Context.SECURITY_CREDENTIALS, "password");
...
3) Inside your bean, you can do "extra" security checks (if you used 'Role'-based
security): (Assuming you have a 'manager' role defined in your deployment
descriptor and a user assigned to this role)
public int getAccountBalance(accountId) {
if (ejbContext.isCallerInRole("manager"))
return balance;
}
You could also enforce security to your EJB server. Using Weblogic, you could add the
following to your weblogic.properties file:
...
weblogic.password.user=password
...
where "user" is the username you grant access for and "password" (after '=') is the
password for this username.
Much more detailed information on this topic can be found by reading the SUN
specification of EJB at: http://www.java.sun.com/products/ejb/docs.html
Persistence in EJB is taken care of in two ways, depending on how you implement
your beans: container managed persistence (CMP) or bean managed persistence
(BMP).
For CMP, the EJB container which your beans run under takes care of the persistence
of the fields you have declared to be persisted with the database - this declaration is
in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon
as the method you have executed is finished, the new data is persisted to the
database by the container.
For BMP, the EJB bean developer is responsible for defining the persistence routines
in the proper places in the bean, for instance, the ejbCreate(), ejbStore(),
ejbRemove() methods would be developed by the bean developer to make calls to
the database. The container is responsible, in BMP, to call the appropriate method on
the bean. So, if the bean is being looked up, when the create() method is called on
the Home interface, then the container is responsible for calling the ejbCreate()
method in the bean, which should have functionality inside for going to the database
and looking up the data.
See the following FAQs, and the appropriate topics (listed on the main EJB FAQ
page):
Can the primary key in the entity bean be a Java primitive type such as int?
Location: http://www.jguru.com/faq/view.jsp?EID=81676
Created: Jun 20, 2000 Modified: 2000-08-15 06:31:10.893
Author: Keith Schwartz (http://www.jguru.com/guru/viewbio.jsp?EID=27189)
Question originally posed by Steven Lau
(http://www.jguru.com/guru/viewbio.jsp?EID=72026
The primary key can't be a primitive type--use the primitive wrapper classes,
instead. For example, you can use java.lang.Integer as the primary key class, but
not int (it has to be a class, not a primitive).
Comments and alternative answers
import java.io.Serializable;
<entity>
...
<prim-key-class>java.lang.String</prim-key-class>
...
<primkey-field>userName</primkey-field>
...
For primary keys which map to primitive types, like int, the specification requires a
primary key wrapper class. You can define these primay key types as compound
primary keys. Note: Compound primary keys are used for multiple primary key fields
as well as single primary key fields of primitive types. With compound primary keys,
the EJB bean developer still has to define the primary key class. Compound primary
keys are defined in the ejb-jar.xml file as follows:
<entity>
...
<prim-key-class>com.mypath.MyBeanPK</prim-key-class>
...
Are EJBs the best solution to make a component which have to manage a
hardware device (modem, fax...) and provide access to them?
Location: http://www.jguru.com/faq/view.jsp?EID=81868
Created: Jun 21, 2000 Modified: 2000-06-21 11:14:30.996
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Luis F. Canals Samaniego
(http://www.jguru.com/guru/viewbio.jsp?EID=66172
I would suggest not, because these devices would probably be served best by
Singleton Objects which could control the access to the device, and EJB does not
support Singletons (in a standard way).
A suggestion is to delegate the call from an EJB to another Object, possibily an RMI
or CORBA object or even an a Java object implementing the Singleton pattern,
possibly using JNI to use OS-dependent device access libraries.
-Chetan.
An EJB container runs inside (or within) an EJB server, and provides deployed EJB
beans with transaction and security management, etc. The EJB container insulates an
EJB bean from the specifics of an underlying EJB server by providing a simple,
standard API between the EJB bean and its container.
(Note: The EJB 1.1 specification makes it clear that it does not architect the interface
between the EJB container and EJB server, which it says it left up to the vendor on
how to split the implementation of the required functionality between the two. Thus
there is no clear distinction between server and container.)
A Connector provides the ability for any Enterprise Information System (EIS) to plug
into any EJB server which supports the Connector architecture. See
http://java.sun.com/j2ee/connector/ for more indepth information on Connectors.
The current release of J2EE (1.2.1) support EJB 1.1 specification so it doesn't
implements JMS over EJB.
This kind of EJB appears only in the EJB 2.0 specifications (available at
http://java.sun.com/products/ejb/docs.html).
At this time only BEA and Silverstream support this specification. Probably in the
future more Vendors will follow this new specification, so wait...
You need to make some adjustments to your EJB bean through the deployment
descriptor. Modify the 'maxBeansInFreePool', 'maxBeansInCache' and
'idleTimeoutSeconds' fields until you get the results desired. The more you increase
the value of 'maxBeansInFreePool' and 'maxBeansInCache', the less you should have
to adjust the 'idleTimeoutSeconds' field.
Comments and alternative answers
Clustering refers to the ability of multiple load-balanced web servers to share session
and entity data. It is a major feature of web application servers. Standardized
support for clustering was one of the primary motivations behind the EJB spec.
Clustering also applies to Servlet containers sharing HttpSession data (similar to EJB
Session Beans).
For more information, see the following questions on the Servlet FAQ:
• What servlet engines support clustering -- that is, sharing of session data
across multiple load-balanced web servers?
see:
http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_deployover.html#1054622
Regards
Anoop Sehdev
More precisely, in a three-tier architecture, business logic is any code that is not
specifically related to storing and retrieving data (that's "data storage code"), or to
formatting data for display to the user (that's "presentation logic"). It makes sense,
for many reasons, to store this business logic in separate objects; the middle tier
comprises these objects. However, the divisions between the three layers are often
blurry, and business logic is more of an ideal than a reality in most programs. The
main point of the term is, you want somewhere to store the logic and "business
rules" (another buzzword) of your application, while keeping the division between
tiers clear and clean.
What are the deprecated EJB 1.0 conventions with respect to EJB 1.1?
Location: http://www.jguru.com/faq/view.jsp?EID=97827
Created: Jul 6, 2000 Modified: 2000-07-09 06:32:26.732
Author: sachin mahishi (http://www.jguru.com/guru/viewbio.jsp?EID=4437)
Question originally posed by Angus Mezick
(http://www.jguru.com/guru/viewbio.jsp?EID=81798
This are the list of changes which can be found in Chapter 1 of EJB 1.1 specification
It is as follows:-
EJB 1.1 attempts to provide a high degree of application compatibility for enterprise
beans that were written for the EJB 1.0 specification. Principally, the deployment
descriptor of EJB 1.0 based enterprise beans must be converted to the EJB 1.1 XML
format. However, the EJB 1.0 enterprise bean code does not have to be changed or
re-compiled to run in an EJB 1.1 Container, except in the following situations:
Are there any good hands-on EJB programming tutorials for WebLogic?
Location: http://www.jguru.com/faq/view.jsp?EID=97780
Created: Jul 6, 2000 Modified: 2000-10-06 22:44:31.497
Author: santosh chakrapani (http://www.jguru.com/guru/viewbio.jsp?EID=97772)
Question originally posed by zhuogang li
(http://www.jguru.com/guru/viewbio.jsp?EID=88190
Can I specify specific WHERE clauses for a find method in a CMP Entity
Bean?
Location: http://www.jguru.com/faq/view.jsp?EID=97806
Created: Jul 6, 2000 Modified: 2000-07-07 06:57:18.246
Author: sachin mahishi (http://www.jguru.com/guru/viewbio.jsp?EID=4437)
Question originally posed by Vijay Anand
(http://www.jguru.com/guru/viewbio.jsp?EID=91574
The EJB query language is totally vendor specific in EJB1.1. It is being standardized
in 1.2.
Yes, you can specify the where clause for a find method. This is the example for
EJB's deployed on weblogic:
[Note: My HttpSessions are persistent (disk swap), so if the handle is not serializable
I will have troubles when the HttpSession is restored. ]
Test result:
I have used the handle for locating local and remote EJB. I have no problem about
storing the handle inside the HttpSession and swapping the HttpSession. However if
some problem arise about the swap of the HttpSession, you may could keep the
HttpSession in memory.
Test conditions:
BEA Weblogic 4.5.1 (uses EJB 1.0 and allow keep HttpSessions in memory). Windows
NT 4.0
Observations:
I'm a little surprised about the test since I keep in mind that handles could only be
used for locating local EJB's not remote ones (wrong?).
You can refer to the url below for more info and a...
Author: kishore_k_v k (http://www.jguru.com/guru/viewbio.jsp?EID=202022), Sep
11, 2000
You can refer to the url below for more info and a clear picture on this topic although
i think you know the answers.
http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_design.html#1022000
What is the initial context factory for sun's EJB reference implementation,
and how is the initial context url specified? I always see the code fragment
"InitialContext ctx = new InitialContext();" but where are the initial
properties specified for this to work?
Location: http://www.jguru.com/faq/view.jsp?EID=98374
Created: Jul 7, 2000 Modified: 2000-07-09 06:27:55.491
Author: K J (http://www.jguru.com/guru/viewbio.jsp?EID=98373) Question originally
posed by Juan Rodriguez (http://www.jguru.com/guru/viewbio.jsp?EID=18476
When you are getting an initial context from outside of the EJB Container, you must
specify the properties for the initial context. These properties include the
InitialContextFactory class, the url of the server, and possibly authentication
parameters. These properties can either by created programatically using a
java.util.Properties object, or can be loaded at runtime from the jndi.properties file in
the classpath.
If you are using Sun's J2EE reference implementation in developing and deploying
EJBs, you are most likely including the J2EE.jar file in your classpath, which is
located in %J2EE_HOME%\lib\. If you look inside of this jar file, you will notice that
in the root of the jar file there is a jndi.properties file. This file sets up the initial
context properties for the Sun J2EE reference implementation. This is why you can
just make a call such as:
without setting up the initial context properties, when using the Sun reference
platform. If you use any other J2EE Application server, you will be required to set up
those properties.
How can I write EJBs that will run (unmodified) in any EJB-Container? What
do I have to pay attention to?
Location: http://www.jguru.com/faq/view.jsp?EID=99739
Created: Jul 10, 2000 Modified: 2000-07-11 14:57:21.311
Author: Archana Karnik (http://www.jguru.com/guru/viewbio.jsp?EID=68139)
Question originally posed by Aladin Sindbad
(http://www.jguru.com/guru/viewbio.jsp?EID=83931
EJB containers are provided by App servers like Weblogic, Websphere etc. EJB
specification does not assure any interoperability between different App servers , in
turn between containers generated by app servers.
When writing EJBs, do not use any vendor specific packages. Stick to javax packages
(as per EJB spects). If you observe this rule, your EJB s should run on any App
server.
Also, check EJB 2.0 spects. They define minimum interoperability standards between
app servers using RMI - IIOP. But I did not find whether it's mandatory for the
vendors or not. I am waiting for the final EJB 2.0 spec to be released.
1. With CMP entity beans, be careful of how you map SQL types to Java types:
WebLogic, at least, is pretty touchy here.
2. If you're lucky enough to be using a container whose CMP can handle
dependant ('value') objects, don't use that feature - it's not at all portable in
EJB 1.1 (2.0 is much better, but much different)
3. As the above points imply, BMP might tend to be much more portable. Make
sure that you do datasource lookups by the spec, though, and you might want
to think about making the datasource JNDI name (the whole shot:
"java:/comp/env/jdbc/DataSourceName") an environment entry (I've run into
bugs where containers weren't putting datasources in the spec-ordained
"java:/comp/env/jdbc" namespace
4. Make sure you use the ejb-reference deployment descriptor stuff, don't use a
client-style lookup from an EJB
5. Stick with the spec, even if you're using a server that allows more fredom.
Don't use threads, don't read the filesystem directly, etc. (Some containers will
let you get away with some of these)
I've got some CMP beans that will run in Weblogic and IAS, getting there was a bit of
an adventure.
Re: I'm not sure why the answer to this question dwells...
Author: Arun Balaji (http://www.jguru.com/guru/viewbio.jsp?EID=119257), Aug
10, 2001
Just to add to Dan's post - you should also consider issues like concurrency which
is not laid out in EJB 1.1. While containers like Weblogic5.1 use pessimistic
concurrency, others like Websphere use optimistic. You may have to plug in
versioning in your code to do staleness checks.
How can a EJB talk to legacy applications written in ILE/RPG without using
the IBM java toolbox?
Location: http://www.jguru.com/faq/view.jsp?EID=100504
Created: Jul 12, 2000 Modified: 2000-07-18 01:44:01.291
Author: Zack Li (http://www.jguru.com/guru/viewbio.jsp?EID=100500) Question
originally posed by Revathy Subramani
(http://www.jguru.com/guru/viewbio.jsp?EID=89892
If there is a method in an Entity EJB that does not modify the bean's data
(read only), can I specify that load() and store() methods should not be
called before and after the call to this method?
Location: http://www.jguru.com/faq/view.jsp?EID=101301
Created: Jul 13, 2000 Modified: 2000-07-18 03:24:40.017
Author: Prasad Thammineni (http://www.jguru.com/guru/viewbio.jsp?EID=36479)
Question originally posed by Corneanu Dan
(http://www.jguru.com/guru/viewbio.jsp?EID=41082
The EJB 1.1 specification does not define any such business method contracts that
you can use as read-only methods (methods which do not call ejbLoad() and
ejbStore()).
Application servers like WebSphere provide you with an ability to specify beans as
read-only. When flagged as read-only in the bean deployment descriptor, WebSphere
optmizes the database access and the use of transaction control mechanisms.
Which, if any, of the automatically generated stub & skeleton class files
does one need to include in a JAR file to be used when creating stand-alone
clients? (I would like to create a client-side jar file which contains only the
class files actually needed by the client.)
Location: http://www.jguru.com/faq/view.jsp?EID=105016
Created: Jul 18, 2000 Modified: 2000-08-11 12:14:09.972
Author: Siva Visveswaran (http://www.jguru.com/guru/viewbio.jsp?EID=46210)
Question originally posed by keith hawkins
(http://www.jguru.com/guru/viewbio.jsp?EID=83055
The answer is really not that generic as one may like to believe! Basically what a
client needs to invoke the services of an EJB layer are:
• locate the home interface (using a JNDI SPI) & invoke methods of the bean
instances (over IIOP). Depending on the vendor (e.g. IONA builds JNDI over
CORBA) the actual files will vary. You have to check with your vendor.
• definitions of serializable objects that are returned to client due to network
considerations (instead of object references).
[Can someone please provide examples, for a specific EJB server if need be?]
See also:
• What classes does a client application need to access EJB? (hmm, kind of
redundant, oops :-)
For RMI clients (standalone) all you require is to copy your stub (generated using
rmic) and the remote interface (wherein you define the remotely invokable methods)
to your client directory, or jar it along with the client implementation of your
program. Thus you require 3 things only.. 1)stub 2)remote Interface 3)client
implementation Hope this solves your problem.. Sharad
Please show me an example of an Entity Bean that accesses more than one
database table, using BMP.
Location: http://www.jguru.com/faq/view.jsp?EID=105215
Created: Jul 18, 2000 Modified: 2000-08-09 20:09:15.717
Author: Asit Padhi (http://www.jguru.com/guru/viewbio.jsp?EID=61648) Question
originally posed by Mohan Raj (http://www.jguru.com/guru/viewbio.jsp?EID=66168
here is the total code of an entity bean that uses multiple table using BMP
package com.orillion.india.nds.ejb.entity;
try {
makeConnection();
closeConnection();
}
return cableId ;
}
//FindByPK method
public Integer ejbFindByPrimaryKey(Integer
primaryKey)
throws javax.ejb.FinderException
{
try {
makeConnection();
if (selectByPrimaryKey(primaryKey)) {
return primaryKey;
}
else {
throw new ObjectNotFoundException
("Row for id " + primaryKey + " not found.");
}
} catch (Exception ex) {
throw new EJBException("ejbFindByPrimaryKey: " +
ex.getMessage());
}
finally {
closeConnection();
}
//Remove Methods....
public void ejbRemove()
throws java.rmi.RemoteException,
javax.ejb.EJBException, javax.ejb.RemoveException
{
try {
makeConnection();
deleteRow(cableId);
} catch (Exception ex) {
throw new EJBException("ejbRemove: " +
ex.getMessage());
}
finally {
closeConnection();
}
}
out.defaultWriteObject();
}
in.defaultReadObject();
}
// serialization done ///
prepStmt.setInt(1, cableId.intValue());
prepStmt.setString(2, cabName);
prepStmt.setString(3,cabType);
if(cabLongName !=null)
prepStmt.setString(4, cabLongName);
else
prepStmt.setNull(4,Types.VARCHAR);
prepStmt.setInt(5, vendorId.intValue());
if(partNum !=null)
prepStmt.setString(6, partNum);
else
prepStmt.setNull(6,Types.VARCHAR);
prepStmt.setString(7, actualState);
prepStmt.setDate(8, actualStateDate);
prepStmt.setString(9, actualSubState);
prepStmt.executeUpdate();
//System.out.println("created the record" +
cableId);
prepStmt.close();
}
private void insertRowIntoConcat(int cabid, int
cabConcatenate,
int position) throws SQLException {
String insertStatement =
"insert into cableconcatenation values ( ?
, ? , ? )";
PreparedStatement prepStmt =
con.prepareStatement(insertStatement);
prepStmt.setInt(1, cabid);
prepStmt.setInt(2,cabConcatenate);
prepStmt.setInt(3, position);
prepStmt.executeUpdate();
prepStmt.close();
}
private void deleteRow(Integer cableId) throws
SQLException {
String deleteStatement =
"delete from cable where cableId = ? ";
PreparedStatement prepStmt =
con.prepareStatement(deleteStatement);
prepStmt.setInt(1, cableId.intValue());
prepStmt.executeUpdate();
prepStmt.close();
}
String deleteStatement =
"delete from cableconcatenation where
cabconcatenate = ? ";
PreparedStatement prepStmt =
con.prepareStatement(deleteStatement);
prepStmt.setInt(1, cabConId.intValue());
prepStmt.executeUpdate();
prepStmt.close();
}
String selectStatement =
"select cableId " +
"from cable where cableId = ? ";
PreparedStatement prepStmt =
con.prepareStatement(selectStatement);
prepStmt.setInt(1, primaryKey.intValue());
ResultSet rs = prepStmt.executeQuery();
boolean result = rs.next();
prepStmt.close();
return result;
}
String selectStatement =
"select
cabName,cabType,cabLongName,vendorId,partNum,actualState,ac
tualStateDate,actualSubState " +
"from cable where cableId = ? ";
PreparedStatement prepStmt =
con.prepareStatement(selectStatement);
prepStmt.setInt(1,this.cableId.intValue());
ResultSet rs = prepStmt.executeQuery();
if (rs.next()) {
this.cabName = rs.getString(1);
this.cabType = rs.getString(2);
this.cabLongName = rs.getString(3);
this.vendorId = new Integer(rs.getInt(4));
this.partNum = rs.getString(5);
this.actualState = rs.getString(6);
this.actualStateDate = rs.getDate(7);
this.actualSubState = rs.getString(8);
prepStmt.close();
}
else {
prepStmt.close();
throw new NoSuchEntityException("Row for id " +
cableId +
" not found in database.");
}
String selectStatement1 =
"select cabId from CableConcatenation where
cabconcatenate = ? order by listposition ";
PreparedStatement prepStmt1 =
con.prepareStatement(selectStatement1);
prepStmt1.setInt(1,this.cableId.intValue());
ResultSet rs1 = prepStmt1.executeQuery();
while (rs1.next()) {
this.conCat.addElement(new Integer(rs1.getInt(1)));
}
if(!(conCat.size() > 0)) this.conCat =new Vector();
prepStmt1.close();
prepStmt.setString(1, cabName);
prepStmt.setString(2, cabType);
if(cabLongName !=null)
prepStmt.setString(3, cabLongName);
else
prepStmt.setNull(3,Types.VARCHAR);
prepStmt.setInt(4, vendorId.intValue());
if(partNum !=null)
prepStmt.setString(5, partNum);
else
prepStmt.setNull(5,Types.VARCHAR);
prepStmt.setString(6, actualState);
prepStmt.setDate(7, actualStateDate);
prepStmt.setString(8, actualSubState);
prepStmt.setInt(9, cableId.intValue());
int rowCount = 0;
try {
rowCount = prepStmt.executeUpdate();
if(conCat.size()> 0) {
deleteRowFromConcat(cableId);
insertIntoConcatenation(cableId,conCat);
}
} catch (SQLException e) {
//e.printStackTrace();
}
prepStmt.close();
if (rowCount == 0) {
throw new EJBException("Storing row for id " +
cableId + " failed.");
}
}
private void insertIntoConcatenation(Integer
cabid,Vector concatenation) throws SQLException {
insertRowIntoConcat(id.intValue(),cabid.intValue(),i+1);
}
}
Comments and alternative answers
See the JNDI FAQ and the LDAP Topic for information on using LDAP from J2EE.
(There is nothing particularly special about using LDAP from EJB, as opposed to any
other use of LDAP from Java.)
Comments and alternative answers
Where can I find EJB components for retail, health care, and utility
solutions?
Location: http://www.jguru.com/faq/view.jsp?EID=111072
Created: Jul 25, 2000 Modified: 2000-07-27 06:41:34.894
Author: Siva Visveswaran (http://www.jguru.com/guru/viewbio.jsp?EID=46210)
Question originally posed by sharon wahl
(http://www.jguru.com/guru/viewbio.jsp?EID=101124
Sure this is just a start and will require some research on the promised component
packages. Since the rather tepid success of IBM's San Francisco, many have not
ventured into productizing reusable components especially for verticals you have
mentioned. Companies like BEA Systems (eBusiness Smart Components) and IBM
(San Francisco) provide some foundation components to get jumpstarted. Others
include TheortCenter (eBSC) and DigitalHarbor (Charisma) - unfortunately not for
the verticals you have listed.
When using a stateful session bean with an idle timeout set, how can the
bean receive notification from the container that it is being removed due to
timeout?
Location: http://www.jguru.com/faq/view.jsp?EID=111811
Created: Jul 26, 2000 Modified: 2000-08-13 15:59:56.613
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by K J
(http://www.jguru.com/guru/viewbio.jsp?EID=98373
[Question continues: ? (Through some tests, it looks like none of the standard EJB
callback methods are called when a stateful session bean is removed due to idle-
timeout.)]
According to the spec, ejbRemove need not (or must not) be called in this case.
ejbPassivate is simply the Wrong Thing to be called (the bean is transitioning to the
'does not exist' state, not the 'passive' state).
The EJB 1.1. spec says in section 6.6.3 Missed ejbRemove Calls:
The application using the session bean should provide some clean up mechanism to
periodically clean up the unreleased resources.
Probably not the answer you're looking for, especially if you allocate some other
resource (a Message Queue, for example) that you need to release. Although, if
you're using a resource, you really should be getting it when you need it (via JNDI)
and returning it back to the pool right away.
The spec says no. Really, (IMHO) these don't translate well to the life of an entity
bean for the following reasons:
• afterBegin might not mean much since the entity might join the transaction
long (computerwise) after the transaction is started.
• Anything an entity bean needs to do 'beforeCompletion' should be done in
ejbStore.
• An entity bean really can't do much 'afterCompletion' - by definition, the
entity's state is already wherever it needs to be (database, queue, legacy
system, etc.)
You might want to re-evaluate what you're actually trying to do: chances are you're
missing a key abstraction in your model.
Comments and alternative answers
Dan. Not Entity Bean but Session bean with BMP
Author: Seetesh H (http://www.jguru.com/guru/viewbio.jsp?EID=1038574), Dec 17,
2002
Hi Dan
The question out here refers to Session bean with BMP and not Entity bean.
As BMP has full control over transactions, can I use the SessionSynchronization
methods?
Seetesh
In short, JavaBeans are not special; you access EJBs from JavaBeans the way you
would from any other EJB client.
However, JavaBeans can be useful as a 'wrapper' for EJBs that hide some of the
complexities of EJBs and allow their use from other Java programs. A visual
JavaBean, in particular, can be assembled in a GUI "bean builder" application, while
an EJB often cannot. However, adapting an EJB to become a JavaBean can be very
complicated and should not be undertaken lightly.
Perhaps another Guru can give feedback to this response with an example and/or
source code demonstrating this technique.
Yes.
The EJB client (in this case your servlet) acquires a remote reference to an EJB from
the Home Interface; that reference is serializable and can be passed from servlet to
servlet.
If it is a session bean, then the EJB server will consider your web client's servlet
session to correspond to a single EJB session, which is usually (but not always) what
you want.
Using Websphere for a small EJB application deployment, why do I get the
message "The jar file you have created does not contain any beans.Please
select a jar file with beans in it".
Location: http://www.jguru.com/faq/view.jsp?EID=114476
Created: Jul 30, 2000 Modified: 2000-07-31 03:29:06.125
Author: Shaun Childers (http://www.jguru.com/guru/viewbio.jsp?EID=30243)
Question originally posed by Yogesh Beri
(http://www.jguru.com/guru/viewbio.jsp?EID=99548
This isn't particularly due to the fact that you are using Websphere, although I won't
rule that out here based on what you have described. The way to check this would be
to try to deploy the same JAR file in Weblogic and see if you receive the same error
message.
More than likely, your problem is the fact that your manifest (serialized, in the JAR
file) is pointing to a bean, say, com.mycompany.mybean.BigBean and inside the JAR
file, the package structure for this bean does not match. In other words, you should
see the exact folder structure of the BigBean in the JAR file as in the manifest file.
So, your JAR file should display the file, BigBean, and then under the 'Path' section,
you should have com/mycompany/mybean/. So, if this is your problem, look at how
you are JARring up your files, the package structure in your classes and you might
need to modify your manifest file.
The jar file you have created may not have a Serialized...
Author: Munish Pandhi (http://www.jguru.com/guru/viewbio.jsp?EID=270315), Dec
12, 2000
The jar file you have created may not have a Serialized Deployment Descriptor file
contained within in it.
1. To prepare the jar file a file named manifest with no extension should be created in
the same package as that of Remote Interface , Home Interface , Bean Class ,Key
Class ( FinderHelper Interface ,FinderObject Class only in case of container managed
persistence entity bean) . The following two lines should be added in the manifest file
:
Name : package/serialized deployment descriptor name.ser Enterprise-
Bean: True
(Here .ser is the extension of serialized deployment descriptor file) The directory tree
of package should be separated by forward slashes(‘/’) . 2. The following command
should be used on command line to create the jar file(Java Archive)
C:\..\project>jar cmf package directory tree\manifest entitybean jar
file name.jar package directory tree\*.class package directory
tree\*.java package directory tree\*.ser
The project is the directory just above where directory tree of the package lies.
In the manifest defined is depicting the path of serialized deployment descriptor and
while using the JAR utility to create the jar file of entity bean we tell the JAR utility
to use our manifest information to create the jar file of entity bean.
If you don’t want to add .java files in the jar file then remove package directory\*.java
from above command.
What is the difference between a Component Transaction Monitor (CTM) and
an Application Server?
Location: http://www.jguru.com/faq/view.jsp?EID=114746
Created: Jul 30, 2000 Modified: 2000-08-03 22:20:06.412
Author: Doug Bell (http://www.jguru.com/guru/viewbio.jsp?EID=113602) Question
originally posed by Nagaraj shyagale
(http://www.jguru.com/guru/viewbio.jsp?EID=29160
[Can someone give feedback with examples of a CTM? Also, is this different from a
TP Monitor? -Alex]
Correct me if I am wrong. These are the words from the famous Enterprise JavaBeans
from O'Reilly.
Regards
Anoop Sehdev
How can I call one EJB from inside of another EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=114944
Created: Jul 31, 2000 Modified: 2000-07-31 05:01:34.042
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by biju mathew
(http://www.jguru.com/guru/viewbio.jsp?EID=90463
Just do it!
EJBs can be clients of other EJBs. It just works. Really. Use JNDI to locate the Home
Interface of the other bean, then acquire an instance reference, and so forth.
How good is the performance of EJB systems? Are there any benchmarks?
Location: http://www.jguru.com/faq/view.jsp?EID=115140
Created: Jul 31, 2000 Modified: 2000-07-31 05:27:47.907
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by Lee Fuller
(http://www.jguru.com/guru/viewbio.jsp?EID=109421
What I mean is this: EJBs allow you to make an application distributed and scalable.
This can have a huge positive impact on performance -- if your application really is
running in a cluster, on dozens of host machines simultaneously, with hundreds of
simultaneous clients. However, the performance of each individual machine will
usually be much slower than the same application running on a single app server.
This is because of the overhead introduced by the EJB server managing your
persistence and transactions for you.
However, like I said, this is by design. As a simple illustration of this, think about
session data. In a simple web server environment, the session data is stored in RAM,
and stays resident for the life of the client session. Access to this session data is very
fast. In a distributed, EJB server environment, the session data may get swapped to
disk between client requests, and the client may connect to a different host for the
second request. This requires more work to save and load the data for each request,
so performance must suffer. However, it also allows many more client sessions to be
active simultaneously, and to make use of the same (limited) amount of RAM per
machine, and to use many many many machines in your cluster.
EJB performance is a classic "hockey stick" curve: the performance suffers in the
short term (small number of hosts), then improves greatly in the long term (large
number of hosts). Another way to look at it is that it enables the "just throw money
at it" solution (i.e. more servers) to actually have a chance of success.
As for benchmarking: as far as I know, nobody has done any benchmarks comparing
different EJB servers, or comparing EJB with other similar technologies. And once
they do, everyone will find problems with it, as usual.
Flame on! Please feel free to object violently to any of the above assertions. That's
what the "feedback" function is for! :-)
http://www.iplanet.com/products/infrastructure/app_servers/wp_dhbrown.html
http://www.iplanet.com/products/infrastructure/app_servers/wp_dhbrown.pdf
To easily achieve this, you can call both inserts from another bean, for example a
Session Bean (if you are using the standard Session wraps Entity design pattern).
Lets say that both Entity Beans have defined create methods, and that the Session
Bean has a method called insertEntities(). Inside the insertEntities() method, you
would obtain handles to the approriate home interfaces and call create on each one.
The trick here is on how you set up the transaction attributes.
You would like both of your Entity Beans to share the same transaction, and in this
example, we can have the Session Bean as the initiator of the transaction.
If we set the insertEntites() method to have a Transaction Attribute of REQUIRED or
REQUIRES_NEW, then we assure that a transaction will be present. (REQUIRED is
generally more robust, since it allows this insertEntities() call to be part of an
ongoing, larger transaction, but if one is not in progress, a new one will be created.)
If we then set the Transaction Attributes for each of the Entity Beans to REQUIRED,
then the same Transaction Context will be propagated from the Session Bean to both
Entity Beans, achieving the result you are after.
[Note that this works no matter which Persistence method (CMP or BMP) the Entity
Beans use.]
This depends on which EJB container / JNDI implementation that you are using.
Using the Inprise Application Server, it will do this automatically if you are within the
same subnet using the Smart Agent, or you can pass a command-line parameter into
the virtual machine.
You should refer to the documentation for the implementation that you are using for
the exact specifics.
How do I use JNDI to locate the home interface of an EJB running on a different
host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug 27,
2001
How do we do this using J2EE server and where is this property specified?
Re: How do I use JNDI to locate the home interface of an EJB running on a
different host?
Author: James Chiang (http://www.jguru.com/guru/viewbio.jsp?EID=341533),
Aug 29, 2001
Setting the following env. when instantiating InitialContext:
Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url",
"iiop://hostname:1050");
InitialContext jndiCtx = new InitialContext(env);
Re: Re: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436),
Aug 29, 2001
Thanks, James...but will this work for all application servers...i am using J2EE
server currently. And how do we know whether our iiop port is 1050(as u have
given in code).
Re: Re: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug
29, 2001
I tried it out but it gives following error on running the client.
javax.naming.NameNotFoundException. Root exception is
org.omg.CosNaming.NamingC ontextPackage.NotFound at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(Unknown
So urce) at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.extract(Unknown
Source) at org.omg.CosNaming._NamingContextStub.resolve(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.callResolve(Unknown Source) at
com.sun.jndi.cosnaming.CNCtx.lookup(Unknown Source) at
com.sun.jndi.cosnaming.CNCtx.lookup(Unknown Source) at
javax.naming.InitialContext.lookup(Unknown Source) at
ConverterClient.main(ConverterClient.java:27)
Re: Re: Re: How do I use JNDI to locate the home interface of an EJB
running on a different host?
Author: James Chiang
(http://www.jguru.com/guru/viewbio.jsp?EID=341533), Aug 29, 2001
It's indeed port 1050 for SUN's j2ee RI server. You can type "j2ee -verbose"
to find the naming service port.
As to solve NotFoundException, just copy j2ee.jar (located at
%J2EE_HOME%\lib) to the client end and set into classpath.
Re: Re: Re: Re: How do I use JNDI to locate the home interface of
an EJB running on a different host?
Author: Sribha Jain
(http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug 29, 2001
I have already done that, but the problem persists...
Re: Re: Re: Re: Re: How do I use JNDI to locate the home
interface of an EJB running on a different host?
Author: moiroux matthieu
(http://www.jguru.com/guru/viewbio.jsp?EID=540275), Nov 6, 2001
i've just try it and it work tx !
Re[2]: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Vassilis Mokas
(http://www.jguru.com/guru/viewbio.jsp?EID=855498), Apr 26, 2002
Can you please tell me the corresponding code for Borland Application Server
4.5 or 5 ? I just want to locate an EJB in BAS using a servlet in Tomcat.
I was just going through the same discovery process with the Borland
AppServer, and found myself at the same place you must have been a
while ago...
javax.naming.Context context;
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.inprise.j2ee.jndi.CtxFactory");
env.put(javax.naming.Context.URL_PKG_PREFIXES,
"com.inprise.j2ee");
context = new javax.naming.InitialContext(env);
The documentation states that URL_PKG_PREFIXES is necessary to support
the standard java:comp namespace.
Cheers,
laurent
Re[2]: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: test sherchan (http://www.jguru.com/guru/viewbio.jsp?EID=962675),
Jul 24, 2002
I am getting the same problem and i am using J2EE server. Can u tell me plz
how to set that env.
Re[3]: How do I use JNDI to locate the home interface of an EJB running on a
different host?
Author: frank xing (http://www.jguru.com/guru/viewbio.jsp?EID=918691), Oct 23, 2002
The way to use JNDI to locate a home interface of an
EJB on remote host differs among different application servers.
As I am using WebLogic6.1, the steps are as follows:
1. at the client side, set the weblogic.jar in your classpath.
2. You have to prepare a Properties object for initialContext, that is:
Properties p = new Properties();
//weblogic's JNDI driver(provider)
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory
And for other application servers, you need to obtain the corresponding JNDI
provider(driver) as step1, set the INITIAL_CONTEXT_FACTORY and PROVIDER_URL
step2 and then follow step 3, 4, 5.
Re: How do I use JNDI to locate the home interface of an EJB running on
a different host? [JBoss]
Author: Edison Wang
(http://www.jguru.com/guru/viewbio.jsp?EID=1149288), Feb 25, 2004
I was about to post a new thread on the forums when I see this one... I sort of
understood how the looking up to another host is now, but which namespace
should I put in for this line? I'm also not sure whether the IIOP for JBoss is on
port 1050.
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
Most application servers provide an api to do logging, however if you want maximum
portability, I would recommend using a third party package, that you can take with
you. An open source libarary such as log4java http://www.log4j.org/ can be used
and fits well with a variety of technologies including EJB and CORBA.
[Does log4j really have support for multitier architectures? That is, so log messages
generated on different hosts end up in the same place? -Alex]
Comments and alternative answers
Yes. Log4j supports remote logging with the SocketAppender. A client can send its
log records to a remote server which can log it according to local server policy. This
includes the ability to log the incoming record on multiple output targets and even to
send the log record to a second log server.
Should I use Entity Beans for all database tables, even though they may
have complicated relations and joins? Or should I just use them for
frequently-used and simple tables such as account info?
Location: http://www.jguru.com/faq/view.jsp?EID=116658
Created: Aug 1, 2000 Modified: 2000-08-04 04:12:44.822
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Kim Wang
(http://www.jguru.com/guru/viewbio.jsp?EID=99794
This is a question for which there is no "yes-or-no" answer for and depends on the
functionality of the product(s) that you are using, and the requirement of the
system.
An example of this is the ability to support dependant objects, which is coming in EJB
2.0, Inprise Application Server 4.1 supports this feature, where you can have non-
EJB Java objects inside your Entity Beans, which map to different tables in the
database. Giving you one entity bean covering multiple tables.
As a general note, I like to use Entity Beans which wrap a table and its dependants,
so that other programmers do not have to remodel simple relationships such as
Orders/OrderLines if there was an Entity Bean per table.
The Transaction Attributes in EJB do not map to the Transaction Isolation levels used
in JDBC. This is a common misconception.
For more details and a summary of Transaction Attributes refer to section 11.6 of the
EJB 1.1 specification.
[Now, how would we actually set JDBC attributes from inside or outside an EJB
method? -Alex]
Each EJB class has an associated EJBMetaData class that can be retrieved from the
Home interface of the bean.
One thing that you will have to consider is using an EJB server that support dynamic
stub downloading, so that you can make remote calls to the EJB.
When using Primary Keys, why do I have to implement the hashCode() and
equals() method in my bean?
Location: http://www.jguru.com/faq/view.jsp?EID=118541
Created: Aug 3, 2000 Modified: 2000-08-15 06:29:09.591
Author: Ryan Lynch (http://www.jguru.com/guru/viewbio.jsp?EID=118538) Question
originally posed by lyndon mendoza
(http://www.jguru.com/guru/viewbio.jsp?EID=8369
Implementing the hashCode() and equals() functions ensure that the primary key
object works properly when used with hash tables. Hash tables are the preferred way
EJB servers use to store and quickly retrieve instantiated entity beans.
If session #1 uses widget "A" (which is an entity bean) then the server needs to do
some work to instantiate and initialize the object. If session #2 then requests the
same widget "A", the EJB server will look in its hash table of existing entity beans of
type widget to see if widget "A" has already been instantiated.
The equals() method needs to compare two primary keys to determine if they are
equal, which is to say that they refer to the same element in the database. The default
implemention of Object.equals() uses object identity, so it only returns true if
the objects are the same object. You need to provide an implementation of
equals() that is based on the content of the primary keys.
if a.equals(b) then a.hashCode() ==
b.hashCode()
Are there any good books that cover EJB (and related topics like LDAP and
so on)?
Location: http://www.jguru.com/faq/view.jsp?EID=119643
Created: Aug 4, 2000 Modified: 2000-08-04 13:18:39.763
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by mathew koshy
(http://www.jguru.com/guru/viewbio.jsp?EID=110668
Check out Enterprise JavaBeans from O'Reilly by our pal Richard Monson-Haefel. The
O'Reilly series also has good books on Security, Distributed Computing, and so on.
See also
If Client C calls EJB A, and EJB A calls EJB B, then will the methods in B be
invoked with the same security context of Client C?
Location: http://www.jguru.com/faq/view.jsp?EID=119676
Created: Aug 4, 2000 Modified: 2000-08-08 01:06:38.194
Author: Prasad Thammineni (http://www.jguru.com/guru/viewbio.jsp?EID=36479)
Question originally posed by tirumala kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=94613
It depends on how you configure the EJBs. If you set the EJB A and B's run-as-
modes to CLIENT_IDENITY in the deployment descriptor, all methods in A and
methods in B will execute within the security context of Client C.
Comments and alternative answers
Yes, multiple EJBs can be deployed in a single jar file. The deployment is somewhat
different between EJB 1.0 and EJB 1.1.
In EJB 1.0 each bean has a separate serialized deployment descriptor. All of the bean
classes and deployment descriptors are placed in the jar file along with the manifest
file named META-INF/MANIFEST.MF. The manifest file must contain an entry for each
bean that names the bean's deployment descriptor. For example, the following
manifest is for a jar file that contains two deployment descriptors:
Name: BeanADD.ser
Enterprise-Bean: True
Name: dirname/BeanBDD.ser
Enterprise-Bean: True
Note that a blank line is required between the entries in the manifest file.
In EJB 1.1 and in the draft EJB 2.0 specification, instead of a manifest and serialized
deployment descriptors there is a single shared XML deployment descriptor named
META-INF/ejb-jar.xml. Within ejb-jar.xml there must be either a <session> or
<entity> element for each bean in the jar file. For example, the following XML
fragment is for a jar file that contains one entity and one session bean:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>MySessionBean</ejb-name>
... other xml elements describing the bean's deployment
properties ...
</session>
<entity>
<ejb-name>MyEntityBean</ejb-name>
... other xml elements describing the bean's deployment
properties ...
</entity>
</enterprise-beans>
</ejb-jar>
The EJB 2.0 draft specification for deployment descriptors differs from EJB 1.1 only in
the addition of XML elements for describing additional bean properties.
No, Tomcat does not support EJB. It is a Servlet/JSP container, not an EJB container.
The Jakarta Project provides an implementation of the Servlets API called Tomcat,
and an implementation of JavaServer Pages called Jasper. These are bundled
together in the Tomcat release.
However, the J2EE Reference Implementation, which supports EJB, is bundled with
an old version of Tomcat. This adds Tomcat's support for Servlets and JSP to the
J2EE product.
See also
• Can I use the latest version of Tomcat inside Sun's J2EE implementation?
• Can I use the Apache Web Server with the Sun J2EE Reference
Implementation?
It's a snap to set up and configure Tomcat w/ it, if you follow the advice given on their
site.
What are the viable alternatives for calling EJBs from non-Java programs?
Specifically, I'm interested in calling EJBs (probably indirectly) from plain
old C language.
Location: http://www.jguru.com/faq/view.jsp?EID=124198
Created: Aug 10, 2000 Modified: 2000-08-10 10:29:51.64
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by Marty Hill
(http://www.jguru.com/guru/viewbio.jsp?EID=115510
See also How can I access my EJBs from COM environments such as VB?
You can call Java methods from C using JNI, you can...
Author: Jim Coker (http://www.jguru.com/guru/viewbio.jsp?EID=2), Aug 10, 2000
You can call Java methods from C using JNI, you can also access Java data structures
directly.
Its codegenerator accepts compiled Java classes as input and generates C++ proxy
classes for them. These proxy classes can be used like normal C++ classes, but totally
transparently to the developer a JVM gets launched when they are used the first time.
All operations on these classes result in the execution of the underlying Java code.
The connection is made through JNI, but you're totally insulated from it by the
generated code.
Once you're in C++, it's very easy to hook the code up to a C program.
One nice benefit of this solution is that all Java types are available to the C++
program. In CORBA you are limited to primitive and IDL-declared types.
Another benefit is that you can use complex Java datatypes in your C++ program
without having to convert the data. Take for example the java.util.Date type. If
your EJB server tries to return a date to a client, how do you have to do this for a C
client? In Java you just return the Date instance but for a C/C++ client you would
have to convert it to some kind of "seconds since" value or extract integers for the
C/C++ client to be able to make sense of it. That's code that you have to write just to
accommodate a language choice on the client.
Using JunC++ion on the other hand, you just use the C++ Date proxy class on the
client side and have full access to its rich call interface.
EJB-IDL-C++
Author: parul dholakia (http://www.jguru.com/guru/viewbio.jsp?EID=451179), Jul
26, 2001
You can convert EJB to IDL and then IDL to c++ which is ofcourse a CORBA
solution.
It depends :-)
Usually you're fine just calling the EB methods (actually, create, and sometimes
remove, would be called on the EJBHome). Use the SB if you have other things you
want to do at the same time, like adding/removing other dependent entity beans, or
logging the action, or performing additional validation.
See also Should I use Entity Beans for all database tables, even though they may
have complicated relations and joins? Or should I just use them for frequently-used
and simple tables such as account info?
Remember that every call to an EJB is a transaction (unless your client is managing
the transaction itself, which is probably more than you really want to do).
Can someone explain in detail the different steps involved in adding 'finder'
methods other than 'findByPrimaryKey' in IBM's VisualAge for Java?
Location: http://www.jguru.com/faq/view.jsp?EID=124806
Created: Aug 11, 2000 Modified: 2000-08-11 13:12:28.152
Author: Badri Kuppa (http://www.jguru.com/guru/viewbio.jsp?EID=98194) Question
originally posed by shyla rajeev
(http://www.jguru.com/guru/viewbio.jsp?EID=111902
You can create finder methods in the Home Interface and give an SQL hint in the
finderHelper class. For example if you want to create a finder method for userId then
the method in the home interface would be like this.
ObjectToBeReturned findByUserId(String userId) throws java.rmi.RemoteException,
javax.ejb.FinderException;
then in the finder helper class you can put this line..
findBy+toBeFound+whereClause
you can replace the where clause by a select statement too!
--Badri bkuppa@usa.net
Applied to web applications and distributed programming, the three logical tiers
usually correspond to the physical separation between three types of devices or
hosts:
However, inside of the application server, there is a further division of program code
into three logical tiers. This is kind of fractal: the part (app server object design)
resembles the whole (physical system architecture). In a classic JSP/Servlet system,
these objects are usually implemented as:
1. JSPs or Servlets responsible for creating HTML or WML user interface pages
2. Servlets or JavaBeans responsible for business logic
3. Servlets, JavaBeans, or Java classes responsible for data access. These
objects usually use JDBC to query the database.
In an EJB system, the three logical tiers are usually implemented somewhat
differently:
As you can see, the precise definition of "tiers" can vary widely depending on the
particular needs and choices of an application designer. However, they all maintain
the general division of client-logic-storage.
If the architecture contains more than three logical tiers -- for instance, multiple data
feeds, multiple transactional data sources, multiple client applications -- then it is
typically called an "N-tier" or "Distributed" architecture.
See also:
• What seperates one tier from another in the context of n-tiered
architecture?
• In distributed architecture (typical three tier consisting of thin client,
middleware & database) which type of JDBC driver should be used
and why?
• What is meant by the term "business logic"?
• Are the following schemes 3 tiered architecture?
• What is the recommended, "best" architecture for JSP applications?
JDO and EJB are different and incompatible persistence models. While there may in
the future be an EJB server that uses JDO, no such thing currently exists, and IMHO
never should.
Comments and alternative answers
Sun's site states that JDO could be used to implement...
Author: John Francis (http://www.jguru.com/guru/viewbio.jsp?EID=296576), Jan 8,
2001
Sun's site states that JDO could be used to implement persistence for a bean using
bean managed persistence. JDO is an object to relational mapping layer, so can live
inside the implementation of the bean.
You invoke an EJB from a servlet or JSP the same way you invoke one from any
other Java code. Just read the EJB docs and FAQ and have fun!
Comments and alternative answers
Re: first create the home object, then using home, access...
Author: J C (http://www.jguru.com/guru/viewbio.jsp?EID=756527), Feb 12, 2002
This seems to be lots of details missing. When you run J2EE client with Sun's
J2EE reference implementation server, you use runclient command which sets a
number of properties. How do you set these within servlet/JSP? I guess that you
have to set these properties when starting web server (e.g., servlet), right?
Why use EJB when we can do the same thing with servlets?
Location: http://www.jguru.com/faq/view.jsp?EID=126400
Created: Aug 14, 2000 Modified: 2001-11-09 06:08:03.377
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by sreenivasulu kadirimangalam
(http://www.jguru.com/guru/viewbio.jsp?EID=123964
The most significant difference between a web application using only servlets and
one using servlets with EJBs is that the EJB model mandates a separation between
display and business logic. This is generally considered a Good Thing in non-trivial
applications because it allows for internal reuse, allows flexibility by providing a
separation of concerns, gives a logical separation for work, and allows the business
logic to be tested separately from the UI (among others).
Some of the hings that servlets and JSPs can do that EJBs cannot are:
Some of the things that EJBs enable you to do that servlets/JSPs do not are:
What restrictions are imposed on an EJB? That is, what can't an EJB do?
Location: http://www.jguru.com/faq/view.jsp?EID=127037
Created: Aug 15, 2000 Modified: 2000-08-16 00:19:27.196
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3)
From the spec:
• An enterprise Bean must not use read/write static fields. Using read-only
static fields is allowed. Therefore, it is recommended that all static fields in
the enterprise bean class be declared as final.
• An enterprise Bean must not use thread synchronization primitives to
synchronize execution of multiple instances.
• An enterprise Bean must not use the AWT functionality to attempt to output
information to a display, or to input information from a keyboard.
• An enterprise bean must not use the java.io package to attempt to access
files and directories in the file system.
• An enterprise bean must not attempt to listen on a socket, accept connections
on a socket, or use a socket for multicast.
• The enterprise bean must not attempt to query a class to obtain information
about the declared members that are not otherwise accessible to the
enterprise bean because of the security rules of the Java language. The
enterprise bean must not attempt to use the Reflection API to access
information that the security rules of the Java programming language make
unavailable.
• The enterprise bean must not attempt to create a class loader; obtain the
current class loader; set the context class loader; set security manager;
create a new security manager; stop the JVM; or change the input, output,
and error streams.
• The enterprise bean must not attempt to set the socket factory used by
ServerSocket, Socket, or the stream handler factory used by URL.
• The enterprise bean must not attempt to manage threads. The enterprise
bean must not attempt to start, stop, suspend, or resume a thread; or to
change a thread's priority or name. The enterprise bean must not attempt to
manage thread groups.
• The enterprise bean must not attempt to directly read or write a file
descriptor.
• The enterprise bean must not attempt to obtain the security policy
information for a particular code source.
• The enterprise bean must not attempt to load a native library.
• The enterprise bean must not attempt to gain access to packages and classes
that the usual rules of the Java programming language make unavailable to
the enterprise bean.
• The enterprise bean must not attempt to define a class in a package.
• The enterprise bean must not attempt to access or modify the security
configuration objects (Policy, Security, Provider, Signer, and Identity).
• The enterprise bean must not attempt to use the subclass and object
substitution features of the Java Serialization Protocol.
• The enterprise bean must not attempt to pass this as an argument or method
result. The enterprise bean must pass the result of
SessionContext.getEJBObject() or EntityContext. getEJBObject() instead.
With the EJBHome version of the remove, you are able to delete an entity bean
without first instantiating it (you can provide a PrimaryKey object as a parameter to
the remove method). The home version only works for entity beans. On the other
hand, the Remote interface version works on an entity bean that you have already
instantiated. In addition, the remote version also works on session beans (stateless
and statefull) to inform the container of your loss of interest in this bean.
[ I have looked through the EJB 1.1 spec for a requirement that containers guarantee
that entity beans in the ready state are unique (i.e. that there is never more than
one instance of a bean with a given primary key value). I cannot find such a
guarantee, but I would expect one. Does anyone know if this is indeed the case? ]
There is no such guarantee. The server (or servers) can instantiate as many
instances of the same underlying Entity Bean (with the same PK) as it wants.
However, each instance is guaranteed to have up-to-date data values, and be
transactionally consistent, so uniqueness is not required. This allows the server to
scale the system to support multiple threads, multiple concurrent requests, and
multiple hosts.
There are a couple of ways you could potentially do this. You will need to select the
one[s] which suit your environment best.
The first is the time tested legacy method of calling any external routine from within
an Oracle database, whcih is to have an external process running in the OS which is
connected to the database. You then communicate with this process via DBMS_PIPEs
and the external process becomes your agent by listening for commands, executing
the call to your EJB, confirming the call and returning any applicable results.
The other possible way to do this is to create an EJB client in the Oracle JVM. I think
this is possible as of Oracle 8.1.6.
The third way would be to use an external library call. I think you can still only do
these in C, but you will probably be able to find a way to invoke an EJB from C.
I believe that the basic reason is that mandating non-final business methods allows
container developers to implement their EJB container via inheritence. They can
generate a class that extends your bean, with methods that perform transactional
housekeeping, then call the inherited method (which is the one you wrote in your
bean), then perform more housekeeping.
That said, I know of no major container that does things this way (although some of
the OODBMS vendors may)
An Entity Bean represents persistent data that is stored outside of the EJB
Container/Server.
The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into
the container, similar to a SELECT statement in SQL.
By making this method mandatory, the client programmer can be assured that if
they have the primary key of the Entity Bean, then they can retrieve the bean
without having to create a new bean each time - which would mean creating
duplications of persistent data and break the integrity of EJB.
Generally, you should use the Handle when holding a reference to an EJB beyond
the life of a client process.
Is there a way that a Stateful Session Bean can remove itself when a
transaction commits? Without this, the remove must be performed by the
client that starts the transaction, which can be difficult when there may be
non-stateful beans in-between.
Location: http://www.jguru.com/faq/view.jsp?EID=131690
Created: Aug 21, 2000 Modified: 2000-08-21 19:05:49.861
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Alex McManus
(http://www.jguru.com/guru/viewbio.jsp?EID=117866
Container - A solution would be to set a timeout value for the stateful session bean
so that it will be removed after a shorter idle duration.
Developer - If the above is not sufficient and you need to explicitly clean up the
bean, you could try posting the Stateful Session Bean's handle in a JNDI context and
have another object check the context, obtain the handle and then call remove on
the home interface, passing in the handle as an argument. Remember that the
Handle is Serializable, so there could be many variations on this strategy.
It seems to me that calling remove explicitly is a cleaner solution, as long as you can
tell which call to the bean has been the last one in a transaction.
You should download the sample Java Pet Store sample application, It's part of the
J2EE Blueprints. http://java.sun.com/j2ee/download.html
I've read that the Primary Key field can be a wrapper class. But, no where
has it been mentioned if it can be any Java API class. To be specific, can
java.util.Vector be a Primary Key class for my bean?
Location: http://www.jguru.com/faq/view.jsp?EID=131699
Created: Aug 21, 2000 Modified: 2000-08-21 19:08:27.141
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by SRI NAGESH NAYUDU
(http://www.jguru.com/guru/viewbio.jsp?EID=122079
I am not aware of any application Server that would allow a Vector to be specified as
a primary key type for an Entity Bean.
Logically when you think about it, there is no clear database type[s] that you would
map it to in a relational database.
If you are trying to make a compound Primary Key, then you should use a wrapper
class that contains simple types.
You can specify Environment Entries that are accesssible by your EJB's. Inside your
ejb-jar.xml you define the environment entries.
<env-entry>
<env-entry-name>theParameter</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>theValue</env-entry-value>
</env-entry>
You can access the variable inside your EJB using the Environment Naming Context
(in EJB 1.1)
You cannot make a clone of an Entity Bean. This is like inserting the same row into a
database twice.
What you may want to do is to make a copy of the values inside an Entity Bean,
using the Details Object design pattern. See the pattern Description for more details.
You can use the Java 2 Platform, Enterprise Edition Client Access Services (J2EETM
CAS) COM Bridge 1.0, currently downloadable from
http://developer.java.sun.com/developer/earlyAccess/j2eecas/
The problem is that a rollback occurs AFTER the timeout, but the exception is thrown
at the END of the transaction.
The other problem is - I want to set the timeout value manually, during runtime.
I am not sure why you cannot format in ejbCreate. I assume this is some sort of CMP
issue. However, we experienced a similar issue where we needed to reference a
database generated sequence in the creation of the entity bean, and the CMP
process did not give us access to the generated number in ejbCreate. In this case,
we used the ejbPostCreate method which is called directly after ejbCreate and I
believe is specifically intended to support operations like yours.
See also How do I map a Date/Time field to an Oracle database with CMP?
When (manually) deploying an EJB where do you specify the JNDI name
that the bean is bound to in the JNDI tree?
Location: http://www.jguru.com/faq/view.jsp?EID=132923
Created: Aug 23, 2000 Modified: 2000-08-24 18:56:25.582
Author: satyanarayana sairam
(http://www.jguru.com/guru/viewbio.jsp?EID=132906) Question originally posed by
Henrik Buch (http://www.jguru.com/guru/viewbio.jsp?EID=121686
[Questioner continues: According to the EJB1.1 spec there is no relation between the
<ejb-name> tag in the deployment descriptor (or assembly descriptor) and the JNDI
name. I can see that a client can use a "logical" name that can be mapped via
vendor specific deployment info (e.g. orion-application-client.xml).]
When you are deploying the application in using Web Logic 4.5.1 server, in the
deployment wizard you can specify the JNDI name and using the same name you can
look up from the client.
[Is there any standard way to do it? If not, can someone give feedback with info for
other servers? -Alex]
Where can I find the API documentation for Enterprise JavaBeans (EJB)?
Location: http://www.jguru.com/faq/view.jsp?EID=134139
Created: Aug 24, 2000 Modified: 2000-08-24 16:08:30.543
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
The EJB API documentation is available from Sun's J2EE API documentation page.
<entity>
<ejb-name>AddressEJB</ejb-name>
<ejb-class>AddressBean</ejb-class>
<home>AddressHome</home>
<remote>Address</remote>
...
</entity>
] No - you don't have to use ejb-link every time you reference an enterprise bean
component. It allows an Application Assembler to reference an EJB by name without
the need to have unique names for all beans by constantly renaming them for the
J2EE application. And, ofcourse, such cannot be guaranteed if one buys third-party
bean components.
The example you have shown is one way that assumes the reference's EJB is in the
same ejb-jar file as the referencing bean. The other way is to use a path-name
<ejb-link>../customers/customer.jar#AddressEJB</ejb-link>
The Deployer is then responsible for binding the ejb-link references to the home of
the target bean.
From R. Monson-Haefel's book on EJB I understand, that EJB clients that are
EJB's themselves, use a somewhat different (namingcontext-)lookup
method than 'regular' clients. But why ? Why the <ejb-ref> tag in the
deployment descriptor and why the 'java:comp/env' namespace ?
Location: http://www.jguru.com/faq/view.jsp?EID=136600
Created: Aug 28, 2000 Modified: 2001-01-25 20:45:47.599
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by murali krishna
(http://www.jguru.com/guru/viewbio.jsp?EID=89398
The short answer is that the extra layer of indirection gives flexibility. Remember that
the container is supposed to give you the ability to map each bean into a fairly
arbitrary place in the JNDI namespace. Since the ejb-ref tag allows you to indicate
the interface you're interested in and the JNDI name that its home will be bound to,
the Deployer can make different decisions about these things than the Bean
Developer did.
The java:comp/env namespace was put into the 1.1 spec to simplify this and a
couple of other things. Putting all of these mappable elements under a consistent
JNDI context helps to ensure interoperability by encouraging consistency. Note that
this can also be used for things like global settings for a bean (say a threshold of
change to a salary that may only be done by someone in the 'HR Manager' role).
This all makes the most sense when you remember that EJB (and J2EE as a whole) is
a Component specification: since each of these things is a component, it should be
configurable to work with other components without code changes.
Note also that recent J2EE specs have implied that the client should be getting
references in much the same way. In fact, the 1.3 spec (available from javasoft.com
as a public draft) indicates that the application client deployment descriptor can
include <ejb-ref> stanzas
ejb reference
Author: pramod talesara (http://www.jguru.com/guru/viewbio.jsp?EID=1067448),
Mar 18, 2003
I am still not clear about ejb reference.Can any one explan me with some example.
Is there any default cache management system with Entity beans ? In other
words whether a cache of the data in database will be maintained in EJB ?
Location: http://www.jguru.com/faq/view.jsp?EID=136858
Created: Aug 28, 2000 Modified: 2000-11-05 16:12:24.651
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Karthikeyan Natarajan
(http://www.jguru.com/guru/viewbio.jsp?EID=129334
Caching data from a database inside the Application Server are what Entity EJB's are
used for.
The ejbLoad() and ejbStore() methods are used to synchronize the Entity Bean
state with the persistent storage(database).
Transactions also play an important role in this scenario. If data is removed from the
database, via an external application - your Entity Bean can still be "alive" the EJB
container. When the transaction commits, ejbStore() is called and the row will not
be found, and the transcation rolled back.
My question is that: my CMP entity bean seems to work without any cache , what is
wrong ? ( My environment is IAS on windows and SQL7.0 . Thanks .)
The following thread within the Server-side discussion forum at Javaworld offers
some concrete guidelines as to when to add EJB into the mix when designing large
web-based applications.
Can I use the latest version of Tomcat inside Sun's J2EE implementation?
Location: http://www.jguru.com/faq/view.jsp?EID=140438
Created: Sep 1, 2000 Modified: 2000-09-06 13:47:18.86
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Alex Chaffee PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=3
The J2EE reference implementation ships with Tomcat. The classes for Tomcat are
located inside the \lib\j2ee.jar. If you wanted to use the latest version of Tomcat you
would have to replace the classes in this archive.
Does the EJB specification allow for such products as the Java Cryptography
Architecture (JCA) and other security APIs, to be used from within session
beans? What are the potential issues that would need to be addressed from
doing this?
Location: http://www.jguru.com/faq/view.jsp?EID=201418
Created: Sep 8, 2000 Modified: 2000-09-11 09:21:33.378
Author: Ron Kurr (http://www.jguru.com/guru/viewbio.jsp?EID=132270) Question
originally posed by Benjamin McCartney
(http://www.jguru.com/guru/viewbio.jsp?EID=109357
I don't believe the specification talks about using any of the crypto APIs or
frameworks. The spec talks about restricting access to particular methods on a bean
and that is handled by the container using information encoded in the deployment
descriptor. If you are just talking calling some crypto APIs, I can't think of anything
that would prevent you from doing cryto work from inside a session bean. Once you
are inside a bean, you can pretty do whatever you want, with just a few exceptions.
Comments and alternative answers
Yes it can, refer to the following sections of the EJB 1.1 specification:
Session Beans (Section 6.10.2)
The session bean class may have superclasses and/or superinterfaces. If the session
bean has superclasses, then the business methods, the ejbCreate methods, the
methods of the SessionBean interface, and the methods of the optional
SessionSynchronization interface may be defined in the session bean class, or in any
of its superclasses.
The entity bean class may have superclasses and/or superinterfaces. If the entity
bean has superclasses, the business methods, the ejbCreate and ejbPostCreate
methods, the finder methods, and the methods of the EntityBean interface may be
implemented in the enterprise bean class or in any of its superclasses.
Keep in mind that the superclass must adhere to the rules and restrictions set out in
section 18.1.2 of the specification.
Is there a profiler application that runs with BEA Weblogic App Server
(v4.51) so that I can monitor my EJB's and server-side Java classes?
Location: http://www.jguru.com/faq/view.jsp?EID=201936
Created: Sep 10, 2000 Modified: 2000-09-11 09:28:25.547
Author: shilpa Tiwari (http://www.jguru.com/guru/viewbio.jsp?EID=138841)
Question originally posed by Ashok Nair
(http://www.jguru.com/guru/viewbio.jsp?EID=12502
Intuitive Systems Inc 's OptimizeIt is a profiler application that integrates with many
application servers including WebLogic 4.5.1.
OptimizeIt basically has an audit program running within WebLogic's VM once it is
integrated with WebLogic (this integration involves changes to the weblogic's policy
file and the weblogic's start script).
The OptimizeIt client ( user interface) then attches to this audit system which is
tracking the weblogic VM. This way you can attach to the weblogic server and see
the profiling information through the GUI. OptimizeIt also provides for distributed
profiling wherein you can attach to optimize its audit system running in a remote
machine's Virtual Machine (VM).
You can find the details and download the product from http://www.optimizeit.com
Is there any reason why value objects cannot have set methods?
Location: http://www.jguru.com/faq/view.jsp?EID=204044
Created: Sep 12, 2000 Modified: 2000-09-12 18:47:36.947
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by Alan Josephson
(http://www.jguru.com/guru/viewbio.jsp?EID=19134
Value objects are recommended when data has to be returned from an EJB server to
the EJB client, if none of the data has to be updated. ie. The value objects are used to
transport read-only data.
It is the equivalent of the client requesting XML from the server tier, except you get
the tighter compile time binding and control, and you don't have to parse the returned
XML.
If, instead, an equivalent EJB reference with the same 'getter' methods is returned,
then each time the client calls a getter method on the reference EJB, this results in a
remote method call to the server tier. This is an uneccessary round trip, when the
object could have held the data locally itself.
If you do need to update data, then you may need to use an EJB reference instead.
However, this fine grained querying/updating of data could become a severe
performance bottleneck, if lots of it is performed. The traffic between different tiers
needs to be minimised. Instead, EJBs should be used by clients for more coarse
granied method invocations.
For example, the client could call a session bean on the server to get a complex data
set (encapsulated in a value object), instead of just 1 row of data from 1 table. The
server session bean may have used many entity beans or jdbc directly, behind the
scenes on the server tier, however, this is hidden from the client. Once the client
recieves the complex value object, it can do as many local method calls, as it likes on
it to get the data. Then a new (or the same) object could then be constructed with all
the updated data. The client would then pass this object back to the server, to perform
the update, by calling the appropriate method on the remote session bean, passing the
new value object as the parameter.
[. e.g. the client displays alarm status of devices. If I use EJB to periodically check
the database for alarm status change, how to program the EJB to forward notification
to clients when the status is changed? ]
Asynchronous notification is a known hole in the first versions of the EJB spec. The
recommended solution to this is to use JMS, which is becoming available in J2EE-
compliant servers.
The other option, of course, is to use client-side threads and polling. This is not an
ideal solution, but it's workable for many scenarios.
See also OK, so EJB doesn't support user-created threads. So how do I perform tasks
asynchronously? .
As quoted by Allaire:
When Not to Use JRun Connection Pooling
If the JDBC driver that you are using already supports the JDBC 2.0 Connection
Pooling, Allaire recommends not using the JRun Connection Pooling mechanism for
that driver. The vendor is probably able to leverage database-specific features when
pooling that are much more efficient and/or robust than a generic connection pool
could provide."
Should I use CMP or BMP for an application with complex data manipulation
& relations?
Location: http://www.jguru.com/faq/view.jsp?EID=208299
Created: Sep 17, 2000 Modified: 2000-09-17 15:44:33.499
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by srinivasa rao
(http://www.jguru.com/guru/viewbio.jsp?EID=139339
Generally, you should use CMP unless you're forced to use BMP due to limitations of
the mapping tools. Also, "complex" is relative; some relatively complex data models
can be captured with mapping tools, but some cannot.
Can I combine two or more finder functions with AND or OR operator to get
one result collection?
Location: http://www.jguru.com/faq/view.jsp?EID=208328
Created: Sep 17, 2000 Modified: 2000-09-17 15:56:16.053
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by Seong Jin Cho
(http://www.jguru.com/guru/viewbio.jsp?EID=141453
You'd have to do that sort of thing on the client side. Naturally, since find* methods
can return many different types of Java objects, you'd have to write custom code
based on the signature of the particular methods you used. Easiest would be if your
find methods returned java.util.Set or java.util.List; you could then addAll() them
both to a java.util.Set for OR, and write a simple loop for AND, like
List result1 = bean.findBySomething();
List result2 = bean.findBySomethingElse();
Set resultAnd = new HashSet();
for (Iterator i = result1.iterator(); i.hasNext(); ) {
Object x = i.next();
if (result2.contains(x)) {
resultAnd.add(x);
}
}
With Entity beans, this is not a problem as the Container automatically calls the
ejbLoad method that refreshed the values from the database.
Can I set the data represented by the BMP Entity Bean to null in ejbStore,
once it's updated in the database?
Location: http://www.jguru.com/faq/view.jsp?EID=211129
Created: Sep 20, 2000 Modified: 2000-09-20 11:12:03.969
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by Prashant Altekar
(http://www.jguru.com/guru/viewbio.jsp?EID=207066
[Question continues:
Every business method is always called after an ejbLoad. Therefore the bean has no
reason to hold on to the memory for the data between an ejbStore and subsequent
ejbLoad. This becomes important when such data is huge and the bean is accessed
infrequently. ]
Theoretically, you could set your data to null after ejbStore, unless your container
implements a caching optimization that skips ejbLoad in some cases (even then you
could turn it off)
Having said this, the real answer is "Go ahead, but don't worry about it unless 'huge
data' means multi-megabyte stuff"
Which application server is best for EJB deployment? [Go crazy, folks: I
expect a nice flame war on this one :-) -A]
Location: http://www.jguru.com/faq/view.jsp?EID=211362
Created: Sep 20, 2000 Modified: 2000-09-21 10:13:57.496
Author: Ravi kalidindi (http://www.jguru.com/guru/viewbio.jsp?EID=41528)
Question originally posed by Tariq Mahmood Gill
(http://www.jguru.com/guru/viewbio.jsp?EID=29492
Weblogic is definitely better among other servers.i worked on weblogic and
websphere.weblogic is best for deployment.i am hearing that Iplanet server too
giving lot of troubles.
ravi kalidindi
Comments and alternative answers
It's a shame an IBM can call their product an Application server. It is nothing more
than a Servlet engine which you have to bring down every 8 hours dew to the Naming
services failures. No wonder they giving it away for free. Well it is not for free. The
big blue still finds the way to back stab their client by charging consulting fees for a
failure of a product.
I want to access a session EJB deployed on a Websphere 3.02 from the web
container of a Weblogic 4.51 Server. Both servers are running on machines
behind the firewalls of two different corporate networks. What are the
viable solutions here?
Location: http://www.jguru.com/faq/view.jsp?EID=215121
Created: Sep 25, 2000 Modified: 2000-09-28 19:26:28.397
Author: Shyam L (http://www.jguru.com/guru/viewbio.jsp?EID=29689) Question
originally posed by Peter Makumbi
(http://www.jguru.com/guru/viewbio.jsp?EID=57706
You deploy the EJB on the Websphere server and include the deployed EJB jar file in
the classpath of the client on the Weblogic server. All other things remain the same.
Comments and alternative answers
Syham says that you simply deploy on Websphere (WS) and access from Weblogic
(WL). It is simple to see that this won't work. WS 3.02 and WL 4.5.1 use different
JNDI RMI SPI impelementations. WS uses an IBM implementation based on IIOP,
whereas WL uses the propriatary T3 Protocol. So this can only work if you use the
IBM JNDI implementation on the WL server. But once again you will later have
problems with getting RMI over IIOP through the corporate firewalls. So My original
question actually poses two questions.
Pemak
To Peter Makumbi
Author: Rajesh S (http://www.jguru.com/guru/viewbio.jsp?EID=460704), Jul 24,
2001
I am facing the same problem as described by you. Did you find any answers for the
question. If so could you please provide me the solution in this forum. You can also
email be at s_rajesh75@yahoo.co.in.
When I try to run J2EE SDK Deploytool.bat it doesn't start and gives:
Exception in thread "main" java.lang.NullpointerExcception. How can I fix
this?
Location: http://www.jguru.com/faq/view.jsp?EID=217722
Created: Sep 28, 2000 Modified: 2000-09-28 19:20:31.021
Author: raviprolu pavan kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=217700) Question originally posed by
Vicky Jain (http://www.jguru.com/guru/viewbio.jsp?EID=134906
Maybe I can tell you some points which you have to remember while using
deploytool. These steps maybe helpful to anybody using the tool.
1. When first running the deploytool set the JAVA_HOME and J2EE_HOME. Maybe
you have done this. In case you did not do then you have to set the Homes.
2. If you get 'out of environment space' then adjust the environment space in the
DOS window
3. Once you have opened the UI and used it, and you are about to close it, make
sure that 'No applications are open'. All applications should be closed. Otherwise if
you close the UI with some applications open, next time you cannot open the tool.
You may like to try and rename the folder where you...
Author: Munusamy Shanmugavelu
(http://www.jguru.com/guru/viewbio.jsp?EID=228254), Oct 13, 2000
You may like to try and rename the folder where you have saved the application .ear
files and start the deploytool again
What is an intermediate data access object and what are the advantages
and disadvantages of using it?
Location: http://www.jguru.com/faq/view.jsp?EID=217790
Created: Sep 28, 2000 Modified: 2000-09-28 19:29:19.386
Author: WEICONG WANG (http://www.jguru.com/guru/viewbio.jsp?EID=217785)
Question originally posed by pradeep patra
(http://www.jguru.com/guru/viewbio.jsp?EID=40386
Check http://www.monson-haefel.com/ejbtips/ejbtip_2.html
Comments and alternative answers
Value Object (VO) and Data access object (DAO) are two distinct patterns - they
serve different purposes.
A DAO is designed to remove SQL logic from a BMP to a stand alone class to
abstract different data sources.
You could also reuse this DAO class to access it from a Session bean ;-)
What happens when a client calls an entity bean's home interface create()
method and an entity bean already exists with that primary key, created
previously by another client ? Also what happens when a client calls an
entity bean's home interface findByPrimaryKey() method and an entity bean
does not already exist with that primary key ?
Location: http://www.jguru.com/faq/view.jsp?EID=218876
Created: Sep 29, 2000 Modified: 2000-10-03 10:27:35.489
Author: Anil Datt (http://www.jguru.com/guru/viewbio.jsp?EID=20887) Question
originally posed by paul martin
(http://www.jguru.com/guru/viewbio.jsp?EID=200835
What is the difference between session and entity beans? When should I
use one or the other?
Location: http://www.jguru.com/faq/view.jsp?EID=221545
Created: Oct 3, 2000 Modified: 2000-10-03 10:09:38.175
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3)
An entity bean represents persistent global data from the database; a session bean
represents transient user-specific data that will die when the user disconnects (ends
his session).
Please see What is an entity bean? and What is a session bean? for more
information.
EJBs are useful in a variety of situations. If you wish to build your application using
components, require transactions, or don't wish to manage some of the basic
infrastructure needed for a server (such as thread and connection pooling), then an
EJB container may be the way to go.
I think the first step is to decide which EJB spec you want to design against. EJB 1.0
and EJB 1.1 have some differences that you might want to account for in your
design. Collaboration implies to me that some database persistence is needed. You'll
need to decide if you should use entity beans to fill that role. If you need pub-sub
notification or point-to-point message queues, you'll need to verify that the JMS and
EJB vendors can operate together transactionally. Although the EJB spec does
"gurantee" a certain amount of standarization between vendors, you'll still find
differences between containers. You might want to build an abstraction that can help
isolate you from those differences. Your build process will also need to account for
the different EJB tools that each vendor supplies.
If you are sure that you'll never switch EJB vendors, you can probably ignore the
previous advice. If you try to be vendor agnostic, however, be aware of some of the
neat things that vendors give you that isn't part of the spec, such as clustering.
I'll talk about sequence type mechanisms first: triggers probably won't work for
reasons I'll discuss later.
The technique you'd want to use would be to retrieve your new key value in your
ejbCreate method(s) and assign it to the appropriate field in your bean. That way the
CMP mechanism in the container can pick it up and will have an identity for your
bean. Note that your ejbCreate method needs to return an instance of your primary
key class (in EJB 1.1 - if you're still at 1.0, consider a different container)
You should be able to get your value with a little bit of BMP looking code: get the
DataSource from JNDI (ctx.lookup("java:comp/env/jdbc/MyConnection") type
things), get a Connection from the DataSource, then execute the SQL ("SELECT
myseq.nextval from dual" if i remember Oracle correctly). Remember to close the
connection to ensure taht it is re-pooled properly.
Triggers probably won't work (assuming you were going to use them to assign values
to the primary key columns directly). This is because most containers really, really
think they need to know the value of your primary key ahead of time, largely (I
believe) to make sure that their cache is right, but also because they really need to
explicitely check for key-violations themselves so that they can throw
DuplicateKeyException (catching and interpreting the SQLException from the JDBC
driver would be vendor dependent and would also have to assume that the primary
key columns are actually defined as primary keys - not a safe assumption for a
container to make, unfortunately)
By the same token, you'll not be able to get your CMP container to emit SQL that hits
your sequence within the insert statement: it requires assumptions that container
developers just can't make (like the existence and syntax of your RDBMS' sequence
feature, as well as all of the above).
JFH
Can my ejbFind methods have return types like RowSet or Vector, or should
it be only of type Enumeration?
Location: http://www.jguru.com/faq/view.jsp?EID=222462
Created: Oct 4, 2000 Modified: 2000-10-06 22:06:36.259
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by Prashanthi Pokala
(http://www.jguru.com/guru/viewbio.jsp?EID=215308
The 1.1 spec. says that ejbFindXXX methods must return either a primary key or a
collection of primary keys, and refers to the section (9.1.8) where the return types of
home interface finder methods is defined. This specifies either Enumeration or
Collection. Since, in Java 2, Vector implements Collection, you should be able to
return a vector, but given the restriction in section 9.1.8, you will probably have to
declare your return type as Collection. Declaring Vector as your return type might
work in some containers, but I wouldn't expect it to be portable.
Returning RowSet will just not work. as the container will not know what to do with
it.
Can my ejbFind methods have return types like RowSet or Vector, or should it
be only of type Enumeration?
Author: Parag Bharambe (http://www.jguru.com/guru/viewbio.jsp?EID=741714), Feb
6, 2002
Suppose I have an option of using vector and Enumerator for finder query which
return me multiple queries? Which one will give me better performance?
Suppose multiple records are retrived from Database. Is it Application server cache
the retrived data , or each record is fetched from Oracle database cache?
Is there any performance problem with calling one EJB from another EJB
running in the same container?
Location: http://www.jguru.com/faq/view.jsp?EID=222470
Created: Oct 4, 2000 Modified: 2000-10-06 22:24:36.278
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by gurdeep singh
(http://www.jguru.com/guru/viewbio.jsp?EID=215882
There are two potential performance issues here, one of which has been eliminated
by most (if not all) container vendors, and the other of which many container
vendors have optional optimization for.
The first issue is that given naive implementations of the JNDI context objects that
the beans use to look each other up, the calls might go through RMI, which involves
quite a bit of overhead even within a process. Again, though most if not all container
vendors optimize this right out of your way. Don't worry about this one.
The second potential issue, though, comes from the spec. The EJB specification
dictates that the container copy all method parameters and return values on these
calls. Here is the quote from section 18.2.3: <quote> Specifically, the EJB Container
is not allowed to pass non-remote objects by reference on inter-EJB invocations
when the calling and called enterprise beans are collocated in the same JVM. Doing
so could result in the multiple beans sharing the state of a Java object, which would
break the enterprise bean’s semantics. </quote> All this copying has obvious
performance implications. However, most container vendors allow this behavior to be
overridden for performance reasons.
Yes it is possible. Using Views is a good way of mapping multiple tables to one Entity
Bean.
Remember that you will also need to write a Primary Key class for your Entity Bean.
Refer to http://www.jguru.com/jguru/faq/view.jsp?EID=20875 for details.
Comments and alternative answers
What is a value object? Why would I use one? What are some problems with
them?
Location: http://www.jguru.com/faq/view.jsp?EID=224988
Created: Oct 9, 2000 Modified: 2000-10-11 19:47:53.853
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3)
A Value Object, aka a Bulk Accessor or Bulk Data Class, is a lightweight Java class,
separate from your EJB class, that contains properties or instance variables
corresponding to each of your EJB's properties.
Paul Done, in feedback to Is there any reason why value objects cannot have set
methods?, defined value objects very well:
Value objects are recommended when data has to be returned from an EJB server to
the EJB client, if none of the data has to be updated. ie. The value objects are used
to transport read-only data.
It is the equivalent of the client requesting XML from the server tier, except you get
the tighter compile time binding and control, and you don't have to parse the
returned XML.
If, instead, an equivalent EJB reference with the same 'getter' methods is returned,
then each time the client calls a getter method on the reference EJB, this results in a
remote method call to the server tier. This is an uneccessary round trip, when the
object could have held the data locally itself.
So basically, value objects are recommended to enable your multi-tier application to
be more performant.
If you do need to update data, then you may need to use an EJB reference instead.
However, this fine-grained querying/updating of data could become a severe
performance bottleneck, if lots of it is performed. The traffic between different tiers
needs to be minimised. Instead, EJBs should be used by clients for more coarse-
granied method invocations.
For example, the client could call a session bean on the server to get a complex data
set (encapsulated in a value object), instead of just 1 row of data from 1 table. The
server session bean may have used many entity beans or jdbc directly, behind the
scenes on the server tier; however, this is hidden from the client. Once the client
recieves the complex value object, it can do as many local method calls as it likes on
it to get the data. Then a new (or the same) object could then be constructed with all
the updated data. The client would then pass this object back to the server, to
perform the update, by calling the appropriate method on the remote session bean,
passing the new value object as the parameter.
One problem with using Value Objects is that they are indeed passed by value, not
by reference. If the data are updated on the server, a client may be accessing an
out-of-date value stored in his local copy of the value object. Furthermore, if you use
value objects to *store* data back on the server, you may inadvertently be reverting
changes to fields that you did not set, but that a different client changed in the
meantime.
Another is that it is simply annoying to write one! It's like, I just wrote all these
accessor methods on the *real* bean, and now I have to write them again on this
fake one! Also, as you upgrade your bean code, you need to remember to update
your value object code as well, leading to possible subtle migration bugs.
See also:
• Is there any reason why value objects cannot have set methods?
• Tip 2 - Bulk Accessors in Entity Beans
• EJBDoclet
All the EJB interfaces are Java 1.1 compatible. EJB's that are written to be used by
both JDK 1.1 and 1.2 should be aware of the differences between the two versions.
These are listed inside section 18 of the EJB 1.1 specification.
[RC - If you know of a container that can support JDK 1.1 clients, please
submit as feedback]
This is the default behaviour for EJB. The specification states that ejbLoad() will be
called before every transaction and ejbStore() after every transaction.
Each Vendor has optimizations, which are proprietary for this scenario. We will
outline the properties for the popular servers below:
WebLogic 5.1
[RC - Please submit answers for other containers as feedback so we can provide a
complete list]
Comments and alternative answers
CMP Only
Author: Jeff Davenport (http://www.jguru.com/guru/viewbio.jsp?EID=842956), Apr
17, 2002
In WebLogic 6.x, the is-modified-method-name option only applies for CMP. It is not
allowed for BMP. I do not know if this is the case in WebLogic 5.1 as well.
Yes it is possible. Although, naturally you must make sure that the methods of the
EntityBean or SessionBean interfaces (depending on which type of EJB you are
writing) are implemented either in the Bean class or its' superclasses.
When descending from an existing class, you should be aware of the EJB
programming restrictions outlined in section 18.1.2 of the EJB 1.1 specification. For
example, You must be careful not to extend from any of the java.io.* classes or
java.lang.Thread.
The time of creation of stubs and skeletions for EJB components varies from server
to server.
The creation of stubs and skeletons for the popular servers is outlined below:
Inprise Application Server 4.x
The stubs and skeletons can be created during development time, for development
and testing with the command line utility of with JBuilder. The stubs and skeletons
for the EJB can also be created during deployment using the IAS Console. There is
also an option to create a Client Jar file. The Client Jar file contains the necessary
stubs and interfaces for the EJB which a client requires to invoke the EJB.
jBoss Server
In jBoss, the stubs and skeletons are not required to be generated by the developer
or deployer. The Server takes care of the creation and downloading of stubs.
There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec
says that the deployer must specify a value for the transaction attribute for those
methods having container managed transaction.
Comments and alternative answers
Is there any way to force an Entity Bean to store itself to the db? I don't
wanna wait for the container to update the db, I want to do it NOW! Is it
possible?
Location: http://www.jguru.com/faq/view.jsp?EID=232157
Created: Oct 19, 2000 Modified: 2000-10-26 06:35:49.787
Author: sailaja nadella (http://www.jguru.com/guru/viewbio.jsp?EID=225889)
Question originally posed by Stéphane Félix
(http://www.jguru.com/guru/viewbio.jsp?EID=210800
Specify the transaction attribute of the bean as RequiresNew. Then as per section
11.6.2.4 of the EJB v 1.1 spec EJB container automatically starts a new transaction
before the method call. The container also performs the commit protocol before the
method result is sent to the client.
What is the Session wraps Entity Pattern? What are the motivations behind
it?
Location: http://www.jguru.com/faq/view.jsp?EID=232943
Created: Oct 20, 2000 Modified: 2000-10-23 21:40:01.55
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by nadella srikanth
(http://www.jguru.com/guru/viewbio.jsp?EID=72838
This pattern is really just a quick way of saying "Clients access the system only
through Session Beans, which encapsulate all details of the system's Entity Beans."
From my perspective, there are two primary motivations for this: to provide good
transactional definition and improve performance, and to hide implementation details
by providing a coarse-grained interface to the system.
The second motivation is to hide implementation details and keep the system
interface relatively narrow. In systems where this is important (and that's really any
system with a projected lifetime of over 2 weeks 8^}) ), data that is displayed is
usually extracted from the entity beans and put into 'View' classes by session beans.
This gives you a narrow system interface (the session interfaces and View classes)
while allowing you the modularity and cohesion benefits of a fine-grained
implementation, as well as (possibly) the development time savings of CMP.
Facade Pattern
Author: prajakt samant (http://www.jguru.com/guru/viewbio.jsp?EID=272793), Mar
22, 2001
The above scenario is also known as Facade Pattern wherein the stateless Session
beans form a "facade" to Entity Beans ,which actually reduces network traffic as
stateless beans could be swapped in between clients,eventually improving the
performance.
• Digex - http://www.digex.com
• ejip.net - http://www.ejip.net
When using Stateful Session Beans, What will happen if an EJB client
program terminates without calling the Stateful Sesson Bean's remove()
method?
Location: http://www.jguru.com/faq/view.jsp?EID=234431
Created: Oct 23, 2000 Modified: 2000-10-23 22:10:22.223
Author: manish sethi (http://www.jguru.com/guru/viewbio.jsp?EID=233027)
Question originally posed by Yongfeng Xiao
(http://www.jguru.com/guru/viewbio.jsp?EID=216776
Referring to page 57 of the EJB 1.1 specification. A stateful session bean would come
into Doesn't Exist state if one of the following happens:
good
Author: sravan reddy (http://www.jguru.com/guru/viewbio.jsp?EID=962689), Jul 24,
2002
its a nice explanation
For example, consider an EJB client requesting a customer addrees from a Customer
EJB. Assume the customer address is a serializable object containing Street address,
State, Zip, etc. You have 2 options - either pass the serializable object asis to the
client over IIOP or provide individual methods on the Customer EJB that return each
piece of information. While the first breaks encapsulation the second will be shot
down by your architect for performance reasons! Also the scenario makes sense for
inter-EJB calls as well to preserve encapsulation.
Enter value objects in EJB 2.0. Value objects are basically a client view of your
persistent object. The Customer bean provider creates this view from the persistent
representation. In order for the container to be able to create these instances, the
appropriate IDL stubs must be deployed on the container when the bean is deployed.
Optionally containers may download them on demand - the spec doesn't impose
either alternative. For more details & examples, refer to the EJB 2.0 specification!
:-)
Author: george varghese (http://www.jguru.com/guru/viewbio.jsp?EID=1143700),
Feb 4, 2004
Dependent value class A dependent value class is a concrete class that is the value of a
cmp-field. A dependent value class may be a class that the Bean Provider wishes to
use internally within an entity bean with container-managed persistence, and/or it may
be a class that the Bean Provider chooses to expose through the remote (or local)
interface of the entity bean. A dependent value class can be the value of a cmp-field; it
cannot be the value of a cmr-field. The get accessor method for a cmp-field that
corresponds to a dependent value class returns a copy of the dependent value class
instance. The assignment of a dependent value class value to a cmp-field using the set
accessor method causes the value to be copied to the target cmp-field. A dependent
value class must be serializable. The internal structure of a dependent value class is
not described in the EJB deployment descriptor.
Is there anything special about sending mail with JavaMail when using EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=240549
Created: Oct 30, 2000 Modified: 2002-03-30 19:49:27.279
Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question
originally posed by vini vipin (http://www.jguru.com/guru/viewbio.jsp?EID=239441
The javax.mail libraries are a standard part of of J2EE, so the whole API is there.
Even the JavaBeans Activation Framework is there, which is required by JavaMail.
However, you're only allowed to send mail, not receive.
With J2EE, you are required to obtain the javax.mail.Session instance from a JNDI
lookup rather than creating it yourself, but other than that it's the same as sending
mail using JavaMail from a standalone app.
You can look at the Java Pet Store example, which does this.
You will also need to configure a smtp host for sending out your mail. You can set this
inside your weblogic.properties file. Actual documentations on this can be found on
the weblogic documentation website at http://www.bea.com Currently, the mail bean
has already been implemented on production systems and working fine.
What are the free EJB containers available? Which version of the EJB
specification do they support? Are they free for development and
production?
Location: http://www.jguru.com/faq/view.jsp?EID=241193
Created: Oct 31, 2000 Modified: 2000-10-31 06:37:34.37
Author: CustomWare Asia Pacific
(http://www.jguru.com/guru/viewbio.jsp?EID=139414) Question originally posed by
Habib El-Zoghbi (http://www.jguru.com/guru/viewbio.jsp?EID=38223
Some application servers are free for development and production, whilst some are
free for development, but require a runtime license. Note that you should confirm
from each site whether or not any licensing terms have changed
• jBoss 2.0 from http://www.jboss.org supports EJB 1.1, and is free for
development and production
• JRun Server 3.0 from http://www.allaire.com supports EJB 1.1, and is free for
development
• Enhydra from http://www.enhydra.org supports EJB 1.1, and is free for
development and production
• OpenEJB from http://www.openejb.org supports EJB 1.1, and is free for
development and production
The EJB 1.1 spec eliminated "runAs" security delegation. Is there some
other way to achieve this effect now? For example, how can I enable
session bean method A, which is running as "guest" to call entity bean
method B which only allows some role not containing "guest" to execute it?
Assume I will do some kind of authentication in method A prior to the call to
B (and only do the call to B on behalf of authorized callers) so this makes
sense.
Location: http://www.jguru.com/faq/view.jsp?EID=245708
Created: Nov 5, 2000 Modified: 2000-11-05 15:43:36.93
Author: Rhett Guthrie (http://www.jguru.com/guru/viewbio.jsp?EID=80532)
Question originally posed by Bob Hall
(http://www.jguru.com/guru/viewbio.jsp?EID=222264
Do the guest-specific authorization in Bean B. Doing this is not as clean as the old
runAs mechanism, but it will work.
What are some standard design patterns that are used in EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=247099
Created: Nov 6, 2000 Modified: 2000-11-07 22:12:12.677
Author: venkat r (http://www.jguru.com/guru/viewbio.jsp?EID=237873) Question
originally posed by bindu devarapalli
(http://www.jguru.com/guru/viewbio.jsp?EID=239587
Some standard design patterns used in EJB include the command and decorator
patterns. An extensive list of patterns for use in EJB can be found at
http://c2.com/cgi/like?EjbDesignPatterns
1. There has been an exception within the scope of the transaction. If you have
proper logging in your program and log all the possible exceptions then you
could easily see the reason of a TransactionRolledBackException. Or more
precisely the exception which led to the rollback. This Exception could be seen
in the stack trace if you dump your stack trace.
2. If the transaction timed out before the completion of the task. In this case
case you could see in the stack trace that the transaction was timed out and
then the TransactionRolledBackException as it would be thrown once
timeout occurs.
The main difference is that throwing remote exception from within the bean is
deprecated: your bean methods (including ejbLoad, ejbStore and their ilk) should
throw EJBException. Other things to note from the spec are that the current
transaction will be rolled back (it wouldn't be if you threw an application exception),
and the client will see it as a RemoteException, even though you threw an
EJBException.
Comments and alternative answers
A list of tools that integrate Java with the Microsoft platform is available here. These
tools can be used, as long as they stay within the EJB specification requirements set
out in section 18.1.2 of the EJB 1.1 specification.
One possible solution (that requires coding) would be to set the transaction that the
Session Bean is running within to be rolled back. To do this, use the
setRollBackOnly() method of the javax.transaction.UserTransaction interface.
This method would of course require that your Session Bean is using transactions.
If the Session Bean is processing many long running requests then it could provide
an optimization by checking the transaction status using the getRollBackOnly() call
of the javax.ejb.SessionContext object.
Yes it is, you'll probably want to use the VisiBroker ORB from the EJB, to override the
default ORB, use the following properties:
org.omg.CORBA.ORBClass=com.inprise.vbroker.orb.ORB
org.omg.CORBA.ORBSingletonClass=com.inprise.vbroker.orb.ORB
These properties can be set on the commandline (using -Dorg...) or using a file
named orb.properties.
[RC - Please give reference to the particular AppServer you are using]
Location: http://www.jguru.com/faq/view.jsp?EID=256842
Created: Nov 17, 2000 Modified: 2000-11-21 10:44:45.924
Author: shiva prasad (http://www.jguru.com/guru/viewbio.jsp?EID=123366)
Question originally posed by Praveen kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=84503
<finder>
<method-name>All</method-name>
<method-params></method-params>
<finder-query<(1 = 1)]]></finder-query>
</finder>
Although technically it is legal, static initializer blocks are used to execute some piece
of code before executing any constructor or method while instantiating a class. Static
initializer blocks are also typically used to initialize static fields - which may be illegal
in EJB if they are read/write - see section 18.1.2.
In EJB this can be achieved by including the code in either the ejbCreate(),
setSessionContext() or setEntityContext() methods.
No. To achieve this you have to deploy your EJB multiple times each specifying a
different JNDI name.
Is it possible to write two EJB's that share the same Remote and Home
interfaces, and have different bean classes? if so, what are the
advantages/disadvantages?
Location: http://www.jguru.com/faq/view.jsp?EID=258282
Created: Nov 20, 2000 Modified: 2000-11-28 13:59:47.825
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by Alan Gault
(http://www.jguru.com/guru/viewbio.jsp?EID=131380
It's certainly possible. In fact, there's an example that ships with the Inprise
Application Server of an Account interface with separate implementations for
CheckingAccount and SavingsAccount, one of which was CMP and one of which was
BMP.
Note that if you just want to map the same EJB to two data sources, you can just
deploy it twice under different names.
Technically yes, spec. compliant NO! - refer to section 18.1.2 of the EJB 1.1
specification (page 273).
"The enterprise bean must not attempt to query a class to obtain information about
the declared members that are not otherwise accessible to the enterprise bean
because of the security rules of the Java language."
For BMP, I don't want all the variables to be updated in the database when
only one variable has been changed in each of the business methods. Is it a
good practice to load and store values from and to database inside the
business methods rather than ejbStore() and ejbLoad()?
Location: http://www.jguru.com/faq/view.jsp?EID=262837
Created: Nov 26, 2000 Modified: 2000-11-28 13:48:16.388
Author: Matthias David (http://www.jguru.com/guru/viewbio.jsp?EID=17908)
Question originally posed by Mahesh chandra Puvvada
(http://www.jguru.com/guru/viewbio.jsp?EID=231051
Placing load and store commands inside business methods is not a good practice.
Imagine if you have several calls to business methods to the bean, in this case you
would have database access on each business method call.
Using the ejbStore() and ejbLoad() methods guarantee that the database access
takes place when it is really necessary, e.g. between transcations.
If only some of the variables change between calls of ejbLoad() and ejbStore() then
an approach to use would be to store which variables have changed using transient
boolean flags and then write only these variables to the database.
Here is the answer from the Java 2 Enterprise Edition Developer's Guide (v. 1.2.1) :
"Enterprise beans make use of the services provided by the EJB container, such as
life-cycle management. To avoid conflicts with these services, enterprise beans are
restricted from performing certain operations:
• ...
• Managing or synchronizing threads
• ... "
(B) Another way to do this is to use an application server which support's JMX.
Basically, create a JMX MBean component which uses the JMX timer services and
then fires off e.g., a session bean when the associated timer expires.
Check out Jeff Schnitzer's JUnitEE package and the Wiki EJB Unit Testing page.
Comments and alternative answers
• For each Entity Bean class, create a serializable base class (i.e. the Entity
Bean class should inherit from this class).
• Move all public attributes, getters and setters to this class (they are not
needed any more in the Bean class, but are inherited).
• Add a returnBase method in the Entity Bean, which returns a copy of its
data, in the form of a base class instance (i.e. a standard java class).
• Avoid direct client - Entity Bean interaction, but wrap the entity bean by a
session bean.
• When undertaking a select statement,
o the client asks the intermediate session bean to call the finder,
o the intermediate session bean calls the returnBase method for each
EJB and stores all the resulting instances in a Vector.
o The vector is returned to the client in one throw !
This does break encapsulation to some extent (by giving the session bean knowledge
of the database structure), but it also avoids hitting the database n+1 times (as using a
finder might). There are also ways of structuring your persistence layer to avoid this
breaking of encapsulation, particularly for BMP beans.
Cheers,
Venkat.
What are the benefits of using a Stateless Session Bean over using a class
purely consisting of static methods?
Location: http://www.jguru.com/faq/view.jsp?EID=281106
Created: Dec 18, 2000 Modified: 2000-12-19 13:39:08.584
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by Danny So
(http://www.jguru.com/guru/viewbio.jsp?EID=236938
Mostly container management of transactions and the ability to 'easily' call remote
code. Really, the two solutions work at different scales: a Stateless Session Bean is
useful when you can define a set of (fairly coarse grained) atomic transactions that
are related by a common theme, where a bunch of static methods in a class are
more useful for (rather fine grained) utility code.
One common use of Stateless Session Beans is to implement a facade over a set of
entity beans, in order to allow the client to be transaction-ignorant. In this pattern
the session bean defines a set of transactions that it implements using entity beans.
See FAQ question "What is the Session wraps Entity Pattern? What are the
motivations behind it?" for more information.
If you mean "can you map the CMP Bean's persistence operations through stored
procedures?", the answer depends on the sophistication of your chosen container's
mapping tool and how tightly it integrates with your database. Sophisticated
mapping tools are free to map your bean's CMP fields to whatever they want,
however they want. However, many CMP tools are much simpler and expect to map
to relational tables.
Now, if your question was more generally "Can a CMP bean call a stored procedure?",
for example from a business method, or from ejb<Post>Create(...), the answer is a
definite yes. Just specify the resource-reference in your ejb-jar.xml (as you will
anyway), look up the DataSource to get a Connection, the do all the
CallableStatement JDBC stuff you want.
Re: Can an Entity Bean call a stored procedure using Container Managed
Persistence ? If yes, how?
Author: Steven Martin (http://www.jguru.com/guru/viewbio.jsp?EID=430104),
Jun 11, 2001
Was any code ever posted? I'd like to use EJBS to do that wrapping as well.
thanks, Steven
Re: Re: Can an Entity Bean call a stored procedure using Container
Managed Persistence ? If yes, how?
Author: V Shah (http://www.jguru.com/guru/viewbio.jsp?EID=226807), Oct
23, 2001
Can CMP call a stored procedure ? I need to have an ORACLE stored
procedure called for every insert/update/delete. How would I go about doing
this ? Thanks
Re: Re: Re: Can an Entity Bean call a stored procedure using
Container Managed Persistence ? If yes, how?
Author: praveen Kumar Nagunoori
(http://www.jguru.com/guru/viewbio.jsp?EID=542975), Nov 13, 2001
Yes u can call a database stored procedure in cmp beans just specify the
database connection resources in the ejb-jar.xml and get the connection in
the call back methods and call ur operation related stored procedure in the
call back methods using CallableStatements. But my suggestion is why u
want to call the stored procedures why dont u apply that in business logic u
implemnt in session beans.
From some source out there where BMP only can call a stored
procedure....
Thanks
Neo
A Web Server understands and supports only HTTP protocol whereas an Application
Server supports HTTP,TCP/IP and many more protocols. Also many more features
such as Caches,Clusters,Load Balancing are there in Application Servers which are
not available in Web Servers. We can also Configure Application Servers to work as
Web Server. In short, Applicaion Server is a super set of which Web Server is a sub
set.
[See also What are all the different kinds of servers? (Such as Web Servers,
Application Servers, etc) ]
Your final summary is fairly good, but I think the best description is that Web servers
are HTTP servers, whereas an application server runs application code in the context
of some higher level API (servlets, EJB, ASP, Enhydra's compiled HTML thingy)
Even if we take it literally, a web server serves web pages so an application server
should serve with application (logic).
The application logic (here, the business logic) is embedded in some form, let that
be an EJB or CORBA component, and the application server allows us to get the
services provided by those components.
IMHO, the qualities such as load balancing, fail-over support, caching are all non-
funtional requirements that are applicabale to any distributed application (web
server, db server, app server etc.)
Application vs Webserver
Author: siraj ahmed (http://www.jguru.com/guru/viewbio.jsp?EID=405469), Apr 18,
2001
If application server has inbuilt jvm and servlet engine then why we call
javawebserver2.0 as "webserver" it can handle the servlet request then its also an
application server. Please comment....
Probably because the EJB container is storing the bean when the transaction
commits, even though you didn't modify it. Some containers have various ways of
optimizing around this, from comparing the data (IAS 4.0) to allowing you to
implement an 'isModified' bethod returning boolean (WebLogic). The container you're
using may allow something like this.
What is EJBDoclet?
Location: http://www.jguru.com/faq/view.jsp?EID=285175
Created: Dec 24, 2000 Modified: 2000-12-24 01:22:49.179
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
EJBDoclet is an open source JavaDoc doclet that generates a lot of the EJB related
source files from custom JavaDoc comments tags embedded in the EJB source file.
Is it legal to use JDBC code inside the business methods of an Entity Bean?
What are the implications of doing so?
Location: http://www.jguru.com/faq/view.jsp?EID=287585
Created: Dec 27, 2000 Modified: 2001-01-01 02:35:20.703
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by amol kher
(http://www.jguru.com/guru/viewbio.jsp?EID=274801
Yes it is allowed. The implications rather depend on your bean and your application.
The biggest implication is in your transactions: if you call your entity business
methods directly from a client, each method will be executed as its own transaction,
so you can expect ejbLoad, your business method, and ejbStore to all be called for
each method. This tends to be a lot of datbase activity, which is why guys like me
advocate the Ssession wraps Entity' pattern. See this FAQ for more details on
'Session wraps Entity'
Another potential problem rises from doing this within a CMP entity bean: you have
to be careful not to modify tables behind the container's back: containers are allowed
to cache CMP entity data (the spec defines three 'commit options', A, B, and C) and
modifying the tables directly can cause the container's cache to be inconsistent in
some cases.
With BMP beans the situation is simpler, and making JDBC calls from normal business
methods can allow you to optimize your application in some situations. For example,
if your application's object model consists of a few very coarse grained entities that
each have several sets of dependent objects, you can use a 'lazy fetch'
implementation to retrieve dependents only when you know they're going to be
used.
Are there any performance issues that have to be considered while using
EJB Components from COM environments?
Location: http://www.jguru.com/faq/view.jsp?EID=287841
Created: Dec 28, 2000 Modified: 2001-01-01 02:36:23.591
Author: Lee Fuller (http://www.jguru.com/guru/viewbio.jsp?EID=109421) Question
originally posed by Nikhil Kapre
(http://www.jguru.com/guru/viewbio.jsp?EID=49106
Personally, I would choose a loosely coupled architecture, with the anticipation of fast
performance not being a requirement. If re-using an existing EJB component, then
this performance hit will have to factored into the expectations, if a new component,
then it is best to keep it all COM(+) for maximum performance. (IMHO)
For a full description and an example, see Read all about EJB 2.0 by Richard Monson-
Haefel in JavaWorld. Basically, the persistence manager maps an entity bean to a
database based on the bean-persistence manager contract / abstract persistence
schema.
1. Finder methods that are defined in the home interface of an entity bean and
which return entity objects.
2. Select methods, which are not exposed to the client, but which are used by
the Bean Provider to select persistent values that are maintained by the
Persistence Manager or to select entity objects that are related to the entity
bean on which the query is defined.
The Enterprise JavaBeans query language, EJB QL, is used to define finder queries
for entity beans with container managed persistence. EJB QL lets the Bean Provider
specify finder methods in a portable way. It is a specification language that can be
compiled to a target language, such as SQL, of a persistent store used by a
persistence manager. This allows the responsibility for the execution of finder queries
to be shifted to the native language facilities provided for the persistent store (e.g.,
RDBMS), instead of requiring finder queries to be executed directly on the persistent
manager’s representation of the entity beans’ state. As a result, finder methods are
both portable and optimizable.
Comments and alternative answers
code?
Author: Ilija Jovanoski (http://www.jguru.com/guru/viewbio.jsp?EID=515190), Oct
9, 2001
This is good but can we see some code with explanation where to put the methods...
Thanks!
Re: code?
Author: Murthy Yadlapati (http://www.jguru.com/guru/viewbio.jsp?EID=536293),
Nov 1, 2001
Look at the following article for examples:
about ejb 2.0 and EJBQL
Here's my definition, such as it is. A 'fine grained' entity bean is pretty much directly
mapped to one relational table, in third normal form. A 'coarse grained' entity bean is
larger and more complex, either because its attributes include values or lists from
other tables, or because it 'owns' one or more sets of dependent objects. Note that
the coarse grained bean might be mapped to a single table or flat file, but that single
table is going to be pretty ugly, with data copied from other tables, repeated field
groups, columns that are dependent on non-key fields, etc.
Fine grained entities are generally considered a liability in large systems because
they will tend to increase the load on several of the EJB server's subsystems (there
will be more objects exported through the distribution layer, more objects
participating in transactions, more skeletons in memory, more EJB Objects in
memory, etc.)
The other side of the coin is that the 1.1 spec doesn't mandate CMP support for
dependent objects (or even indicate how they should be supported), which makes it
more difficult to do coarse grained objects with CMP. The EJB 2.0 specification
improves this in a huge way.
As with other interfaces in Java, the remote interface can extend multiple interfaces.
In fact, it's common to pull the business methods out of the remote interface and
define them in a separate interface. This new interface can then be extended by the
remote interface and implemented by the bean class. The advantage here is that
now the compiler can do the checking for you to make sure the bean class is
implementing the method signatures that are exposed by the remote interface. You
wouldn't want the bean class to implement the remote interface directly because it
would then be required to implement the methods from EJBObject. You'll see this
referred to as using a "business interface" in Monson-Haefel's book.
Are there any examples and best practices for implementing the hashCode()
and equals() methods for a compound primary key class?
Location: http://www.jguru.com/faq/view.jsp?EID=296598
Created: Jan 8, 2001 Modified: 2001-01-09 05:59:49.552
Author: John Francis (http://www.jguru.com/guru/viewbio.jsp?EID=296576)
Question originally posed by paul martin
(http://www.jguru.com/guru/viewbio.jsp?EID=283798
Try this article at www.ejbnow.com
Comments and alternative answers
Examples for implementing the hashCode() and equals() methods for a compound
primary key class are: <body>
In reference to EJB, what is the meaning of scalable?, how does EJB support
scalability?
Location: http://www.jguru.com/faq/view.jsp?EID=298862
Created: Jan 10, 2001 Modified: 2001-01-16 19:54:50.067
Author: Dan Christopherson (http://www.jguru.com/guru/viewbio.jsp?EID=39644)
Question originally posed by Anand Kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=288893
First, remember that scalability is only one of the goals of the EJB sped: some of the
others are portability, automated transaction management, standardization of life-
cycle management, ease of development, and compatability/interoperability. A lot of
the scalability goal can really be considered as supporting scalability while not forcing
the code writers to jump too many hoops. In other words, ensuring that scalability is
purely a design or application architecture issue and doesn't become a coding issue.
Another point to remember is that scalability is really a hardware matter: all software
can do is make the problem more or less difficult.
Note that this does not mean 'fast.' I expect EJB implementations to be slower than
equivalent CORBA distributed systems that ignore transactions and security. I also
expect EJB based implementations of Web applications to be slower than the
equivalant Servlet/JSP -> JDBC/Data Access Object implementation. The
performance 'knee' of the EJB application will be higher in both cases - if it's a well
designed EJB application that accounts for and makes use of EJB features.
One of the scalability support features is the EBJObject itself: because the client
doesn't call the bean directly, but only through a redirection layer, the container can
interpose in the call and make a decision as to how to handle the call. This might
involve a pool of bean instances, in which multiple beans can assume the same
entity, or it can involve blocking while the last transaction executes (note, though,
that a stateful session bean can balk by throwing an exception if access is attempted
from two different transactions at once). The container's implementation and
configuration is the limiting factor here.
Other scalability gains come in places where the spec doesn't neccessarily define
behavior: container vendors are free to implement their client-side stubs in any way
they see fit - in some cases, the vendor can implement client stubs in such a way as
to take advantage of their clustering capabilities.
Of course, clusters of application servers would be a bear to write code for if there
weren't a simple way of writing transactional code to run on them. Here, EJB enables
scalability by defining a declaritive transaction model. The alternative would be to
write directly to one of the distributed transaction APIs (Xopen or the CORBA
Transaction Service, for example). Using these APIs directly tends to make code
fairly hairy.
Another scalability feature for designers and architects to take advantage of is the
Stateless Session Bean. The EJB specification allows containers to pool instances of
these and rotate through them on a request by request (invocation by invocation)
basis. Your client can hold a single reference to a stateless session but in making 10
method calls to it, it may actually be serviced by 10 different instances of the bean.
This enables scalability in a couple of ways:
1. methods on stateless session beans can be designed to be transactions, thus
keeping critical sections short and increasing throughput by avoiding waits on
locks.
2. Total memory utilization by the server will be less than if the container had to
have one instance of the bean per client reference
A big part of EJB is that it is a framework for underlying RMI: remote method
invocation. You're invoking methods remotely from JVM space 'A' on objects which
are in JVM space 'B' -- possibly running on another machine on the network.
To make this happen, all arguments of each method call must have their current
state plucked out of JVM 'A' memory, flattened into a byte stream which can be sent
over a TCP/IP network connection, and then deserialized for reincarnation on the
other end in JVM 'B' where the actual method call takes place.
If the method has a return value, it is serialized up for streaming back to JVM A.
Thus the requirement that all EJB methods arguments and return values must be
serializable. The easiest way to do this is to make sure all your classes implement
java.io.Serializable.
I think that serialization mechanism is not a good solution to that problem : it is slow
(no // between network, client and server) and it uses a lot of memory.
What is the correct DTD URL (DOCTYPE) for use with a messaging bean? [I
am trying to deploy messaging bean using Weblogic 5.1 SP3. This comes as
an example with weblogic. In the ejb-jar.xml for messaging bean, the
DOCTYPE is defined as : DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/j2ee/dtds/ejb_2_0.dtd" I found that the url to the
DTD is incorrect. I am unable to deploy my bean. ]
Location: http://www.jguru.com/faq/view.jsp?EID=303322
Created: Jan 15, 2001 Modified: 2001-01-16 07:02:32.632
Author: Matthew Kershaw (http://www.jguru.com/guru/viewbio.jsp?EID=243677)
Question originally posed by Archana Karnik
(http://www.jguru.com/guru/viewbio.jsp?EID=68139
I believe someone asked this question to Umit Yalcinalp in the EJB2.0 Java DevConn
chat on 19-Sep-00. The answer given was "we have not published it yet, except
listing it in the specification. This is because we currently have a draft of the
specification and we needed to be flexible as we make changes to the spec. We plan
to make it available when we have the Proposed Final Draft released."
The DTD has yet to be released.
http://developer.java.sun.com/developer/community/chat/JavaLive/2000/jl0919.htm
l
Comments and alternative answers
Try: http://java.sun.com/dtd/ejb-jar_2_0.dtd
Author: Mihir Kulkarni (http://www.jguru.com/guru/viewbio.jsp?EID=312865), Jan
25, 2001
Try: http://java.sun.com/dtd/ejb-jar_2_0.dtd
The only thing that comes to (my) mind is that you could write a 'group accessor' - a
method that returns a single object containing all of your entity bean's attributes (or
all interesting attributes). This method could then be placed in a 'Requires New'
transaction. This way, the current transaction would be suspended for the duration of
the call to the entity bean and the entity bean's fetch/operate/commit cycle will be in
a separate transaction and any locks should be released immediately.
Depending on the granularity of what you need to pull out of the map, the group
accessor might be overkill.
Why am I able to call a business method using the same Remote Interface
reference after I called the remove() method of a Stateless Session Bean??
Location: http://www.jguru.com/faq/view.jsp?EID=307891
Created: Jan 20, 2001 Modified: 2001-01-20 14:40:32.385
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Arun Prasad Paramahamsan
(http://www.jguru.com/guru/viewbio.jsp?EID=257985
Figure 6.9.3 - Client-invoked remove() from the EJB 1.1 specification answers
your question.
For Stateless Session Beans, the container may choose to optimize and re-use the
EJB instance.
What is the advantage of using Entity bean for database operations, over
directly using JDBC API to do database operations? When would I use one
over the other?
Location: http://www.jguru.com/faq/view.jsp?EID=308342
Created: Jan 21, 2001 Modified: 2001-02-01 15:53:58.627
Author: Suresh Rangan (http://www.jguru.com/guru/viewbio.jsp?EID=308330)
Question originally posed by sujatha karuppiah
(http://www.jguru.com/guru/viewbio.jsp?EID=218765
Entity Beans actually represents the data in a database. It is not that Entity Beans
replaces JDBC API. There are two types of Entity Beans Container Managed and Bean
Mananged.
In Container Managed Entity Bean - Whenever the instance of the bean is created
the container automatically retrieves the data from the DB/Persistance storage and
assigns to the object variables in bean for user to manipulate or use them. For this
the developer needs to map the fields in the database to the variables in deployment
descriptor files (which varies for each vendor).
In the Bean Managed Entity Bean - The developer has to specifically make
connection, retrive values, assign them to the objects in the ejbLoad() which will be
called by the container when it instatiates a bean object. Similarly in the ejbStore()
the container saves the object values back the the persistance storage. ejbLoad and
ejbStore are callback methods and can be only invoked by the container.
Apart from this, when you use Entity beans you dont need to worry about database
transaction handling, database connection pooling etc. which are taken care by the
ejb container. But in case of JDBC you have to explicitly do the above features.
Advantages
Author: lyndon mendoza (http://www.jguru.com/guru/viewbio.jsp?EID=411396), Apr
27, 2001
I think the questioner wanted to know if there is an advantage in using entity beans as
opposed to using just the jdbc api. There are a lot of advantages to using Entity Beans
but if speed is paramount it may not be the best solution. If you have an existing
system with tons of existing and well-tested stored procs don't just throw them away. I
am guessing this is the main reason why you asked the question in the first place. You
can leverage these procs with the use of jdbc api.
This method should be called once the bean is associated with an EJBObject. As, if
the bean is not associated with one, then you will get an IllegalStateException. The
earliest you can call this method without getting an exception is in the
ejbPostCreate() mtehod.
The bean is swapped from and to the pool. So when we use callback methods like
ejbLoad or ejbStore, we should not use the bean instance' primary key but get it from
the bean context which is a more permanent storage than the poolable bean.
And rest of the coding may be done using the bean's key attribute.
Can I use the Apache Web Server with the Sun J2EE Reference
Implementation?
Location: http://www.jguru.com/faq/view.jsp?EID=314392
Created: Jan 28, 2001 Modified: 2001-01-29 17:14:41.91
Author: Sebastian Kim (http://www.jguru.com/guru/viewbio.jsp?EID=314386)
Question originally posed by Alex Chaffee PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=3
The answer to your question is yes and no: Under the Jakarta project of Apache, the
product Tomcat, which extends the Apache Web Server, allows you to run your basic
servlets, JSPs and the like.
However, if you want to utilize J2EE's EJB functionality, you need to use an EJB
container, which neither Apache nor Apache+Tomcat is (or rather has). If you're
going down the open source road and sticking to Apache, the appropriate solution is
JBoss (jboss.org). If you're open at this point, but want to stay away from BEA
Weblogic or IBM Websphere, try Enhydra (enhydra.com) by Lutris.
I have Apache 1.3.x (12?) running on a Linux box at home, that has also got the
Sun J2EE reference implentation running. And yes, it works.
If you read the Minimalist User's Guide (for Tomcat 3.2.3 I believe) it talks about
where you can configure Apache and Tomcat so that Apache handles everything
(HTML, GIF, etc) other than servlets and JSPs.
The EJB container implements the EJBHome and EJBObject classes. For
every request from a unique client, does the container create a separate
instance of the generated EJBHome and EJBObject classes?
Location: http://www.jguru.com/faq/view.jsp?EID=315785
Created: Jan 29, 2001 Modified: 2001-01-31 22:04:14.634
Author: vasanth s (http://www.jguru.com/guru/viewbio.jsp?EID=314566) Question
originally posed by prakash prabhu
(http://www.jguru.com/guru/viewbio.jsp?EID=91561
The EJB container maintains an instance pool. The container uses these instances for
the EJB Home reference irrespective of the client request. while refering the EJB
Object classes the container creates a separate instance for each client request.
Comments and alternative answers
Having said that, yes most of the container providers implement the pooling
functionality to increase the performance of the app server. How it is implemented, it
is again up to the implementer.
Coming back to the question and assuming that the container supports pooling ....
1) The home interface can be pooled since it is doesnot hold the state of the client.
Similarly the stateless session BEAN OBJECT INSTANCE can be pooled.
2)The other type of BEAN OBJECT INSTANCES (Stateful session bean and entity
bean) holds the state of the client at any point of the time. So the Bean OBJECT
INSTANCES cannot be pooled here. Maybe, the CLASS INSTANCES can be pooled
and whenever a BEAN OBJECT INSTANCE of this type of beans is idle, it is
passivated and that CLASS INSTANCE is given to the next client.
Note the difference between the CLASS INSTANCE and the OBJECT INSTANCE.
Having said that, yes most of the container providers implement the pooling
functionality to increase the performance of the app server. How it is implemented, it
is again up to the implementer.
Coming back to the question and assuming that the container supports pooling ....
1. The home interface can be pooled since it is does not hold the state of the
client. Similarly the stateless session BEAN OBJECT INSTANCE can be
pooled.
2. The other type of BEAN OBJECT INSTANCES (Stateful session bean and
entity bean) hold the state of the client at any point of the time. So the Bean
OBJECT INSTANCES cannot be pooled here. Maybe, the CLASS
INSTANCES can be pooled and whenever a BEAN OBJECT INSTANCE of
this type of beans is idle, it is passivated and that CLASS INSTANCE is given
to the next client.
Note the difference between the CLASS INSTANCE and the OBJECT INSTANCE.
The class instance is the one with no values attached to the class attributes and hence
no state maintained. The object instance always holds the state of that object.
It's not that they don't have to be re-entrant: they cannot be reentrant. The spec
says "The container must ensure that only one thread can be executing an instance
at any time" (EJB 1.1 Spec. 6.11.6). This is partly to simplify development of the
EJB: the bean developer needn't concern himself with concurrency issues. The other
major factor is that Session beans are seen as extenstions of the client - multiple
threads implies multiple clients, which does not fit with this view of an extension.
Granted that stateless sessions are used more as facades over entities or service
interfaces than as 'extensions of the client', the programming model (and the
container's developer's task) are much simpler if we restrict session beans to one
thread of execution at any one time. Also, because of the way that stateless session
beans are pooled by the container, allowing two threads in one at once is not really
needed.
Of course, the 'Gotcha' here is that session beans can't be 'called back' to from
another EJB even within the same transaction. The reason that Entity beans are
allowed to be reentered (if their deployment descriptor says they're built that way) is
that there are (arguably) more cases when an entity might need to be called back
than there are for sessions.
• EJB 1.1
http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd
• EJB 2.0
http://java.sun.com/dtd/ejb-jar_2_0.dtd
When using EJB and making use of connection pools. How can changes to
the database be audited per user?
Location: http://www.jguru.com/faq/view.jsp?EID=318819
Created: Feb 1, 2001 Modified: 2001-02-02 12:11:16.527
Author: Subrahmanyam Allamaraju
(http://www.jguru.com/guru/viewbio.jsp?EID=265492) Question originally posed by
Chris Melville (http://www.jguru.com/guru/viewbio.jsp?EID=305546
This is quite not the case with EJBs. When you create a connection pool, the J2EE
server is the client for the database. Since a J2EE environment is a shared
environment, the practice is setup a very small number of connection pools, and
recycle the same pool of connections across several invocations (across several
"users").
The notion of a database user does not therefore exist. For instance, you may have
1000 concurrent HTTP sessions, but only 10% of them may be using connections
actively. In such cases if you try to allocate connections on user bases, you'll have
too many idle connections, ultimately paying performance penalty.
To answer your question, there is no direct and simple way of determining who
changed what. A reasonable approach is to constrain the methods on various beans
based on user roles, and log/audit certain business events (not database events).
For this we typically don't rely on DBMS logging but instead perform application level
logging using LAST_UPDATED_USER and LAST_UPDATE _TIMESTAMP columns on the
table. Okay so how do we populate the LAST_UPDATED_USER with the real user
who's updating the information? We can obtain it from the Session/Entity context in
the EJB.
When using EJB and making use of connection pools. How can changes to the
database be audited per user?
Author: Allen Fogleson (http://www.jguru.com/guru/viewbio.jsp?EID=344251), Jun
3, 2001
We actually had a client insist on this since the DB vendor had convinced the client
that only the database could effectively audit transactions. So we were forced into
designing a system that did this. What we ended up doing was not using any entity
beans, and all calls to the database used the datasource.getConnection(user, password)
method. Im not sure how the container manages that, probably instantiates a new
connection object, thus killing all the performace gained using a pool, but it worked.
(slow... and im sure that will be the complaint next, but it worked)
}//end of class
In Deployment Descriptor:-
<cmp-field><field-name>firstName</field-name></cmp-field>
<cmr-field>
<cmr-field-name>myaddress</cmr-field-name>
<cmr-field-type>Address</cmr-field-type>
</cmr-field>
Thus when Persistence manager generates the concrete class for above abstract
class.It creates a variable "firstName" of type String as CMP and "myaddress" which
of type Address, which is a CMR or also called as dependant object.
Regards
Prajakt
Comments and alternative answers
correction
Author: Venugopal Thachappilly
(http://www.jguru.com/guru/viewbio.jsp?EID=286533), Jul 23, 2002
Atleast in the latest specification of EJB 2.0, the above said is not entirely correct.
CMR is a relationship between two entity beans and the relationship is also managed
by the container. In the above example, address wouldn't be a value object, but a full
fledged entity bean. Refer to the spec or a book for details.
With RMI over IIOP, RMI based EJB servers can be mixed with RMI based or CORBA
Based EJB servers because everyone are propagating context information using IIOP.
RMI has the ability to tunnel through Firewalls. This is very slow and arduous
process, and it is really a security loophole. Special IIOP Firewall Proxies are
developed and available that will permit IIOP traffic to pass through. If you are using
IIOP protocol, any RMI or CORBA code you write will navigate the firewall.
Limitations are the effectiveness of the proxies. ie you will have to have proxies on
both client and server.
One cant set up a B2C site with a IIOP proxy thinking that will be a solution for the
problem. Only for limited applications where the server and client can be controlled,
IIOP proxy add value.
IONA provides a proxy called WonderWall and Borland provides the VisiBroker
GateKeeper.
Comments and alternative answers
Re: You could also use the Simple Object Access Protocol...
Author: Prasanna Singh (http://www.jguru.com/guru/viewbio.jsp?EID=280922),
Mar 27, 2001
I was trying to authenticate firewall inorder to send SOAP message accross the
internet and i was using java authenticate class. But did not work for me. What is
the correct way to do the authentication ? thanks
Re: Re: You could also use the Simple Object Access Protocol...
Author: ce ce (http://www.jguru.com/guru/viewbio.jsp?EID=238982), Mar 27,
2001
I think it depends on what type of authentication the firewall/proxy is
expecting. If your firewall wants NTLM level authentication then java may
cause you a problem since when the HTTP request goes out and the firewall
returns an NTML authentication msg the JVM may see that as an error. What
type of firewall are you using?
Does EJB 1.1 support mandate the support for RMI-IIOP ? What is the
meaning of "the client API must support the Java RMI-IIOP programming
model for portability, but the underlying protocol can be anything" ?
Location: http://www.jguru.com/faq/view.jsp?EID=319549
Created: Feb 2, 2001 Modified: 2001-02-02 16:26:35.097
Author: Nick Minutello (http://www.jguru.com/guru/viewbio.jsp?EID=222214)
Question originally posed by sanjeev jain
(http://www.jguru.com/guru/viewbio.jsp?EID=211266
A CORBA-based EJB Server actually implements its EJB Objects as CORBA Objects (it
therefore encorporates an ORB and this means that EJB's can be contacted by
CORBA clients (as well as RMI-IIOP clients)
A proprietry EJB still implements the RMI-IIOP API (in the client's stub) but the
underlying protocol can be anything. Therefore your EJB's CANNOT be contacted by
CORBA clients.
The difference is that in both cases, your clients see the same API (hence, your client
portability) BUT how the stubs communicate with the server is different.
No, RMI-IIOP doesn't support dynamic downloading of the classes as it is done with
CORBA in DII (Dynamic Interface Invocation).Actually RMI-IIOP combines the
usability of Java Remote Method Invocation (RMI) with the interoperability of the
Internet Inter-ORB Protocol (IIOP).So in order to attain this interoperability between
RMI and CORBA,some of the features that are supported by RMI but not CORBA and
vice versa are eliminated from the RMI-IIOP specification.You can download from the
Sun Microsystems RMI-IIOP home page.
Does RMI-IIOP support code downloading for Java objects sent by value
across an IIOP connection in the same way as RMI does across a JRMP
connection?
Then the answer is Yes.
If you use Oracle 8 you can use ORACLE ADVANCE QUERYING and subscribe for it
with JMS, so you object can register some message listener, which will be notified
when message sent by your batch process will arrive. For more detail information
how to lookup Oracle Advance Querying system and to subscribe your JMS receiver
or subscriber, look
http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/appdev.817/a
85456.pdf. (You may need to register yourself on technet.oracle.com first).
Comments and alternative answers
Re: Would this architecture actually work with CMP & BMP?
Author: Stu Charlton (http://www.jguru.com/guru/viewbio.jsp?EID=423826),
May 17, 2001
Entities and Sessions can't directly receive messages from JMS. You would need
an active object to montior the JMS queue, which would then act as an EJB client.
See the J2EE Patterns on http://developer.java.sun.com for an example of adapting
JMS onto EJB's without message-driven beans.
What is a Message Driven Bean, What functions does a message driven bean
have and how do they work in collaboration with JMS?
Location: http://www.jguru.com/faq/view.jsp?EID=327430
Created: Feb 13, 2001 Modified: 2001-02-13 08:45:45.329
Author: ranjay sinha (http://www.jguru.com/guru/viewbio.jsp?EID=290360)
Question originally posed by vasanth s
(http://www.jguru.com/guru/viewbio.jsp?EID=314566
Message driven beans are the latest addition to the family of component bean types
defined by the EJB specification. The original bean types include session beans,
which contain business logic and maintain a state associated with client sessions, and
entity beans, which map objects to persistent data.
Message driven beans will provide asynchrony to EJB based applications by acting as
JMS message consumers. A message bean is associated with a JMS topic or queue
and receives JMS messages sent by EJB clients or other beans.
Unlike entity beans and session beans, message beans do not have home or remote
interfaces. Instead, message driven beans are instantiated by the container as
required. Like stateless session beans, message beans maintain no client-specific
state, allowing the container to optimally manage a pool of message-bean instances.
Clients send JMS messages to message beans in exactly the same manner as they
would send messages to any other JMS destination. This similarity is a fundamental
design goal of the JMS capabilities of the new specification.
When a message arrives, the container ensures that a message bean corresponding
to the message topic/queue exists (instantiating it if necessary), and calls its
onMessage method passing the client's message as the single argument. The
message bean's implementation of this method contains the business logic required
to process the message:
Note that session beans and entity beans are not allowed to function as message
beans.
-ashutosh
When calling an EJB from another EJB should they both be packaged in
same JAR?. Are the any preferences for Weblogic or any other servers?
Location: http://www.jguru.com/faq/view.jsp?EID=332819
Created: Feb 19, 2001 Modified: 2001-02-25 07:49:39.083
Author: Alexey Ryndin (http://www.jguru.com/guru/viewbio.jsp?EID=221245)
Question originally posed by Junaid Shamim
(http://www.jguru.com/guru/viewbio.jsp?EID=136546
Definitely not. You can use any object published in JNDI by looking up it by name,
obtain reference to it and narrowing this reference. As far as I know this can be done
with any J2EE compatible server.
The only possible catch is to have the client classes available to the calling bean. See
What classes does a client application need to access EJB?
But If the beans are in the same J2EE Application unit ...
Author: Jonathan Morrissey (http://www.jguru.com/guru/viewbio.jsp?EID=330060),
Mar 19, 2001
I agree with the previous answer that the beans do not need to be in the same jar, but
it's worth knowing that if they are in the same container you can use EJB references
(see EJB spec 1.1, page 207, Sect 14.3). I have used this in my current project with a
performance gain of over 50%. Regards, Jonathan
Can I re-use the same Primary key class for various Entity Beans?
Location: http://www.jguru.com/faq/view.jsp?EID=342031
Created: Mar 1, 2001 Modified: 2001-03-01 15:23:42.06
Author: Robert Castaneda (http://www.jguru.com/guru/viewbio.jsp?EID=4362)
Question originally posed by Roy abraham
(http://www.jguru.com/guru/viewbio.jsp?EID=340391
There is a discussion of this pattern on the serverSide site titled Command Pattern
(Abstracted value-objects in/out of EJB).
Well most of the Application servers have tools for creating the deployment
descriptor. But if they do not have it, then you can use the SessionDescriptor class
for creating a deployment descriptor for session beans and EntityDescriptor class for
entity beans. For further reference refer the following JavaDoc
But remember that EJB 1.1 uses XML for specifying the deployment descriptor and
these classes have since been deprecated.
There is also a useful thread on the topic of J2EE naming standards here .
Comments and alternative answers
Looking at the Sun site, in "Java Live" chat about J2EE standardization, there're
people asking for coding standards to Sun: check this link:
http://developer.java.sun.com//developer/community/chat/JavaLive/2000/jl0201.html.
How can I use a local DTD to validate ejb-jar.xml instead of going to SUN's
server as specified in DOCTYPE element?
Location: http://www.jguru.com/faq/view.jsp?EID=347169
Created: Mar 8, 2001 Modified: 2002-12-01 15:45:28.793
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
nicole li (http://www.jguru.com/guru/viewbio.jsp?EID=281530
You can do this by specifying a local DTD-file in the SYSTEM property of the
DOCTYPE element. Here is an example:
If your DTD was located inside a localfolder - "C:/localdtd" then your DOCTYPE
element should be as follows:
ACTIVATION/PASSIVATION
Author: OBUCHI MACHINI (http://www.jguru.com/guru/viewbio.jsp?EID=297581),
Apr 3, 2001
Yes,this can be tuned accordingly.. The APPSERVER Which I know of is
"WEBLOGIC 5.1 ". In this u can tune the Activation/Passivation
Re: ACTIVATION/PASSIVATION
Author: Gautam Mehta (http://www.jguru.com/guru/viewbio.jsp?EID=390509),
Apr 13, 2001
can u explain it in a bit detail Thanks Gautam
Re: ACTIVATION/PASSIVATION
Author: lakshman prasad (http://www.jguru.com/guru/viewbio.jsp?EID=423825),
Jun 17, 2001
Dear Obuchi, Can explain little more about how to do this tunning in weblobic app
sever.
How can I pass a ResultSet from an EJB to a client? what are the best
classes to use?
Location: http://www.jguru.com/faq/view.jsp?EID=349555
Created: Mar 12, 2001 Modified: 2001-03-15 13:41:49.123
Author: Jonas Bergqvist (http://www.jguru.com/guru/viewbio.jsp?EID=81465)
Question originally posed by Alec Smecher
(http://www.jguru.com/guru/viewbio.jsp?EID=319506
It is better that you iterate through the ResultSet on the server side and return a
Vector of Vectors (or something else similar) representing the rows and columns of
the ResultSet. Everything that is sent between the EJB server and the EJB client
should of course be serializable (due the to RMI specification). A ResultSet is NOT
serializable and therefore you should (can) not return a ResultSet.
Comments and alternative answers
Use can use CachedRowSet to pass ResultSet back to client and to other beans.
Author: Stan UA1OUT (http://www.jguru.com/guru/viewbio.jsp?EID=555595), Nov
21, 2001
Check out sun.jdbc.rowset.CachedRowSet class.
It can be used to disconnect a rowset from the DB and passed back to the client. Since
cached rowset implements javax.sql.RowSet the client can manipulate the
disconnected instance of the cached class as usual.
To be able to use CachedRowSet you have to download and put on your client's and
server's classpath rowset.jar file.
The above is described in more details in "Data transfer Rowset" EJB pattern.
Regards,
Stan
How can I get the underlying JDBC connection which the CMP bean is using?
Location: http://www.jguru.com/faq/view.jsp?EID=351799
Created: Mar 15, 2001 Modified: 2001-03-15 15:00:32.431
Author: sukumar kaukuntla (http://www.jguru.com/guru/viewbio.jsp?EID=351793)
Question originally posed by prateek saxena
(http://www.jguru.com/guru/viewbio.jsp?EID=304604
Technically speaking you can't. But you can access a JDBC connection within the
same transaction from a CMP bean using the following XML deployment descriptor :
<enterprise-beans>
<entity>
<resource-ref>
<description>Datasource for the myDB database</description>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>java.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
</entity>
....
</enterprise-beans>
Comments and alternative answers
Might be possible...
Author: Ivo Limmen (http://www.jguru.com/guru/viewbio.jsp?EID=327483), Apr 9,
2001
The J2EE 1.2 specifications state that retrieving the JDBC connection should but
possible but it might be having a context that is not stated as specified in the
specifications. This is a piece of the specifications:
This specification recommends, but does not require, that all resource factory
references be organized in the subcontexts of the application component’s
environment, using a different subcontext for each resource manager type. For
example, all JDBC™ DataSource references should be declared in the
"java:comp/env/jdbc" subcontext, all JMS connection factories in the
"java:comp/env/jms" subcontext, all JavaMail connection factories in the
"java:comp/env/mail" subcontext, and all URL connection factories in the
"java:comp/env/url" subcontext.
This means that you will have to lookup in your console application at the used
naming facilities and see what the naming context is for the JDBC connections. You
can use a context lookup to retrieve the Bean's JDBC datasource.
With regard to Entity Beans, what happens if both my EJB Server and
Database crash, what will happen to unsaved changes? Is there any
transactional log file used?
Location: http://www.jguru.com/faq/view.jsp?EID=412828
Created: Apr 30, 2001
Author: Shaun Childers (http://www.jguru.com/guru/viewbio.jsp?EID=30243)
Question originally posed by ponraj sivaram
(http://www.jguru.com/guru/viewbio.jsp?EID=314542
Actually, if your EJB server crashes, you will not even be able to make a connection
to the server to perform a bean lookup, as the server will no longer be listening on
the port for incoming JNDI lookup requests. You will lose any data that wasn't
committed prior to the crash. This is where you should start looking into clustering
your EJB server.
Comments and alternative answers
Answer
Author: Uma Maheswari Kandasamy
(http://www.jguru.com/guru/viewbio.jsp?EID=310809), May 6, 2001
Hi, Any unsaved and uncommited changes are lost the moment your EJB Server
crashes. If your database also crashes, then all the saved changes are also lost unless
you have some backup or some recovery mechanism to retrieve the data. So consider
database replication and EJB Clustering for such scenarios, though the occurence of
such a thing is very very rare. Thx, Uma
For Entity Beans, What happens to an instance field not mapped to any
persistent storage,when the bean is passivated ?
Location: http://www.jguru.com/faq/view.jsp?EID=412829
Created: Apr 30, 2001
Author: Jonathan Morrissey (http://www.jguru.com/guru/viewbio.jsp?EID=330060)
Question originally posed by bob miller
(http://www.jguru.com/guru/viewbio.jsp?EID=342494
The specification infers that the container never serializes an instance of an Entity
bean (unlike stateful session beans). Thus passivation simply involves moving the
bean from the "ready" to the "pooled" bin. So what happens to the contents of an
instance variable is controlled by the programmer. Remember that when an entity
bean is passivated the instance gets logically disassociated from it's remote object.
Theoretically you can achieve it with CMP, but using 6 different instances of the
application server, or 6 'applications' on your application server (if it will allow you).
Each application will connect to one of your 6 databases.
Based on the login of your customer, you get the correct InitialContext().
Other ideas..
Author: Stu Charlton (http://www.jguru.com/guru/viewbio.jsp?EID=423826), May
17, 2001
Some extended CMP implementations should allow for multiple mappings inside an
EJB JAR. WebGain's TopLink, for instance, might be able to do this, since it adds a
lot of features outside the realm of CMP.
6 diff databases
Author: bidarkar jay kumar (http://www.jguru.com/guru/viewbio.jsp?EID=440821),
Jun 18, 2001
i trie using weblogic5.1(though older) but it worked when i used to connect to 3
different databases.i guess this should happen in any case.
No, it doesn't. At this point in time, the EJB 2.0 specification is not completely
finalized.
It's just because a Stateless Session Bean does not have state. The container does
not guarantee (like for the Stateful SEssion Bean) that the bean that will be used on
two method calls, will be the same.
Comments and alternative answers
To be precise, for the sake of argument, let's say that a stateless bean can maintain (it
can, in fact) state.
During a transaction, a client can invoke one or more methods on a bean. However,
the container does not guarantee that the same bean instance is used for all calls.
Imagine a pool of instances participating in a group of concurrent trasnactions. Since
an instance can participate in multiple ongoing transactions, it can not compensate (or
synchronize) itself due to transaction commit/rollback. You can try to visualize this by
trying to write some code for synchronization.
I tried to do that because I wanted to trace the transaction boundaries to a log file, to
measure how long it takes to perform a transaction, and how long the commit takes. I
was quite confused because it didn't work, until I found out that
SessionSynchronization doesn't work with stateless session beans.
Where can I learn (more) about CORBA (Common Object Request Broker
Architecture)?
Location: http://www.jguru.com/faq/view.jsp?EID=431188
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
Where can I learn (more) about using JNDI (Java Naming and Directory
Interface)?
Location: http://www.jguru.com/faq/view.jsp?EID=431212
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
Where can I learn (more) about using design patterns with Java?
Location: http://www.jguru.com/faq/view.jsp?EID=431238
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
Where can I learn (more) about Java's support for developing multi-
threaded programs?
Location: http://www.jguru.com/faq/view.jsp?EID=431248
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
Where can I learn (more) about Java's support for transaction processing?
Location: http://www.jguru.com/faq/view.jsp?EID=431948
Created: May 31, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
With that comment aside, I'd suggest that you model relationships with associations,
and draw them in class diagrams. Component diagrams, are only suitable for
expressing dependencies (a weak form of relationship).
If it is a business model, then your classes are just business (domain) objects, many of
which map to EJBs. In that case, you just draw relationships (association or
inheritance) between the business objects as dictated by the semantics of the business
domain. How those associations are implemented is not a concern at this level.
If your model is a design model, on the other hand, your classes represent EJBs. In
the JSR 26 referred to by Jim Conallen, stereotypes are used to identify whether a
class is an entity bean, session bean, etc. The stereotypes are in fact a sort of
shorthand. An entity bean actually consists of a group of Java classes: the
implementation class, the remote interface, the stubs/skeletons, the local interface,
etc. An association or an inheritance relationship between EJBs may be implemented
in different ways, depending on which design pattern(s) you use. Some standard
patterns are now emerging (see Sun's EJB blueprint directory, jGuru, and elsewhere).
However, I do not believe any of them have been codified into stereotypes or any sort
of shorthand notation as yet. So, IMHO, expressing relationships between entity
beans in a UML model means chossing between two options:
1. Draw all the EJB classes explicitly in the class diagram and draw the relationships
as you intend to implement them.
2. If you are going to be consistent in your implementation (always a good idea :-),
use a shorthand notation (e.g., stereotypes) for the EJBs and for the relationships, and
document the shorthand using supporting class diagrams (where you explicitly draw
all the classes and associations).
Hope this answers the question somewhat.
Yes, you can create CMP Entity Beans without primary keys. But you must be aware
of the implications:
In essence, CMP was not designed to not have primary keys, although it can work.
The development process is the same as when you create CMP which has primary
keys.
Yes it is possible
Author: prashant jani (http://www.jguru.com/guru/viewbio.jsp?EID=100991), Jan 18,
2002
in the cmp xml file. Do not provide CMp mapping for the primary key.
Thats all
but u will have to create a sequence at the database level for the primary key.
this will avoid duplicate keys problem
Jani
about EJB performance Where can I find articles about EJB performance?
Location: http://www.jguru.com/faq/view.jsp?EID=438168
Created: Jun 12, 2001
Author: Luis F. Canals Samaniego
(http://www.jguru.com/guru/viewbio.jsp?EID=66172) Question originally posed by
slose Lin (http://www.jguru.com/guru/viewbio.jsp?EID=429700
EJB performance
Author: Shahram Khorsand (http://www.jguru.com/guru/viewbio.jsp?EID=3357), Jun
17, 2001
The EJB performance is very dependent on the products you are using. However,
couple of really good reviews of different products are available on
http://www.theserverside.com.
Cheers,
Shahram
Using the Java Connector Architecture with EJBs Can I map an entity bean
to an EIS for which a JCA resource manager exists? Ideally, I would like to
use container managed persistence for this.
Location: http://www.jguru.com/faq/view.jsp?EID=440204
Created: Jun 16, 2001
Author: CustomWare Asia Pacific
(http://www.jguru.com/guru/viewbio.jsp?EID=139414) Question originally posed by
Ara Kassabian (http://www.jguru.com/guru/viewbio.jsp?EID=57884
Is there a COM Bridge that lets Windows developers create native client
applications that access Enterprise JavaBeansTM (EJBTM) components
deployed on a J2EE App server?
Location: http://www.jguru.com/faq/view.jsp?EID=448051
Created: Jun 30, 2001
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
JavaTM 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM
Bridge 1.0 Early Access.
There are code samples in Sun's JNDI tutorial that explain how to perform LDAP
authentication through JNDI.
env.put(Context.InitialContextFactory,
"com.sun.jndi.ldap.LdapCtxFactory"); // I added this line myself
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires,
o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
You may want to store the actual LDAP tree that contains the users you are
authenitcating so youi can dynamically set it without recoding, so the actual code
may look like this if you store the LDAP tree name in JNDI as "myUserLDAPTree"
(ou=NewHires, o=JNDITutorial):
env.put(Context.InitialContextFactory,
"com.sun.jndi.ldap.LdapCtxFactory"); // I added this line myself
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=" + passedUserName + "," +
(String)new InitialContext().lookup("myUserLDAPTree"));
env.put(Context.SECURITY_CREDENTIALS, passedPassword);
// Create the initial context
DirContext ctx = new InitialDirContext(env);
How would you find and store the actual LDAP tree?
Author: neal ravindran (http://www.jguru.com/guru/viewbio.jsp?EID=17737), Mar 5,
2003
You have said
"You may want to store the actual LDAP tree that contains the users you are
authenitcating so youi can dynamically set it without recoding, so the actual code may
look like this if you store the LDAP tree name in JNDI as "myUserLDAPTree"
(ou=NewHires, o=JNDITutorial): "
I have to authenticate users at different ou levels...Some are one level deep other are
more than that. How can I write a common login program using the technique you
mentioned?
Stateful Session Beans and Fail Over How are stateful session beans
handled in a failover situation -- is this vendor dependent?
Location: http://www.jguru.com/faq/view.jsp?EID=452355
Created: Jul 9, 2001
Author: Shahram Khorsand (http://www.jguru.com/guru/viewbio.jsp?EID=3357)
Question originally posed by Krishna Dev
(http://www.jguru.com/guru/viewbio.jsp?EID=414725
If you are planning on spending alot of money. There are hardware clusters and
different technologies that provide HA (high availability) services. see SUN clustering
servers.
When it comes to WL and WAS there wasn't a clean failover technology that didn't
impact the performance. Because the problem with statefullness is that it makes
everything so much slower. I found that BAS gave us the best performance.
Some justification...
Author: Nick Minutello (http://www.jguru.com/guru/viewbio.jsp?EID=222214), Sep
1, 2001
I think we might need a few more details to back up the comments on "who's best".
Firstly, it is guaranteed that you will have to accept some performance hit when you
cluster. You cant get scalability and availability otherwise. There is no such thing as a
free lunch.
Secondly, unless I am mistaken, BAS dont really have a statefull fail-over solution. (I
could be wrong). My understanding is that the only state replication mechanism is via
passivation! This means you might get statefull session failover with BAS if the
Session Bean miraculously gets passivated just before its failover.... I dont know of
any other state replication mechanism that Borland has. I would gladly be corrected
on this if this were wrong.
So, in conclusion, clustering and fail-over DO have a performance cost. I suspect you
dont see a performance impact with Borlands solution because, in fact, it doesnt have
a statefull fail-over solution.
None of the EJB containers support this. In any case, the performance impact
would be quite large - you would be talking about a 2PC commit on every
transaction.
Correcting my earlier post, WLS doesnt use *multi-cast* to replicate - but the
in-memory replication is done over the network.
Weblogic does this after the Stateful bean's transaction commit - which means
there is only a tiny window where failure can occur resulting in state loss.
Re: Old
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7), Jul 10,
2001
Oops, 2000 for the J2EE ones. The standard library ones are 1999.
Re[2]: Old
Author: innum onenu (http://www.jguru.com/guru/viewbio.jsp?EID=385539),
Dec 2, 2001
so What's the inference about javareport.com package structure? Is it new and
updated or old? Also, eventhough the main root element is J2EE, guess it
doesn't cover all the J2EE API's(JMS, JNDI etc.) Any other place where the
entire(latest) set could be found? Also any thoughts on how to produce these
sort of documents? Is it possible to attain through javadoc? Lastly, What are all
the API's covered under J2EE and their latest versions(a link would be great).
Does setting the Home and Object stubs to null from an EJB client improve
performance?
Location: http://www.jguru.com/faq/view.jsp?EID=475266
Created: Aug 13, 2001
Author: Nick Minutello (http://www.jguru.com/guru/viewbio.jsp?EID=222214)
Question originally posed by prakash prabhu
(http://www.jguru.com/guru/viewbio.jsp?EID=91561
If your appserver uses JRMP, then it *might* mean that your serverside objects
(EJB's) get garbage collected sooner. However, it depends on the appserver's lifecycle
management. Since IIOP is mandated in the EJB spec (and IIOP does not support
distributed garbage collection) then most appservers probably rely on a different
strategy for object lifecycle management.
If you ARE using JRMP, then the client-side garbage collection of the stubs (which can
be accelerated by setting references to null) can reduce the network load (as the
stubs sit there pinging the server objects to keep them alive).
In fact, you will get better performance by *caching* your home stubs (these are
always slow to look up). Check out the Home Factory pattern at
http://www.theserverside.com/home/thread.jsp?thread_id=7931
In EJB 2.0 Entity Beans, What is the difference between the local home
interface and the remote home interface?
Location: http://www.jguru.com/faq/view.jsp?EID=477519
Created: Aug 15, 2001
Author: Christopher Pickslay (http://www.jguru.com/guru/viewbio.jsp?EID=468619)
Question originally posed by CustomWare Asia Pacific PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=139414
EJB 2.0 adds the notion of local beans, which are accessible only from within the JVM
your beans are running in.
The idea behind this is that many beans you might create are never meant to be
accessed by remote clients. For example, you may program beans meant for your
public interface like Order and Invoice, and you may have other helper beans which
are never meant to be instantiated by remote clients, like Inventory and
SalesTaxCalculator. Or you might have an entire system that takes advantage of
EJB's transaction management, persistence, etc, but which has no remote (i.e.,
outside the current JVM) clients at all.
With EJB 1.1, you had to implement remote client views for all these beans, even if
you had no remote clients. This means that your home and remote interfaces had to
extend javax.rmi.Remote, which puts several restrictions on them, including:
Local beans also have limitations, the primary one being that you can only access
them from within the same JVM, so they don't make much sense for distributed
applications. Also, if you're converting your old remote interfaces to local ones, you
have to be careful about the pass-by-reference semantics, which may lead to
unintended consequences.
Note that you can implement both remote and local interfaces to your beans. But in
most cases it makes more sense to define your application model first, based on
access, distribution, and deployment needs, and then decide on local vs. remote
based on the tradeoffs.
In EJB 2.0, What is an Entity Bean's local interfaces? How do I define them?
Location: http://www.jguru.com/faq/view.jsp?EID=477524
Created: Aug 15, 2001
Author: CustomWare Asia Pacific
(http://www.jguru.com/guru/viewbio.jsp?EID=139414) Question originally posed by
CustomWare Asia Pacific PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=139414
In EJB 2.0, An Entity Bean can have a set of Local interfaces for use by clients within
the same JVM (known as collocated clients). The local interfaces extend the following
interfaces:
Arguments between these interfaces and clients calling them are passed by
reference.
What is the difference between Public Final Draft and Public Final Draft 2 of
EJB 2.0?
Location: http://www.jguru.com/faq/view.jsp?EID=479764
Created: Aug 20, 2001
Author: CustomWare Asia Pacific
(http://www.jguru.com/guru/viewbio.jsp?EID=139414) Question originally posed by
CustomWare Asia Pacific PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=139414
Check out section E.12 of Public Final Draft 2 for a complete listing of the changes
between versions.
The major changes were the addition of Local interfaces and Local Home interfaces
for both Entity and Session Beans.
On the Container Managed Persistence (CMP) front, Dependant Objects (which were
a source of controversy) were removed.
How do EJB and Web Services relate together? Are Web Services a
replacement for EJB?
Location: http://www.jguru.com/faq/view.jsp?EID=488279
Created: Aug 31, 2001
Author: CustomWare Asia Pacific
(http://www.jguru.com/guru/viewbio.jsp?EID=139414) Question originally posed by
CustomWare Asia Pacific PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=139414
Web Services can be thought of as a wrapper that can be used to allow EJB's to
invoke external services and also to allow external services and clients to invoke the
EJB's. A major strength of Web Services is in the integration of the J2EE platform
with the Microsoft .NET platform. Using Web Services allows, for example, Microsoft
Visual Basic clients to access EJB's as clients.
Some products such as IBM WebSphere and BEA WebLogic already support Web
Services inside there Application Servers.
EJBs are Java Components that can be only accessed directly using another Java
client. The disadvantage here is that these components and its services are remotely
available to only Java application. (Here I am not talking about web clients)
Suppose you want have a service, say, Tax Calculation Service EJB, which you would
want another application to access, no matter what kind/technology that application is
written in, then you will go for this WebServices. All you would do is PUBLISH your
service to a registry called the UDDI and let the other applications know about such a
service. Then, this other application will contact the REGISTRY using SOAP and
know about the methods and parameters that your component needs and will build up
a SOAP REQUEST for your component. Your component will then do the Tax
Calculation and then give back a SOAP RESPONSE which the client application will
use for its purpose.
So EJB is one way to write your WebService. Hope this makes things clear, Uma
A select method is similar to a finder method for Entity Beans, they both use EJB-QL
to define the semantics of the method.
They differ in that an ejbSelect method(s) are not exposed to the client and the
ejbSelect method(s) can return values that are defined as cmp-types or cmr-types.
For more information on EJB QL, see this FAQ.
How can I update the primary key field in a CMP Entity Bean?
Location: http://www.jguru.com/faq/view.jsp?EID=515864
Created: Oct 9, 2001
Author: Tim Duggan (http://www.jguru.com/guru/viewbio.jsp?EID=506387)
Question originally posed by Shanks75 shanks75
(http://www.jguru.com/guru/viewbio.jsp?EID=506367
You cannot change the primary key field of an Entity bean. Refer to page 130 of the
EJB 2.0 specification, it states "Once the primary key for an entity bean has been
set, the Bean Provider must not attempt to change it by use of set accessor methods
on the primary key cmp-fields. The Bean provider should therefore not expose the
set accessor methods for the primary key cmp-fields in the component interface of
the entity bean."
A work around to update a primary key field, would be to remove and then an re-
create the bean.
When using Websphere 3.5, VisualAge and Oracle to develop CMP EJB's I
receive the following error: "Unable to insert data into a NOT NULL field".
What am I doing wrong?
Location: http://www.jguru.com/faq/view.jsp?EID=515867
Created: Oct 9, 2001
Author: Shai Almog (http://www.jguru.com/guru/viewbio.jsp?EID=501707) Question
originally posed by Theresa Betts
(http://www.jguru.com/guru/viewbio.jsp?EID=506361
You need to modify the create method for the Entity bean to initialize ALL the not null
fields.
VAJ defaults to initializing the primary key but it doesn't initialize the NOT NULL
fields, this won't work because any invocation of create() immediately causes insert.
Take a look (or debug) the deployed code generated by VAJ to see the generated
code that is deployed into the server.
Answer
Author: Rocky NAIR (http://www.jguru.com/guru/viewbio.jsp?EID=537969), Nov 3,
2001
well hi there proabably in in the backend that particular field will be not null and u
must be trying to insert a null field .. in visula age there is an option for break points..
and also u can see which field has got what values in the top right corner.. this way u
can check which variable has got a null value and compare it with the database
Regards..
Stateful and Stateless Session Beans are for different purposes. Therefore, stateful
session bean cannot act as a Stateless Session Bean since their lifecycles are
different. You can create a Stateful Session Bean to not store any conversational
state and therefore, at least in theory, you can make it stateless, but since the
lifecycles of Stateless and Stateful Session Beans are different, you do not achieve
anything by doing this.
Comments and alternative answers
Stateful to stateless
Author: Subrahmanyam Allamaraju
(http://www.jguru.com/guru/viewbio.jsp?EID=265492), Nov 15, 2001
I would like to clarify the above answer. It is possible to change stateful beans into
stateless beans declaratively. However, depending how the bean is implemented there
may be some side effects.
Firstly, if the state of the bean is modified by different methods, there may be
inconsistencies in the behavior of the bean.
Secondly, the container will not invoke session synchronization methods and hence
you can not manipulate the state of the bean in the case of a rollback.
As long as your bean does not depend on the above two, you can make a stateful bean
stateless. In your case, you may have to carefully analyze if there is state held in the
bean, and if so, how the state is modified by different methods.
Omar,
In few words, "marshalling" refers to the process of converting the data or the
objects inbto a byte-stream, and "unmarshalling" is the reverse process of
converting the byte-stream beack to their original data or object. The conversion is
achieved through "serialization".
Yes, you can convert them later, but keep in mind that Java Beans are client-side
objects and EJBs are server side object, and they have completely different
development, lifecycle, purpose... They have nothing in common other than the fact
that they both have Java Beans in their name.
It is the same as if you ask can you convert any java class into EJB. The answer is
still yes given that the class you want to make an EJB does not violate any of the EJB
restrictions posed in its specifications.
If you need to write EJBs, it is a big waste of time to create java beans and then
convert them to EJBs.
There is absolutely no good reason to do that and many reasons why not to do it.
Are there any examples where i can look for such a conversion?
(1)JavaBeans are not used for distributed purposes and EJB's are used for
Distributed applications.
(3)One way, they are realated to each other, they are component based
models.A component is developed for specific purpose and not for specific
application.It can be reused across the software life cycle.
So dude, clearly understand what EJB is meant for and what javabean is meant
for.The power of EJB can be achieved by utilising it for the right purpose.
Regards,
jay..
In EJB 1.1., how do I ensure that while any client can access EJB A, only EJB
A should be allowed to access EJB B? ie my client cannot access EJB B
directly.
Location: http://www.jguru.com/faq/view.jsp?EID=560080
Created: Nov 25, 2001
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
lina chitturi (http://www.jguru.com/guru/viewbio.jsp?EID=388164
Hi,
Maybe this it's just a silly idea, but can't you just limit the access to EJB B inside the
deployment descriptor, using the <method-permission> tag?
<method-permission>
<role-name>guest</role-name>
<method>
<ejb-name>EJB_A</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<method-permission>
<role-name>administrators</role-name>
<method>
<ejb-name>EJB_B</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
This should not allow anyone without the administrator permissions to access to the
EJB_B, and I think that you can set the context inside EJB_A to be in that security
level.
Bypassing login prompt for J2EE1.3 using runclient command
Location: http://www.jguru.com/faq/view.jsp?EID=560676
Created: Nov 26, 2001
Author: Gerard Weatherby (http://www.jguru.com/guru/viewbio.jsp?EID=550879)
Question originally posed by Gauri Tendulkar
(http://www.jguru.com/guru/viewbio.jsp?EID=542648
Additional Information
While connecting to J2EE1.3 server for a standalone java application (in .ear) using
runclient command, there is the need to bypass the login prompt for login name and
password.
As per the documentation, this can be done by the following command:
runclient -client <<appname.ear>> -name
<<app_displayname>>
-Dj2eelogin.username=<<user_name>>
-Dj2eelogin.password=<<password>>
But this does not work. (Ultimately it prompts for login name and password).
Location: http://www.jguru.com/faq/view.jsp?EID=560681
Created: Nov 26, 2001
Author: Bozidar Dangubic (http://www.jguru.com/guru/viewbio.jsp?EID=433955)
Question originally posed by Janakiraman Nellissery
(http://www.jguru.com/guru/viewbio.jsp?EID=539086
(b) Read the top of my message. so, you cannot automatically. You could try to save
the state of stateful session bean to non-volatile storage after each method
invocation. that wastes lots of resources but could be implemented if you really,
really need to keep client's state when server crashes. Of course, you would need a
mechanism to recover that state from storage yourself.
(c) Well, you do not. The design of stateful session beans is such that it starts out at
default and maintains a state as clients perform operations on the system. Nowhere
in the specifications do you read that session are "crash-safe" or that there is a fail-
over when server crashes. Web containers do not keep http sessions around when
they crash and ejb container is no different. As I wrote in (b) you can implement it
yourself but you have be smart on how you go about doing it.
No. You cannot change the transaction isolation level in the middle of transaction.
Comments and alternative answers
So my conclusion would be: The isolation level only can be set for session bean
methods beginning a new transaction (REQUIRES resp. REQUIRES_NEW), by no
means for entity beans. Is this conclusion correct. Many thanks Klaus
First: How the isolation level is set I already knew. Second: That it isn´t
possible to be changed in the middle of a transaction was a previous answer.
And anyway: I think the isolation level can be set. Therefore I would like to
ask my question again.
A lot of thanks
Klaus
What is the need of Remote and Home interface. Why cant it be in one?
Location: http://www.jguru.com/faq/view.jsp?EID=567986
Created: Nov 30, 2001
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
hari kp (http://www.jguru.com/guru/viewbio.jsp?EID=557981
Hi,
In a few words, I would say that the main reason is because there is a clear division
of roles and responsabilities between the two interfaces.
The home interface is your way to communicate with the container, that is who is
responsable of creating, locating even removing one or more beans.
The remote interface is your link to the bean, that will allow you to remotely access
to all its methods and members.
As you can see there are two distinct elements (the container and the beans) and
you need two different interfaces for accessing to both of them.
I would suggest you to take a look at this FAQ: What's the difference between
EJBHome, EJB Home, EJB Object, EJBObject and EJB (not to mention Home Interface
and Remote Interface)? and, maybe, spend some time in reading the EJB
Specifications that are extremely clear and interesting.
If the objects are local, then you can use a factory method or a factory object.
However, if the objects are remote, you can only use a factory object. CORBA had
such a concept as a factory object.
In EJB, the factory object is the Home Object. There is always one and only one of
these home objects, thats why you can have an interface to this object (without the
need for another factory object).
It would be impossible for the server side object to be both object AND factory - so
that is why there are two interfaces.
You can have CMP Entity Bean map to whichever table you want and you can have
business methods in the bean retrieve values from whichever table you want but not
ejbStore() ejbLoad()... (i.e not the container callbacks).
CMP does stand for Container managed persistence and therefore you have to let the
container do the persistence for you.
But there is nothing to prevent you from declaring a business method in your entity
bean that uses JDBC to connect to the database and retrieve data from some other
table.
The trouble is that if you business method in populating attributes of the bean itself
from a table to which it is not mapped. What can happen in this scenario is app
server can figure out that the value of an attribute in your bean has changed and call
callback that will retrieve values into the bean attributes from the original table to
which CMP attributes are mapped.
As far as I know, there is nothing, in the EJB specifications, that prevents you to
create an Entity Bean without the create() method. In this situation, the only way to
obtain an instance of the bean is using a finder method.
Without the create() method, the only way to create new beans is manually
accessing to the database and using, for example, SQL insert statements.
In those cases, you can create an instance of a bean based on the data present in the
table. All one needs to know is the primary key of that table. i.e. a set a columns that
uniquely identify a single row in that table. Once this is known, one can use the
'getPrimaryKey()' to get a remote reference to that bean, which can further be used to
invoke business methods.
EJBs are suppose to be portable between different app server who comply with the
Sun's specifications for compliant EJB containers. Because of this reason, loading of
native libraries is not allowed in EJB. if some app servers allow this as an
enhacement, you need to look at the documentation of that particular app server to
find your answers. but overall, loading native libraries and using JNI from EJB is
prohibited by the spec. you could use JMS or MDBs to accomplish the same with
similar amount of work.
Comments and alternative answers
J2EE Connector
Author: Nick Minutello (http://www.jguru.com/guru/viewbio.jsp?EID=222214), Dec
9, 2001
What sort of functionality is in this C++ library? How fine-grained is the interface to
it? What does it do?
A valid means of using native code is to use the J2EE Connector Architecture.
However, I would strongly recommend that for C++ code, you dont use JNI. The
main reason is that a bug in your C++ code can bring your whole JVM down. It really
compromises the robustness that the appserver environment gives you.
If you really have to - then try use a separate Appserver for the JNI components - and
cluster them separately.
EJB-JNI
Author: Wap Dev (http://www.jguru.com/guru/viewbio.jsp?EID=914149), Jun 13,
2002
I am devloping an application server which is in windows platform,i want to Invoke
Java Beans using JNI,whether it is possible or only normal .class files will be intiated
BTW: This is also possible for .NET applications using Codemesh's JuggerNET tool.
If you don't want to purchase our product, you have several other choices:
The first alternative might actually not be too bad if all you need to do can be
wrapped up in one or two method calls. We usually recommend against doing
it by hand if you need advanced features like asynchronous callbacks (for
MessageListeners) or if you have more than 10 integration points.
Good luck,
Alex
There is EntityContext too which is also and EJBContext object that'll be provided to
an EntityBean for the purpose of the EntityBean accessing the container details.
In general, the EJBContext (SessionContext and EntityContext), AppletContext and
ServletContext help the corresponding Java objects in knowing about its 'context'
[environment in which they run], and to access particular information and/or service.
Whereas, the javax.naming.Context is for the purpose of 'NAMING' [by the way of
referring to] an object.
InitialContext
Author: rao ande (http://www.jguru.com/guru/viewbio.jsp?EID=760782), Feb 15,
2002
What can be inferred from implementing the methods in Context. i.e, Is it that if we
set the InitialContext and give a name, we are binding it by that name?
What are all the steps that are required to port EJB 1.1 code to EJB 2.0
compatible?
Location: http://www.jguru.com/faq/view.jsp?EID=585941
Created: Dec 15, 2001
Author: Bozidar Dangubic (http://www.jguru.com/guru/viewbio.jsp?EID=433955)
Question originally posed by Dilli Babu Nandarapu
(http://www.jguru.com/guru/viewbio.jsp?EID=260919
Question continues:
What are all the changes I have to do for my EJB1.1 code to port into EJB2.0
compatible. The present application is in EJB1.1. I need to port this code to EJB2.0
spec.
Ejb 1.1 code will run in the container compatible with Ejb 2.0 without any change.
But, EJB 2.0 is a more robust and powerful specification with many new features so
you may considering altering your code to take advantage of these new features.
But as I said, you do not need to change anything to make EJB 1.1 code execute in
an EJB 2.0 environment.
[If you are interested in an article about the migration from EJB 1.1 to EJB 2.0, I
strongly suggest you to take a look at this article: Migrating from Enterprise
JavaBeansTM(EJBTM) 1.1 to 2.0 - AAG]
Does this mean that EJB1.1 & EJB2.0 beans can interoperate without problems?
Re: Does this mean that EJB1.1 & EJB2.0 beans can interoperate without
problems?
Author: Sushil Srivastava (http://www.jguru.com/guru/viewbio.jsp?EID=744298),
Feb 4, 2002
You should be able to use both the EJB1.1 and EJB2.0 bean in the App Serve
without a hitch as EJB2.0 suports EJB1.1 and as such they can co exist. So you
should not need to change anything. But do bear in mind that the CMP
specifications have changed quite a lot and as such are not compatible althoug the
application server is required to support both.
From the EJB 2.0 specification: "An onMessage call is always a separate transaction,
because there is never a transaction in progress when the method is called."
When a message arrives, it is passed to the Message Driven Bean through the
onMessage() method, that is where the business logic goes.
Since there is no guarantee when the method is called and when the message will be
processed, is the container that is responsible of managing the environment,
including transactions.
To have a consistent interface, so that there is no different interface that you need to
implement for Stateful Session Bean and Stateless Session Bean.
Both Stateless and Stateful Session Bean implement javax.ejb.SessionBean and this
would not be possible if stateless session bean is to remove ejbActivate and
ejbPassivate from the interface.
You could argue that the two (stateful and stateless) are so different that they should
have their own interface but Sun did not think so. They made both session beans
implement the same interface and provided deployment descriptor to denote which
one is it that you are deploying.
Comments and alternative answers
Static variables in EJB should not be relied upon as they may break in
clusters. Why?
Location: http://www.jguru.com/faq/view.jsp?EID=710888
Created: Jan 6, 2002
Author: Bozidar Dangubic (http://www.jguru.com/guru/viewbio.jsp?EID=433955)
Question originally posed by Gaurav Sharma PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=66767
Static variables are only ok if they are final. If they are not final, they will break the
cluster.
What that means is that if you cluster your application server (spread it across
several machines) each part of the cluster will run in its own JVM. If you declare a
static variable that is not final, it can be changed.
Suppose that you are tracking something with a static integer that you are increasing
at some point and lets say that you start with a value of 100. Say a method on the
EJB is invoked on cluster 1 (we will have two clusters - 1 and 2) that causes value of
the static variable to be increased to 101. On the subsequent call to the same EJB
from the same client, a cluster 2 may be invoked to handle the request. A value of
the static variable in cluster 2 is still 100 because it was not increased yet and
therefore your application ceases to be consistent. Therefore, static non-final
variables are strongly discouraged in EJBs.
But if the variable is only required to show the same value within each JVM, it will
work just as well in a cluster as in a single-JVM server.
For example a cache is usually not required to have the same content in the different
JVMs of a clustered container.
Note that some care is needed even in a non-clustered server though, e.g. if a
synchronized method on the static would call an EJB you would mess upp the locking
in the container, risking a deadlock.
Check out the Java Developer Connection of Sun's Java web site.
There is a very interesting article, written by Beth Stearns: Enterprise JavaBeans 2.0
Container-Managed Persistence Example.
Said so, we have to add that an EJB Transaction is automatically rolled back only
when a SystemException (or a subtype of it) is thrown.
No and Yes
Author: Dattaraj Joshi (http://www.jguru.com/guru/viewbio.jsp?EID=585880), Jan
28, 2002
You can tell container to rollback the transaction, by using setRollBackOnly on
SessionContext/EJBContext object as per type of bean you are using.
If the container starts a transaction for a method, then the transaction must be
disposed of by the container before the method returns to the caller. If that method
throws any exception, checked or unchecked, then the transaction must be rolled
back.
If, however, the method inherits the transaction started by the container for the caller's
method, then the transaction will not be rolled back by the container when the called
method throws a checked exception. The caller must either catch the exception,
propagate it out, or throw an unchecked (i.e runtime) exception.
If the caller catches the exception, the caller should decide whether or not to invoke
setRollbackOnly(). If the caller popagates the exception out, then it is a checked
exception for the caller, in which case the same condition described for the called
method applies to the caller method. And, of course, if the caller throws an unchecked
exception, the transaction will get rolled back by the container.
Personally, I think that Richard is right, even after taking another quick look at the
specs and thinking a little bit about it.
Reading the specs, in fact, there is no clear indication that a Stateful Session Bean is
or is not pooled, while for the Stateless Session bean there is a specific paragraph
(7.9.4 "Adding instance to the pool") that discuss the sequence for adding/removing
an instance to/from the pool.
To this, I would add some thoughts. The lifecycle of a Stateful Session Bean is strictly
connected with "his" client. When the client decides to remove the bean, the bean
has no reason to exists, because it cannot be used from another client without being
(at least) reinitialized. Pooling it doesn't really make sense.
But, at the same time, I would accept that, maybe for gaining performance (or for
other reasons), some containers do pool Stateful Session Beans just to avoid the
overhead of recreating the object.
Hi,
When you execute a lookup to get the home interface of your bean, you normally use
the lookup() method of the javax.naming.Context interface.
This method will return you an Object that needs to be casted to the home interface
you've asked for. Unfortunately, this cannot be done using the normal/explicit casting
[MyHome myHome = (MyHome)returnedObject].
As you have already found out, the reason is connected to CORBA. Why?
For EJB, the communication between the server and the client is based on RMI (both
remote and local interfaces, in fact, do implements the java.rmi.Remote interface).
The underlying protocol that it is used for the communication is IIOP (I think 1.2),
that is part of CORBA standards. It is normally used to describe this communication
system using the Java RMI over IIOP.
IIOP has not been designed for Java, but for generic languages, and this means that
there are some limitations. Some languages, in fact, do not have the concept of
casting.
Java RMI-IIOP provides a mechanism to narrow the the Object you have received
from from your lookup, to the appropriate type. This is done through the
javax.rmi.PortableRemoteObject class and, more specifically, using the narrow()
method.
Just a note: when you are using the new EJB 2.0 Local Client API, you should be able
to do a direct/explicit cast from the looked up Object, to the interface you need.
RMI-IIOP
Author: Deepak Kalra (http://www.jguru.com/guru/viewbio.jsp?EID=1152019), Mar
10, 2004
Since Remote and Home interface implements java.rmi.Remote interface. ThE calls
to these interface will be remote calls and Most of the conatiner use IIOP as
communication network protocol and IIOP is CORBA standard. So we have to use
narrow method of PortableRemoteObject as Its define as the standard of IIOP.Normal
cast operator will not work as Application server use IIOP protocol
Re: RMI-IIOP
Author: Kacel Kacel (http://www.jguru.com/guru/viewbio.jsp?EID=1161993), Apr
11, 2004
The spec says to always narrow. If your ejb server (container) doesnt serv IIOP on
wire , then the usual cast should work BUT your client code wont be vendor
independent. Deploying, again, your ejb on an IIOP server, yhis time, will break
your clients (without narrow). Think narrow instructions as portable condition for
your bean, and think that your client is not always written in Java.
Re[2]: RMI-IIOP
Author: Suresh Subramanian
(http://www.jguru.com/guru/viewbio.jsp?EID=1226627), Feb 11, 2005
I have seen a single application using both normal java casting and narrowed
objects. In this application all servlets use normal casting to lookup ejbs and
ejbs use narrow to lookup other ejbs like client java command line applications.
Is there a specific reason to have this difference in approach? I want to know
the difference. Please explain Thanks Suresh
The EJB specification says that we cannot use Bean Managed Transaction in
Entity Beans. Why?
Location: http://www.jguru.com/faq/view.jsp?EID=734608
Created: Jan 25, 2002
Author: Matt Goodall (http://www.jguru.com/guru/viewbio.jsp?EID=450000)
Question originally posed by Prasad B
(http://www.jguru.com/guru/viewbio.jsp?EID=422641
The short, practical answer is... because it makes your entity beans useless as a
reusable component. Also, transaction management is best left to the application
server - that's what they're there for.
It's all about atomic operations on your data. If an operation updates more than one
entity then you want the whole thing to succeed or the whole thing to fail, nothing in
between. If you put commits in the entity beans then it's very difficult to rollback if
an error occurs at some point late in the operation.
Think of an account transfer which takes money from the first account and then pays
it into a second account. If the paying in part fails how do you put the money back in
the first account? What about if that then fails too?
The transaction should always "wrap" the entire operation. There are two obvious
ways of achieving this in an EJB environment:
Solution 2 is the "correct" way to do it. Either way, you can simply leave all
transaction code out of your entity beans.
2. Does the reference map to a specific instance of the stateless session bean or
to a pool of beans?
- Since stateless session beans are all "created equal" most app servers using
pooling to increase the performance. so the answer is that it maps to the pool
of stateless session beans of the type for which you have the handle.
For completing your answer, can you provide examples of what type of state
would you put into a Stateless Session Bean.
Thanks.
We're looking at any resource needed by the bean on many (unrelated) method
invocations. Particularly resources that would be costly to create every time
these methods are called.
Also -- while we're on the topic -- you might want to cache another SLSB's
EJB object, since we all agree it's worthwhile to keep these references hanging
around, rather than repeatedly looking them up.
The important thing is that this "state" does not track client progress through a
drawn out process, as it does in an SFSB. More formally, this state MUST not
impact on the idempotence of the bean's business logic.
thoughts?
Why does the Sun j2EE Reference Implementation invoke ejbLoad() and
ejbStore() twice in a row?
Whenever I find an EJB (either BMP or CMP), the container calls ejbLoad(),
then ejbStore(), then ejbLoad() again, then ejbStore() again. Is this the
standard Entity Bean lifecycle, or something specific to the RI?
Location: http://www.jguru.com/faq/view.jsp?EID=737225
Created: Jan 28, 2002
Author: Bozidar Dangubic (http://www.jguru.com/guru/viewbio.jsp?EID=433955)
Question originally posed by Wesley Janik
(http://www.jguru.com/guru/viewbio.jsp?EID=301189
Container has a contract with the developers to provide certain things such as
security, transactions, ... The way in which application server does this is up to the
implementation.
What you are seeing with multiple callbacks is not suprising. Most appllication
servers allow you to specify to a certain extent when the callbacks occur.
Orion Application Server offers isModified() method which is called before any
callback. If isModified() (which you implement) returns false, the callbacks will not be
invoked.
Without these kinds of optimization techniques, you will see many callbacks most of
which will not make sense to you.
ejbStore(), ejbLoad()
Author: GFSDG GSDSGG (http://www.jguru.com/guru/viewbio.jsp?EID=926600),
Jun 25, 2002
ejbStore(), ejbLoad() are the callback methods of EJBs.The calling of these methods
is Container Vendor Dependent.To maintain the cache consistency, these methods are
called twice. i.e., these methods are called before any other method of a bean instace
called, and these methods are called after any other method of a bean instace
called.This happens just because of cache consistency. Because there are many
number of bean instances concurrently running, to reflect the changes made my the
one bean instace to that of another, this happens.
Additional info:
This exception appear when an invocation failed because the caller has insufficient
privileges.
Try using J2EE runclient tool from sun, when a popup appear insert guest (or j2ee) in
username and password fields.
This is an example:
set APPCPATH=C:\MyProjects\MyTestsClient.jar
runclient -client MyTests.ear -name MyClient
2. These tools specify they could support EJB-BMP too, what does this mean? In
BMP, the developer writes all the JDBC code in the callback methods or
executes Stored procedures. Where does these tools fit in here?
- It means that they should be extensible. You may encounter a database
schema that is far to complex to be completely automated. You may have
many tables with special and awkward relationship that you can solve neither
with CMP nor with any commercial tools. Therefore, any tool should allow you
to extend what they generate to provide a more specific persistence using
stored procedures for instance or some other persistence rules that cannot be
described otherwise.
3. By using these tools, does it mean development of EJB's are not required at
all as they would be generated.
- Depends on the tool. You may still have to do some legwork to package and
deploy.
4. Does EJB-CMP latest version provide mapping a object to more than one
table? If so then why go for such tools??
- Again, this depends on your situation. Perhaps your development team likes
the GUI interface for development and does not want to hand-code the EJBs.
Or perhaps EJB-CMP is inadequate to solve all of the persistence issues you
may have. At times, you need to represent the beans that not only come from
many many tables in the database but have awkward relationships and things
like that. At times, you may need to execute a database-specific function to
accomplish certain things that you need during persistence. All these issues
cannot possibly be solved in CMP although Sun is trying really hard and
getting better with each new specification.
Note that here is no guarantee that the variable still has the value, so don't rely on
it.
Variables in stateless session beans should only contain state which can be used by
any client instance and not state which is specifically stored for a specific client
instance. The reason is because at any time between method calls on the bean, the
container may throw the bean out of the pool of available beans and destroy it. A
stateful bean should be used if this is required.
is it possible that if f1() modified some member variable of the bean it may
reflect in method f2().
Author: GFSDG GSDSGG (http://www.jguru.com/guru/viewbio.jsp?EID=926600),
Jun 25, 2002
yes,definetly the bean variables modification reflect in the f2(). Since they are bean
Variable, means their scope is for that bean. if the scope of the variable is to that of
f1() then there will not be any reflection in f2().
Re: is it possible that if f1() modified some member variable of the bean it may
reflect in method f2().
Author: Surender Kumar (http://www.jguru.com/guru/viewbio.jsp?EID=1133672),
Dec 12, 2003
Depends.If it's a stateless bean, then container may give you another instance from
the pool, which would be having another state.Change would be definitely there,
but you may/may not get them
Re[2]: is it possible that if f1() modified some member variable of the bean
it may reflect in method f2().
Author: aruna kalidindi
(http://www.jguru.com/guru/viewbio.jsp?EID=1143705), Feb 4, 2004
When will a container create new instance? Can we force it to create a new
instance if we wish to see the change.
Actually the answer is no, you cannot map more than one table to a single CMP
Entity Bean. CMP has been, in fact, designed to map a single table.
Said so, we can see that there could be some workaraounds.
The easiest one is to create a VIEW on the database side and have your CMP Entity
mapped to it.
This is a perfect fit for a read-only solution and, since views are not database
dependant, this is a portable solution.
Personally, I think that considering the way database work, it should be possible to
use not-read-only ejbs with views. The trick, probably, is to include all the fields
from all the tables (including the pk of all tables) and create a compound PK object
that maps to all the PKs of the tables.
I haven't tested that but if anybody is interested in "wasting" some time, it would be
nice...
What is the advantage of puttting an Entity Bean instance from the "Ready
State" to "Pooled state"?
Location: http://www.jguru.com/faq/view.jsp?EID=784545
Created: Mar 6, 2002 Modified: 2002-03-06 05:57:52.176
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
mandeep baruah (http://www.jguru.com/guru/viewbio.jsp?EID=781969
The idea of the "Pooled State" is to allow a container to maintain a pool of entity
beans that has been created, but has not been yet "synchronized" or assigned to an
EJBObject.
This mean that the instances do represent entity beans, but they can be used only
for serving Home methods (create or findBy), since those methods do not relay on
the specific values of the bean. All these instances are, in fact, exactly the same, so,
they do not have meaningful state.
If X clients find the same entity bean, will there be X caches in the
container?
Location: http://www.jguru.com/faq/view.jsp?EID=787017
Created: Mar 7, 2002
Author: Jon Thorarinsson (http://www.jguru.com/guru/viewbio.jsp?EID=776345)
Question originally posed by Jon Thorarinsson
(http://www.jguru.com/guru/viewbio.jsp?EID=776345
An Entity Bean represents data in a persistent storage like a database and it caches
the data.
If X clients connect (via a findXXX method to the same Entity EJB, will there be X
copies of the cache in the container or will the container serialize access to a single
Entity EJB?
When writing the entity bean business methods, the Bean Provider does not have to
worry about concurrent access from multiple transactions. The Bean Provider may
assume that the container will ensure appropriate synchronization for entity objects
that are accessed concurrently from multiple transactions.
[...]
You shouldn't.
What will happen depends on the implementation, but the call will most likely be
ignored.
Comments and alternative answers
Agreed.
Author: Kenneth Liu (http://www.jguru.com/guru/viewbio.jsp?EID=304008), Mar 7,
2002
You should leave system level management like garbage collection for the container
to deal with. After all, that's part of the benefit of using EJBs, you don't have to
manage resources yourself.
Emmanuel DURIN
http://www.durin.org
Except for the JMS part of EJBs, Enterprise Java beans have synchronous interfaces,
meaning that a response to a request on a bean must be sent before another request
is sent to the bean.
Entity EJB can be shared between clients but Session EJB cannot.
This implies that the Entity Beans could possibly benefit from being re-entrant,
meaning that requests to them will not be serialized.
Whether or not an application server will or can take advantage of the "re-entrant"
field in the deployment descriptor is vendor specific.
Without going into too much detail, an application server that relies on the database
for transaction management, f.ex., will likely not read the "re-entrant" field at all,
because it will create entity beans on demand, not share them and thus not serialize
access to them - making re-entrancy become a no-issue.
Even though session beans are synchronous, the fact that entity beans can be
shared between clients means that an entity bean can receive a request that
originated from a client B, while being buisy handling a request from a client A.
This means that the container has at least 3 ways of dealing with this:
• The container may store a single instance of the entity bean in the server's
memory (RAM) and serialize access to the bean.
• The container may store a single instance of the entity bean in the RAM and
take advantage of the fact that the bean's "re-entrant" field has been set to
true and thus it will not serialize access to the bean.
• The container may ensure that there exists at least one instance of the entity
bean per client that is actively sending methods to the bean. The entity bean
is "cloned" in a sense and all of those cloned instances are mapped to the
same record in the database. In this case the bean doens't have to be re-
entrant, because a new client requesting access to the bean will get a new
copy of the bean (although logically, all the clients appear to be connected to
the same bean). The container also doesn't have to serialize access to the
bean.
The Re-entrant field has nothing to do with concurrency and threading (though,
thread-safety is usually what re-entrant implies).
The re-entrant flag is there to allow loop-back calls on an entity bean. it is best
illustrated by an example: If there are 2 entity beans A, B, and there is a call made on
beanA which calls a method on beanB which in turn makes a call on beanA, you
effectively have a loopback.
Now, if re-entrant is not set, the container will throw an exception at this point. If re-
entrant is set, the container will permit the loopback call.
Now, the risk with marking an Entity Bean as "re-entrant" (and the reason why it is
not advised) is that the container cannot tell the difference between a loopback call
and a single client performing multi-threaded access. If a client has multiple threads
accessing EJB's, and if these threads access the same Entity Bean, then the calls on
the entity bean wont be serialised. (it is a bit more complicated than that - the
concurrency setting and the transaction context play a part also)
In general, loopback calls are not common. In general dont mark your bean as re-
entrant.
Why the Session beans should not be re-entrant and the same way entity
bean should be re-entrant?
Author: Gururaj Havanur (http://www.jguru.com/guru/viewbio.jsp?EID=138442),
Jan 17, 2003
Session beans are one thread of execution during one
method call from the client. They cannot be accessed
by more than one thread at the the same time. If they
do then it cannot be called a bean with a state, as
state can be easily modified by another bean.
The ejbCreate() methods is part of the bean's lifecycle, so, the compiler will not
return an error because there is no ejbCreate() method.
• the home interface of a Stateless Session Bean must have a single create()
method with no arguments, while the session bean class must contain
exactly one ejbCreate() method, also without arguments.
• Stateful Session Beans can have arguments (more than one create method)
stateful beans
Author: alok dashore (http://www.jguru.com/guru/viewbio.jsp?EID=797732), Mar 14,
2002
stateful beans can contain multiple ejbCreate() as long as they match with the home
interface definition
You need a reference to your EJBObject to startwith. For that Sun insists on putting a
method for creating that reference (create method in the home interface). The
EJBObject does matter here. Not the actual bean.
ejbCreate()
Author: Ramachandra Kondawar
(http://www.jguru.com/guru/viewbio.jsp?EID=868788), May 7, 2002
Container creates the bean instance in the following steps.
1.newInstance(). 2.setSessionContext() 3.ejbCreate().
Hence ejbCreate() is required for the beans.
I have the second edition of Richard Monson Haefels EJB book, and the
examples don't work on JBoss (apparently due to a server bug).
I remember seeing some time ago about a fixed set that changed the action
of the primary key class.
Does anyone have a link for the fixed examples?
Location: http://www.jguru.com/faq/view.jsp?EID=794338
Created: Mar 13, 2002
Author: Jonas Bergqvist (http://www.jguru.com/guru/viewbio.jsp?EID=81465)
Question originally posed by simon m
(http://www.jguru.com/guru/viewbio.jsp?EID=790083
rmh_jboss.zip
from: http://www.jboss.org/doco_files/
PS. I don't know how up-to-date those files are, since I haven't used them. Just
remembered I saw them there.
no file
Author: jignesh patel (http://www.jguru.com/guru/viewbio.jsp?EID=972821), Sep 3,
2002
there is no .zip file available on the given link
Re: no file
Author: Thomas Laresch (http://www.jguru.com/guru/viewbio.jsp?EID=958761),
Sep 26, 2002
Good luck!
Re[2]: no file
Author: Thomas Laresch
(http://www.jguru.com/guru/viewbio.jsp?EID=958761), Jun 14, 2004
The JBoss code and workbook are now done and have been moved to the
O'Reilly web site, co-located with the other EJB workbooks. The first two
links in my previous post are no longer valid - instead, go straight to
Enterprise JavaBeans, 3rd Edition: Exercise Workbooks and Examples.
The EJB 2 Spec (10.8.3 - Special case: Unknown primary key class) says that in
cases where the PrimaryKeys are generated automatically by the underlying
database, the bean provider must declare the findByPrimaryKey method to return
java.lang.Object and specify the Primary Key Class as java.lang.Object in the
Deployment Descriptor.
When defining the Primary Key for the Enterprise Bean, the Deployer using the
Container Provider's tools will typically add additional container-managed fields to
the concrete subclass of the entity bean class.
In this case, the Container must generate the Primary Key value when the entity
bean instance is created (and before ejbPostCreate is invoked on the instance.)
The create method takes all the values as arguments except the primary key.
Within the create method generate the new primary key.
1. select max(id) + 1 from table_name;
2. select sequence.next() from dual;
Use this value as the primary key.
Proceed as per the persistance type.
The second solution works well but not independant of the underlying database. I
think a sequence ist not standard sql nor is the virtual table dual.
THe table will have the numeric field to store the sequence id.
U can use a different table for each reqd sequence or a
sequence table with
BeanName, SequenceVal columns
Jani
What is clustering? What are the different algorithms used for clustering?
Location: http://www.jguru.com/faq/view.jsp?EID=813950
Created: Mar 27, 2002
Author: Jeroen Voogt (http://www.jguru.com/guru/viewbio.jsp?EID=423345)
Question originally posed by devseal devseal
(http://www.jguru.com/guru/viewbio.jsp?EID=71093
Clustering
Author: josyula srikanth (http://www.jguru.com/guru/viewbio.jsp?EID=888425), May
22, 2002
For at least two reasons you often want your web site to be served by more than one
web server: Fault tolerance Handling larger loads than one server can survive The act
of letting two individual servers work together to perform one task is often referred to
as clustering. Clustering is an essential piece to solving the needs for today's large
websites.
Re: Clustering
Author: Sandeep Shilawat
(http://www.jguru.com/guru/viewbio.jsp?EID=1017906), Jan 18, 2003
http://www.onjava.com/pub/a/onjava/2000/12/15/ejb_clustering.html
Re[2]: Clustering
Author: ravi vedala (http://www.jguru.com/guru/viewbio.jsp?EID=1143327),
Feb 4, 2004
Typically there are 3 algorithms followed by Weblogic : a. Round robin
algorithm. b. Random allocation algorithm. c. Weight-based algorith.
You can pass the HttpSession as parameter to an EJB method, only if all objects in
session are serializable.
This has to be consider as "passed-by-value", that means that it's read-only in the
EJB. If anything is altered from inside the EJB, it won't be reflected back to the
HttpSession of the Servlet Container.
The "pass-by-reference" can be used between EJBs Remote Interfaces, as they are
remote references.
Is there a way to get the original exception object from inside a nested or
wrapped Exception (for example an EJBException or RemoteException)?
Location: http://www.jguru.com/faq/view.jsp?EID=813959
Created: Mar 27, 2002
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Prasoon Choudhary (http://www.jguru.com/guru/viewbio.jsp?EID=264897
Hi,
Absolutely yes, but the way to do that depends on the Exception, since there are no
standards for that.
Some examples:
As usual, the best way to check how to get that piece of information is to read the
documentation of the specific Exception.
Problem inserting records with CLOB column with Oracle in EJB 2.0.
Location: http://www.jguru.com/faq/view.jsp?EID=826293
Created: Apr 5, 2002
Author: Gabriel Jufer (http://www.jguru.com/guru/viewbio.jsp?EID=822382)
Question originally posed by Amitava Ghosh
(http://www.jguru.com/guru/viewbio.jsp?EID=822343
Additional Info
EJB2.0 with an Oracle 8i, with a table containing a CLOB column.
In the entity bean of that table the get and set methods are defined to return and
accept java.lang.String resp. for that particular CLOB column.
That particular field is specified as OracleClob using the <dbms-column-type> tag of
the vendor specific descriptor (weblogic-cmp-rdbms-jar.xml).
But when trying to insert a record using create method, Oracle returns an error
saying: record containing LOB column is not locked.
1. Insert a row with all your data. All lobs (BLOB, CLOB) must have the value
empty_blob() or byte[]{1}
2. Lock the row and get it (we need a result set!) Select * from your_table for
update
3. Parse the result set to get the BLOB or CLOB Object oracle.jdbs.CLOB
myCLOB = (CLOB) myResultSet.getObject( /*column index*/ 1);>
4. With this object you can fill data into the db! get the CharArrayOutputStream,
fill your data, flash it and close it!!
5. Unlock the row with a SQL update.
Note: to update the row, you must call trim from the CLOB object before you fill in
the data! Make sure you have the right Oracle thin driver!
[It seems that all these steps would require a BMP bean, rather than a CMP. - AAG]
try
{
//switch off commits
conn.setAutoCommit(false);
ps = conn.prepareStatement(qry);
rset = ps.executeQuery();
if (rset.next())
{
//get the CLOB locators
displayClob = ((OracleResultSet)
rset).getCLOB(1);
searchClob = ((OracleResultSet)
rset).getCLOB(2);
if ((displayClob != null) && (displayText !=
null))
writeTextToCLOB(displayClob,
displayText);
//commit changes
conn.commit();
throw ex;
}
finally
{
//reinstate auto commit
if (!conn.getAutoCommit())
{
conn.rollback();
conn.setAutoCommit(true);
}
Writer w = null;
try
{
//get the writer from the clob (locator)
w = c.getCharacterOutputStream();
try
{
//try closing again
w.close();
}
catch (Exception ex2) {;}
}
}
If you're accessing or writing data back to CLOBs you may be required to use BMP
as opposed to CMP... Hope the above helps.
Thanks, Chris
How u map a composite Primary Key in CMP Entity Bean and how u handle
the same composite primary key in primary key class?
What is the usage of HashCode() and Equals() methods? They return only
one single primary key value?
Location: http://www.jguru.com/faq/view.jsp?EID=854006
Created: Apr 25, 2002 Modified: 2002-04-26 00:30:22.28
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
pavan kumar tammara (http://www.jguru.com/guru/viewbio.jsp?EID=780028
I think you are making some confusion on the purpose of the equals() and
hashCode(): they do not return a "single primary key value".
equals() returns a boolean that indicates whether another object is "equal" to this
one, while
hashCode() returns an int that represent the hashcode of an object, that is used for
the benefit of hashtables, like java.util.Hashtable.
anand narang also added that the reason why we have 2 methods is that hashcode
may not always return unique values. So the container also calls the equals method
to verify the uniqueness.
Regards
EntityBean:Primary Keys
Author: Manjula Gundluri (http://www.jguru.com/guru/viewbio.jsp?EID=738246),
Jun 4, 2002
HashCode:By supplying this method,our primarykey class can be stored in a
Hashtable.The container need this because inside the container it may use a Hashtable
or similar structure to store a list of all entity beans it has in memory,keyed on their
primary keys Equals:The container calls this to compare this primary key to others
when determining internally if two cached entity beans(which each have a primary
key) are representing the same database data
Composite Primary Key Usage in HashCode and equals method of Primary Key
class.
Author: Jiten Taluja (http://www.jguru.com/guru/viewbio.jsp?EID=1102000), Jul 17,
2003
The following has been taken from an EJB link in java.sun.com and hence is not my
proprietary:
In the following example, the XXXKey class implements a composite key for the
XXXEJB entity bean. The key is composed of two fields, keyModel and keyId,
whose names must match two of the persistent fields in the entity bean class.
public XXXKey() { };
return false;
}
return keyModel.concat(keyId).hashCode();
}
}
If my session bean with single method insert record into 2 entity beans,
how can know that the process is done in same transaction (the attributes
for these beans are Required)?
Location: http://www.jguru.com/faq/view.jsp?EID=854012
Created: Apr 25, 2002
Author: Jesper Lai Petersen (http://www.jguru.com/guru/viewbio.jsp?EID=817052)
Question originally posed by NG SWEE TIONG
(http://www.jguru.com/guru/viewbio.jsp?EID=816768
If yor method in the session bean is already running under a transaction the calls to
any other bean which have been deployed with trans-attribute 'Required' will be
executed within the same transaction context.
If your session bean is using bean-managed transactions, you can ensure that the
calls are handled in the same transaction by :
javax.transaction.UserTransaction tran= null;
try{
tran=ctx.getUserTransaction();
tran.begin();
myBeanHome1.create(....);
myBeanHome2.create(...);
tran.commit();
}catch(...){}
You may want to check if you're already running in a transaction by calling
tran.getStatus().
Comments and alternative answers
SessionSynchronization Interface
Author: Avi Abrami (http://www.jguru.com/guru/viewbio.jsp?EID=31214), Apr 27,
2002
If your session bean is a stateful session bean that uses container meneged
transactions, it can also implement the (optional) SessionSynchronization interface.
This interface consists of callback methods that are invoked at certain stages in a
transaction's life cycle. See section 7.5.3 of the EJB specification for more details.
Have a stateful session bean, that has method m1. Invoking the create
method of an entity bean , TWICE , with same parameters. Thus, this will
throw an DuplicateKeyException when called second time with same
parameters.
I want to know that when this exception is thrown , will the container
rollback the first insertion also ?
So in this case, when the above 2 stmts are executed, since 2nd one will
raise an exception will first one get rolled back - I Think it must bcos thats
what is txn mgt that either the whole group of stmt must be committed or
nothing ? But when i tried it doesnt !
The txn attr set for the method is required in the stateful session bean.
Regards, Dileep
With Stateful Session Bean the passivation process of a bean it does saves the
state of the bean in a secondary storage. The reason is because a stateful session
bean do maintain the state between calls.
In order to do that, the container has to save that state somewere. It uses its own
storage area, that could be memory or a cache or the disk, and it calls this
"secondary storage area", since the database is considered to be the first storage
area.
For entity beans ejbRemove() is only called if the user explicitly deletes the bean. I
think that is the reason why the engineers at SUN invented the unsetEntityContext()
for this kind of bean.
unsetEntityContext()
Author: Ramachandra Kondawar
(http://www.jguru.com/guru/viewbio.jsp?EID=868788), May 7, 2002
when ejbRemove() is called , the row represented by the entity bean is removed from
the database and the bean instance is returned to the instance pool.
Only when unsetEntityContext is invoked, the bean instance is destroyed.
Re: unsetEntityContext()
Author: Sheikh Azad (http://www.jguru.com/guru/viewbio.jsp?EID=967553), Jul
28, 2002
In Entity bean ejbRemove() does 2 things:(1)-unsetEntityContext(),(2)-Delete
Row from the DataBase.In Session Beans you are not worried about the Data Base
synchronisation so ejbRemove() alone can perform the work without side effects.
Sesssion
Author: Govindu Ravikumar (http://www.jguru.com/guru/viewbio.jsp?EID=93067),
Jan 20, 2003
Because, session beans called transcation beans, so does;t matter abt conext.
When a client refers to a Stateful Session object reference, all calls are directed to
the same object on the EJB container. The container does not require client identity
information or any cookie object to use the correct object.
This means that for a client to ensure that calls are directed to the same object on
the container, all it has to do is to use same reference for every call.
For example the following holds for all stateful session beans:
//Note that the second test would evaluate to true for stateless beans
Thus, if you're calling a Stateful Session Bean from a servlet, your servlet need to
keep the reference to the remote object in the HttpSession object between client
calls for you to be able to direct calls to the same object on the container.
Likewise, if you're calling from an application, you only obtain the reference to the
bean once and reuse the object throughout the application session.
The ejbSelectXXX() and findXXX are very similar methods, and the main
difference is that the first one is not exposed through the client interface, that means
that it cannot be called by a client directly, unless wrapped in a method.
There is another interesting difference related to the transaction context under wich
an ejbSelectXXX() or findXXX() method is executed.
The ejbSelectXXX() methods are executed in the transaction context of the method
that is actually using it, while the findXXX() execute according to their own attributes
(as specified by the bean provider).
Deciding when to use one and when the other, is really up to the developer. The
ejbSelectXXX() seems to be a little bit more powerful. Is important to remember that
it cannot be used by the client.
Is it possible to invoke multiple Session Beans from one Session Bean, using
Reflection?
Location: http://www.jguru.com/faq/view.jsp?EID=868735
Created: May 7, 2002
Author: Viral Shah (http://www.jguru.com/guru/viewbio.jsp?EID=278910) Question
originally posed by jyoti rath (http://www.jguru.com/guru/viewbio.jsp?EID=836863
You use reflection when you actually instantiate the objects or invoke the method.
In the EJB Scenario Beans invoke other Beans as clients. The client only looks up the
objects (not instantiating) and the operations are invoked on the stubs only.
// add this line, so you get an object of the home interface type
ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(ejbHome,
homeClass);
EJB-And-Reflection.YES.Why NOT?
Author: vimarsh vasavada (http://www.jguru.com/guru/viewbio.jsp?EID=972756),
Jan 21, 2004
As Mr. Chang has described one can use reflection with EJB also.Strictly disagree
with author Viral on this point. The same idea i would like to extend for
EJBObject...i.e. how a particluar client[servlet/pojo/session] can invoke a method on
another session bean without importing its Home/Remote?i.e. the client is linked to
EJB at compile time but at run-time.
In Plain Java world one needs to delegate call to instances that are in same JVM.
In EJB instances are distributed and ,as Viral said,the client does not have reference to
instances.But client does have reference to STUB.A stub by defination is proxy for
remote aka distributed instances.So if you can delegate calls to stub...youcan delegate
call to remote instances..
Then the question is how does one get access to Stub... ..the answer is with the help of
EJBMetaData..for example
//NORMAL-WITHOUT-REFLECTION
import MyHome;
import MyRemote;
import javax.ejb.*;
EJBMetaData md =
this.theHome.getEJBMetaData();
Class homeClass =
md.getHomeInterfaceClass();
EJBObject theRemote = (EJBObject)
this.invoke(homeClass,theHome,"create");
}
return r;
}
}
Now how does it work?back to question:"how does one get access to Stub...?"
What does LookUp return: Object -->EJBHome WHat is this EJBHome actually?--
>internally it refers to Stub returned by distributed server.
What does create return: Object -->EJBObject WHat is this EJBObject actually?--
>internally it refers to Stub returned by distributed server.
ok.so client is holding a stub only.and hence can invoke on it.stub any talks to
server..!!so it works.The crux is EJBMetaData which gives you access to ACTUAL
REMOTE CLASS...!!
Rarley one would use such reflection-techniques to right the business code..then
where it is usefull.. 1. IDE/Deployment Tools.. Just refere EJBMetaData javadoc.its
enlightning.
2. Scheduler products like Kronova...can invoke any method on any Session bean..as
per schedule...it allows GUI to define an EJBTask.visit
http://www.kronova.com/documentation.html
3. Business-Rule-Engine.
4. !!!
5. !!!
So it's possible.Not every application needs it.it has its domain.
With what transaction level are ejbCreate and ejbRemove method called for
Entity Beans?
Location: http://www.jguru.com/faq/view.jsp?EID=942752
Created: Jul 9, 2002
Author: G M (http://www.jguru.com/guru/viewbio.jsp?EID=802175) Question
originally posed by ani ani (http://www.jguru.com/guru/viewbio.jsp?EID=706510
Additional info:
What is the transaction level with which the ejbCreate and ejbRemove will be
executed? For business method I can have any attributes in my DD, as TX.Reqd,
TX.Reqd_New, TX.Support etc...
Does ejbCreate and ejbRemove methods have any default transaction levels?
If not can we set it as we do for other business methods?
<container-transaction>
<method>
<ejb-name>myBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
In the above, do all the methods including ejbCreate ejbRemove will have
transaction attribute of Required?
If not then with what transaction level these methods are executed (if they have any
default transaction level)?
ejbCreate() and ejbRemove are called using an unspecified transaction context. In
short, you can't set a tx attribute for these.
Refer sections 7.5.7 - "Transaction context of session bean methods" and 17.6.5 -
"Handling of methods that run with “an unspecified transaction context" of EJB 2.0
spec.
Comments and alternative answers
Regs, Fyodos
How can I retrive from inside my Bean (Stateless Session and Entity CMP) the user
name which I'm serving (the user name of user just logged in my web application)?
I need to know user name because I have a "logger Class" in my enterprise
application that automatically generates logs files for tracking transactions for each
user that logs in.
Inside an EJB you may retrieve the "Caller" name, that is the login id by invoking:
sessionContext.getCallerIdentity().getName()
where sessionContext is the instance of "SessionContext" (setSessionContext)
passed to the Session Bean, or the instance of "EntityContext" (setEntityContext)
passed to the Entity Bean.
There are no specific restriction for using Java primitive types in the <method-
params> tag in the Deployment descriptor.
The EJB 2.0 specifications, describe the <method-params> by saying: "[...] are the
fully-qualified Java types of the method’s input parameters [...]".
In addition there are few examples where the types used are both classes (i.e.
java.lang.String) or simple primitives:
<method-params>
<method-param>char</method-param>
<method-param>int</method-param>
[...]
</method-params>
Is it possible to integrate TIBCO system with EJB or, generally, with J2EE?
Is this done through the JMS-TIBCO connector? Is it possible to deploy EJB
directly on TIBCO?
Location: http://www.jguru.com/faq/view.jsp?EID=997068
Created: Sep 10, 2002 Modified: 2002-09-11 04:34:57.777
Author: Jon Dart (http://www.jguru.com/guru/viewbio.jsp?EID=996845) Question
originally posed by Francesco Marchioni
(http://www.jguru.com/guru/viewbio.jsp?EID=59707
TIBCO has a product called TIBCO Adapter for EJB that facilitates communication
between EJBs and services that use TIBCO's Rendezvous messaging system.
TIBCO also has a full-featured JMS implementation that can gateway JMS messsages
into and out of TIBCO Rendezvous.
You cannot deploy EJB directly on TIBCO, since TIBCO isn't a deployment platform
for EJBs.
anthony warden has also added the link to the TIBCO Enterprise for JMS, that
provides a standardized interface for enabling communications between J2EE-
compliant applications, Enterprise Java Beans, and application servers.
The integration with JBoss and weblogic is documented in the help files.
How do I use EJB with SUN JDMK package? Because JDMK uses sockets, is that
mean I can't use in my bean? What is the exact reason? What are all the 3rd party
packages/API I can use with EJB ? How the restrictions comes?
The reason that opening sockets is forbidden with EJB is that e.g. your EJB could run
in a clustered environment and multiple call to the same EJB might be executed on
different hosts which could lead to problems.
Therefore it's the application container's job to manage e.g. JDBC Connections which
are guaranteed to work in a clustered environment.
Additional info: What restrictions are imposed on an EJB? That is, what can't an EJB
do?.
Home interface is basically ment to define the methods that allow a remote client to
create, find, and remove EJB objects, as well as home business methods that are not
specific to a bean instance.
Where as EJBMetaData interface is intended for development tools used for building
applications that use deployed enterprise Beans, and for clients using a scripting
language to access the enterprise Bean, and that is why its has methods like
getHomeInterfaceClass()
getRemoteInterfaceClass()
isSession()
...etc
that provide info regarding there classes and types etc.
Hence providing meta-data info is not in scope of home interface and thus it does not
have any methods like getMetadataInfo().
Reasonable answer
Author: Arun Thomas (http://www.jguru.com/guru/viewbio.jsp?EID=1084056), May
12, 2003
I'm quite confused by this response to the question regarding why EJBMetaData is
not accessible from the EJBLocalHome. As far as I can see, the response gives a
reason why home interfaces in general do not provide any metadata information.
While the argument may have merit, it certainly is not the pattern or the logic
followed by the spec writers, as the remote HOME interface does have an accessor
for the EJBMetaData.
Re: Reasonable answer
Author: Tomcy John (http://www.jguru.com/guru/viewbio.jsp?EID=1078595), Jun
10, 2004
getEJBMetaData() is used to get a sort of interrogation into the bean as a
whole...in the case of local bean since it exists in the same heap in a JVM....we
can use java reflection to get the various details about the bean...thats the reason
we dont have getEJBMetaData() method in the case of local beans.....
Hope it helps...
Tomcy John
Hi,
Well, the quick answer to your second question is "Yes". You can use CMP and BMP
beans in the same application... obviously, a bean can be BMP or CMP, not both at
the same time (they are mutually exclusive).
The answer to your first question cannot be easy at all. There are so many players in
the game that is almost impossible provides a complete and always-valid answer.
As somebody else has said in some threads or other FAQs (i.e.: Should I use CMP or
BMP for an application with complex data manipulation & relations>) there is a
common approach that is normally used and considered a good one.
You should start developing CMP beans, unless you require some kind of special
bean, like multi-tables, that cannot be completely realized with a single bean.
Then, when you realize that you need something more or that you would prefer
handling the persistence (performanbce issue are the most common reason), you
can change the bean from a CMP to a BMP.
Take also a look to this faq: Is there a difference between container managed and
bean managed persistence in terms of performance?
Additional info:
I am using Oracle 9ias server. I have given max-connections to 50 in data-
sources.xml file. And the class i am using is
"oracle.jdbc.pool.OracleConnectionCacheImpl". I have also tried with
OracleConnectionPoolDataSource class in data-sources.xml. But i feel that
connection pool is not utilised, because in the middle of the retrieval, the server
hangs as there will no be connections left for opening...
In entity beans, I have created connections in setEntityContext and releasing them in
unsetEntityContext...
Do not get the connection in the setEntityContext. Get the connection only when you
need it.
If you get the connection in setEntityContext with the pool of 50 connections and you
retrieve 50 different entity beans each bean will hang on to the connection and you
will hang.
So, get the connection when you need it and release the connection as soon as you
have no need for it any longer.
There is no reason to get the connection in setEntityContext.
Comments and alternative answers
database connection
Author: P Manchanda (http://www.jguru.com/guru/viewbio.jsp?EID=344357), Feb
28, 2003
you should get the database connection in the ejbActivate() method and release it in
the ejbPassivate() method.
Hope this makes sense.
What is the best way to generate a universally unique object ID? Do I need
to use an external resource like a file or database, or can I do it all in
memory?
Location: http://www.jguru.com/faq/view.jsp?EID=1030397
Created: Nov 25, 2002 Modified: 2003-02-28 08:01:34.258
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Andy Brown (http://www.jguru.com/guru/viewbio.jsp?EID=1027054
[I need to generate unique id's that will be used for node 'ID' attribute values within
XML documents. This id must be unique system-wide. The generator must be
available to a number of servlets that add various node structures to my XML docs as
a service. What is the best way to tackle this? The 'possible' ways I can see:
• Keep the maximum ID value in a flat-file where the service would read it upon
start-up and increment it. Upon shutdown or failure, it would write the latest
max id to the file.
• Calculate the max id by searching the XML itself. This will be tougher since
XML requires an alpha-numeric value (not strictly numeric).
• Use a database (MySQL) with a two-field table where one field is the
incremental counter.
I just have this feeling that none of the above are the most efficient ways of doing
this.
Regards, -Andy]
There is an additional way to do that that doesn't rely on an external file (or
database) like the one you have presentred. If has been presented in the EJB Design
Patterns book, written by Floyd Marinescu, and available in a pdf format for free from
the given link.
The suggested solution is based on the UUID for EJB pattern, that comes out from
this question:
How can universally unique primary keys can be generated in menory without
requiring a database or a singleton?
Without enetring in the specifics (you can fully check out the pattern by reading the
appropriate chapter), the solution is to generate a 32 digit key, encoded in
hexadecimal composed as follows:
1: Unique down to the millisecond. Digits 1-8 are are the hex encoded lower 32 bits
of the System.currentTimeMillis() call.
2: Unique across a cluster. Digits 9-16 are the encoded representation of the 32 bit
integer of the underlying IP address.
3: Unique down to the object in a JVM. Digits 17-24 are the hex representation of
the call to System.identityHashCode(), which is guaranteed to return distinct
integers for distinct objects within a JVM.
• I need to generate a GUID and have seen suggestions about using an RMI
server but nothing about how to actually generate the GUID itself.
• What is the best way to provide a unique identifier as a primary key that will
work in a database independent manner? I'm looking for functionality similar
to Oracle's proprietary MY_SEQ.NEXTVAL.
• How do I automatically generate primary keys?
• and the original thread: What is the best way to implement a system-wide
object ID generator?
- Alex Chaffee]
Comments and alternative answers
Random class
Author: P Manchanda (http://www.jguru.com/guru/viewbio.jsp?EID=344357), Feb
28, 2003
Hi,
Try using the java.util.Random class to generate random numbers that can be used as
IDs.
Re: Random class
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727), Feb 28, 2003
Hi,
java.util.Random will generate random numbers, not unique numbers.
(BTW,you don't need to use rmi nor know anything about rmi to use these classes)
-Nathan
Making it Faster
Author: Kimbo Mundy (http://www.jguru.com/guru/viewbio.jsp?EID=1120338), Oct
8, 2003
It seems to me that you could speed up the algorithm above by modifying step #4.
Instead of computing the random number every time, just compute it the first time,
and then increment it after that. 2 different JVMs should still just have a 1 in 4 billion
chance of overlap.
Millisecond overlap
Author: Thomas Paré (http://www.jguru.com/guru/viewbio.jsp?EID=1238395), Apr
14, 2005
Thanks for the very interesting pointer on 'Ejb design patterns'. I've read the
implementation details and found something troublesome.
In step 1 : "Unique down to the millisecond. Digits 1-8 are are the hex encoded lower
32 bits of the System.currentTimeMillis() call". Only the lower 32 bits of time are
considered, which makes the uniqueness of that part only valuable for a period of 50
days. Looks like a serious issue.
Congratulations! You've just described the infamous n+1 entity bean problem. Let
me explain what's happening.
First, your application container is querying the database and retrieving the keys to
all of the rows that match the WHERE clause. Second, for each matching row, it is
taking an entity bean instance from the pool and assigning the key to it. When you
call the getXXX() on the entity bean, the entity bean is fetching all the field values
from the row it represents. So if your query found 15 rows, the "n" value is 15 and
represents the getXXX() methods you will call on your 15 entity beans. The +1 is the
initial query on the database. You will have a total of 16 database dips.
By now, you're probably disgusted with entity beans. However, consider this: entity
beans cut down the amount of code dramatically. You avoid having to write JDBC
(except in special cases) and reduce the amount of bugs you generate. I'm not trying
to over dramatize this but our team just spent days fixing tons of JDBC code which
had no close statements on result sets and JDBC connections. This caused our
application to crash.
Some application containers have something called field groups which allow you to
group fields together. If, for example, you have a field named XXX in the same group
as the key field, calling getXXX() on the entity bean will avoid a second database dip
because XXX will have already been read in with the initial query.
The EJB Entity Bean specification is likely to doom any truely robust application for
the following reasons:
If this is impossible, use a write-through cache only for those queries that need it and
work to seperate read-only from read-write data.
2.) An object tree or graph or map can take on any data model the programmer can
imagine. Not all of these will map well to a relational model. My writing the JDBC
explicitly, you must consider the painful aspects of object-to-relational modeling.
Painful, yes, but not very hard. You will have much better performance.
3.) Even for those app servers with the best mechanism for marked "dirty" objects,
high performance systems will change the state of an object or entity quickly and
often. Unless these are implemented as a two-phase committ, the state of an object's
"dirtiness" will have some (slight) delay with respect to the database itself. If it is
implemented as a two-phase committ this get very expensive very fast. If your
application is displaying the family photo album, fine. If you are dealing with money
over a farm of multiple EJB servers, you will not be able to maintain transactional
consistancy. Not appropriate for business.
4.) The Entity Bean 2.0 specification with dynamic loading of foreign keys and
cascading updates / deletes is a nightmere. It is a perfect example of why people try
(the same approach)to solving object persistance once and for all and almost always
fail.
Just an opinion,
Jonathan
The alternative would be to package the JDBC driver that is required to connect to
the database inside your jar file along with the Session EJB and then to load the
driver and get a connection from the DriverManager.
This is really not a way to go. There is nothing in the spec that will prohibit this kind
of programming but it is really a horrible way of doing things.
In addition, it is much harder than it would be to simply create a resource reference
to your data source and get a connection that way.
ejbCreate() is called before the state of the bean is written to the persistence
storage (database). After this method is completed, a new record (based on the
persistence fields) is created and written. If the Entity EJB is BMP, then this method
must contain the code for writing the new record to the persistence storage.
If you are developing an EJB following 2.0 specs, you can have overloading methods
in the form of ejbCreateXXX(). This will improve the development so you can have
different behaviour for creating a bean, if the parameters differs. The only
requirement is that for each ejbCreateXXX() you need to have corrisponding
createXXX() methods in the home or local interface.
ejbPostCreate() is called after the bean has been written to the database and the
bean data has been assigned to an EJB object, so when the bean is available.
In an CMP Entity EJB, this method is normally used to manage the beans' container-
managed relationship fields.
ejbCreate(), ejbPostCreate()
Author: Sheikh Azad (http://www.jguru.com/guru/viewbio.jsp?EID=967553), Mar 9,
2003
In short:Primary Key is available only after execution of ejbPostCreate(),not after the
ejbCreate(). :)
"ejbCreate() is called before the state of the bean is written to the persistence storage
(database). After this method is completed, a new record (based on the persistence
fields) is created and written."
Life cycle of entity bean works this way. When the client calls the craete method on
entity home interface, Container calls the ejbCreate() and ejbPostCreate() method and
that time Container associate the bean instance with Entity Object and moved the
bean instance from Pooled State to Ready State. So That time no record is inserted in
the database Only bean instance is associated with Entity Object. After this Container
calls the ejbStore method to synchronize the bean instance with database so It writes
the bean instance to database. This way the container calls the method in this
sequence
ejbCreate()
ejbPostCreate()
ejbStore()
ejbPostCreate
Author: Manoj Dhanji (http://www.jguru.com/guru/viewbio.jsp?EID=1153157), Mar
10, 2004
"ejbPostCreate() is called after the bean has been written to the database and the
bean data has been assigned to an EJB object, so when the bean is available."
The explanation above is really good.
I would like to extend it a bit.
ejbPostCreate() is called after the bean has been written to the database (record
inserted) and the bean data has been assigned to the bean's proxy EJBObject.
You have the primary key available after ejbCreate and a reference to the bean's
proxy.
It is between ejbCreate and ejbPostCreate that the bean's proxy EJBObject is
created.
Re: ejbPostCreate
Author: Sachin Popli (http://www.jguru.com/guru/viewbio.jsp?EID=1172707),
Jun 6, 2004
My doubt is, if we are doing ejbCreate() then that means we are inserting new set
of data in DB. Then where does question of bringing bean instance in synch with
DB arises when the data does not exist in DB at first instance. So why should
ejbStore() be called for that. Shouldn't it be ejbCreate(), ejbPostCreate() first time.
Later on in life cycle of entity bean to bring in memory object state in synch with
db state ejbStore can be called by container. (I am new to EJB concepts,so please
excuse my ignorance about the subject)-Thanks
Is there some kind of Design pattern which would make it possible to use
the Same code base in EJB and non EJB context?
Location: http://www.jguru.com/faq/view.jsp?EID=1050393
Created: Jan 26, 2003
Author: Jan Matèrne (http://www.jguru.com/guru/viewbio.jsp?EID=567992)
Question originally posed by Sandeep Shilawat
(http://www.jguru.com/guru/viewbio.jsp?EID=1017906
class PieceOfCode {
public Object myMethod() {}
}
ejb
Author: madhavi latha (http://www.jguru.com/guru/viewbio.jsp?EID=1194493), Aug
20, 2004
what happened when the data is updated if the object is in the passivated state? means
data is commited or rollbacked?
What is the default time for transaction manager? And how to set maximum
time(timeout) for transaction?.
Location: http://www.jguru.com/faq/view.jsp?EID=1050395
Created: Jan 26, 2003
Author: Nick Maiorano (http://www.jguru.com/guru/viewbio.jsp?EID=780589)
Question originally posed by venkata devi prasad kankanalapalli
(http://www.jguru.com/guru/viewbio.jsp?EID=1034636
The default time depends on your app server. It is usually around 30 seconds. If you
are using bean-managed transactions, you can set it like this:
If you are using container-managed transactions, this value is set in a app server
specific way. Check your app server's deployment descriptor DTD.
The Singleton pattern is not permitted by the J2EE spec, so How can I cache
EJB home interfaces across EJBs in my application and avoid having each
EJB get its own home interfaces?
Location: http://www.jguru.com/faq/view.jsp?EID=1051835
Created: Jan 30, 2003
Author: Nick Maiorano (http://www.jguru.com/guru/viewbio.jsp?EID=780589)
Question originally posed by Eric Snyder
(http://www.jguru.com/guru/viewbio.jsp?EID=806379
This is one of those grey areas in the J2EE spec. Yes, it's true that theoretically,
static objects (hence, singleton patterns) are not permitted. This is because you
never know how many class loaders there are in your ejb container - unless you
know the inner working of your container. Therefore, the singleton object will be
unique in the class loader only. If there are multiple class loaders, your singleton
object will exist more than once (1 instance per class loader). However, if you are
ready to accept the fact that your ejb stub may be cached multiple times (as much
as once in every class loader), the singleton pattern will still work.
Ithe ejb container's responsibility to cache ejb stubs. However, some implementation
of jndi are very slow to lookup. Repeatedly performing jndi lookups can actually slow
down your app considerably. In fact, I have written that exact singleton class you are
contemplating and this has increased performance.
Anyway, those are the facts. It's up to you to decide if you want to remain "J2EE
pure" or make a deal with the devil. ;-)
[Alex: Also check the comments on this FAQ: Can a bean act as a singleton to
provide logging and other services?]
Are there any tools for porting EJB Applications from one Application Server
to another?
Location: http://www.jguru.com/faq/view.jsp?EID=1051912
Created: Jan 30, 2003
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
GANESHAN KALEMBETH (http://www.jguru.com/guru/viewbio.jsp?EID=1005460
In theory, you should not need any tools for that task.
If you have developed a fully compliant J2EE application, you will be able to deploy it
on any Application Server that follows Sun J2EE Specifications. That is one of the
biggest advantages of using standards and following the spceifications.
Maybe, then, you will probably have to spend some time in tuning and fixing the
configuration of the specific server.
Are there any tools for porting EJB Applications from one Application Server to
another?
Author: Nagarjun Chevula (http://www.jguru.com/guru/viewbio.jsp?EID=1059450),
Feb 22, 2003
Usually the Application Server vendor should provide such tools if they are needed.
EJB Applications are supposed to be portable across all application servers. This is
based on the fact that you did not use any vendor specific classes while building your
EJB application. If you did then your code becomes not-portable. You may have to do
some configuration changes to the Datasources/JDBC drivers/JMS providers/
Security Roles etc to match what is in the new environment. Performance tuning is
something that you have to do always while porting code to other application servers,
Re: Are there any tools for porting EJB Applications from one Application
Server to another?
Author: Jeff Luszcz (http://www.jguru.com/guru/viewbio.jsp?EID=1091881), Jun
6, 2003
You should check out the Cacheon Migrator <http://www.cacheon.com> It's a rule
based Java to Java transformation tool that comes with rule sets for App server to
App server migration. Jeff
Are there any tools for porting EJB Applications from one Application Server to
another?
Author: Paulo Noreña (http://www.jguru.com/guru/viewbio.jsp?EID=1113812), Sep
8, 2003
And what about the entity-relationship mapping descriptors in CMP? They are vendor
specific then CMP is not a standard?
How can I get the references of all active objects of a particular EJB class?
Location: http://www.jguru.com/faq/view.jsp?EID=1059079
Created: Feb 21, 2003
Author: Vinay Salehithal (http://www.jguru.com/guru/viewbio.jsp?EID=1039322)
Question originally posed by Angel Bata
(http://www.jguru.com/guru/viewbio.jsp?EID=480237
In any case, I dont think such kind of functionality is provided ready made by any
application server. Some may provide this as a additional feature in an application
server monitoring console.
At best, if an application server has any JMX hooks to do such kind of stuff, you may
be able to utilize that.
What are the differences of Container Managed Persitence 1.1 and 2.0
Location: http://www.jguru.com/faq/view.jsp?EID=1059871
Created: Feb 24, 2003
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
RaviKiran Sristy (http://www.jguru.com/guru/viewbio.jsp?EID=1031174
The main difference is that in EJB 2.0, the persistence manager is responsible for
mapping the entity bean to the database based on the newly introduced abstract
persistence schema. In other words, you can say that the persistence manager
handles persistence of your CMP entity beans at runtime.
Plus, thanks to the EJB Query Language, the persistence manager is also responsible
for implementing and executing find methods based on it.
In the previous CMP EJB 1.1, is the developer that must declare the bean class'
persistent fields as either Java primitive or serializable types, providing getters and
setters for all of them.
In CMP EJB 2.0, its persistent fields are not defined directly in the bean class, thanks
to the new abstract persistent schema.
This schema has been developed to allow the bean provider to declare the persistent
fields (and bean relationships, eventually) indirectly.
CMTs and BMTs are 2 different animals. Mixing them in the same bean would require
the application container to potentially start a transaction at the beginning of the
method while the BMT bean itself would start another. Things could get quickly get
out of hand.
Even mixing CMT beans and BMT beans in the same process flow can be tricky. For
example, a BMT bean cannot participate in transactions started by a CMT bean
(although the opposite is allowed).
The real is question is why would you need to do this? Most of the time, you will use
CMTs. BMTs are used in special circumstances where you need fine-grained
transaction control.
Session facade is one design pattern that is often used while developing enterprise
applications.
It is implemented as a higher level component (i.e.: Session EJB), and it contains all
the iteractions between low level components (i.e.: Entity EJB). It then provides a
single interface for the functionality of an application or part of it, and it decouples
lower level components simplifying the design.
Think of a bank situation, where you have someone that would like to transfer
money from one account to another.
In this type of scenario, the client has to check that the user is authorized, get the
status of the two accounts, check that there are enough money on the first one, and
then call the transfer. The entire transfer has to be done in a single transaction
otherwise is something goes south, the situation has to be restored.
As you can see, multiple server-side objects need to be accessed and possibly
modified. Multiple fine-grained invocations of Entity (or even Session) Beans add the
overhead of network calls, even multiple transaction. In other words, the risk is to
have a solution that has a high network overhead, high coupling, poor reusability and
mantainability.
The best solution is then to wrap all the calls inside a Session Bean, so the clients will
have a single point to access (that is the session bean) that will take care of handling
all the rest.
Obviously you need to be very careful when writing Session Facades, to avoid the
abusing of it (often called "God-Bean").
What are the differences between EJB 1.1 and EJB 2.0?
Location: http://www.jguru.com/faq/view.jsp?EID=1061674
Created: Feb 28, 2003
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
venugopal k (http://www.jguru.com/guru/viewbio.jsp?EID=1060133
There are many differences, all of them should give different type of advantages
among the previous 1.1 version.
How to register a connection to a database with a JNDI name and use the
JNDI name specified?
Location: http://www.jguru.com/faq/view.jsp?EID=1061802
Created: Feb 28, 2003
Author: Nick Maiorano (http://www.jguru.com/guru/viewbio.jsp?EID=780589)
Question originally posed by Arun Sista
(http://www.jguru.com/guru/viewbio.jsp?EID=1060253
First, let's say that the way in which you do this will vary depending on whether you
are using an Entity Bean or a Session Bean.
The way in which you access your database from an Application Server is vendor
specific.
Usually, you define a connection by specifying a JDBCdriver in your Application
Server's config file. You supply the driver along with a user/password to your
database (although this too is database and driver specific). Once you've done this,
your Application Server will automatically register the connection in JNDI and
possibly create a pool of connections.
With Entity Beans, you can define which connection you wish to use inside the
deployment descriptor. With Session Beans using JDBC, you lookup the name of the
connection you've configured with JNDI.
Since much of this is really Application Server dependant, I recommend you look at
sample code from your Application Server vendor.
Vendors, in fact, usually include basic examples for stuff like this.
Can JavaMail be used from a Message Driven Bean? The EJB specifictation
requires that the bean implementation must be single-threaded. Isn't
JavaMail multi-threaded? If so, can it be used from a Message Driver Bean?
Location: http://www.jguru.com/faq/view.jsp?EID=1063436
Created: Mar 5, 2003
Author: Jens Dibbern (http://www.jguru.com/guru/viewbio.jsp?EID=9896) Question
originally posed by Shiv Kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=844764
You should configure a JavaMail resource for your EJB container and access it by
JNDI. It works just like JavaMail in an application without setting up the connection
first. You just get it from the JNDI tree. This should work for your MDB just like it
workes for my stateless session bean
Comments and alternative answers
When a client invokes a method on the stub, the container will look into the bean
pool and see if there are any available bean instances that can satisfy that request.
It will create more instances if all instances are currently being used by other clients.
You can control the size of the pool thru the deployment descriptor.
EJb objects?
Author: saravanan Balasundaram
(http://www.jguru.com/guru/viewbio.jsp?EID=1084714), May 14, 2003
Hey there is a strong relation ship between EJb objects and ur bean instance.Ofcourse
both couple together to service a client request. One more important thing is that
EJBobject is a vendor tool generated one.[By the container provider.]So its not
mandatory that a EJB object should be created at the same time a bean instance is
created.During passivation and activation a decoupling occurs when the Ejb object
decouples from a bean instance.
Value objects, on the other hand, represent an abstract design pattern used in
conjuction with entity beans, jdbc, and possibly even JDO to overcome commonly
found isolation and transactional problems in enterprise apps. Value objects alone do
not allow you to persist objects - they are simple data holders used to transfer data
from the database to the client and back to the database.
Side note: I know that many books out there still refer to these data holders as
value objects but the correct term is DTO: data transfer objects. Value objects refer
to objects that hold a value. A good example of this java.lang.Integer object which
holds an int.
why we use home interface in EJB. In RMI we dont have any concept like
home interface.why we particularly go for Home Interface Both RMI and EJB
are distributed applications. In EJB we use Home interface which is not
avaliable in RMI. There must be several reasons for using Home Interface of
EJB. can any one give reason for this?
Location: http://www.jguru.com/faq/view.jsp?EID=1081979
Created: May 5, 2003
Author: Nick Maiorano (http://www.jguru.com/guru/viewbio.jsp?EID=780589)
Question originally posed by vishnu rajan t k
(http://www.jguru.com/guru/viewbio.jsp?EID=1075172
By posing this question, you seem to be comparing RMI and EJB as if they were the
same type of technology and they are definately not. RMI is a lower level technology
that allows java objects to be distributed across multiple JVMs. Essentially, RMI
abstracts sockets and inter-JVM communications.
EJB, on the other hand, is a technology built atop of RMI but does so much more
than allow java objects to be distributed. It is a framework that allows you to build
enterprise applications by (among other things) abstracting transactions, database
access and concurent processing.
Having said this, the answer to your question is the following. The home interface is
EJB's way of creating an object. Home interfaces act as factories to create session
beans and entity beans. These factories are provided by the application container
and take care of many low level details. Since RMI is a lower level technology, it does
not offer the home interface. You would have to create it yourself.
more EJB/RMI
Author: Laurent Mihalkovic (http://www.jguru.com/guru/viewbio.jsp?EID=407112),
Jun 8, 2003
couple things...
Although EJB originally started as a technology for remoting, and therefore made use
of RMI for containers implementations, the technology has now outgrown its original
intent. The introduction of local interfaces geve EJBs a boost for situations where
remoting was not necessary, leading to faster intra-VM calls.
In view of this departure form the remoting nature of EJBs, I do believe that the real
defining feature of EJBs is the life cycle management provided by the application
server. In recent years, the JVM itself has received many improvements in the area of
memory management and garbage collection. Sun and IBM have both studied
carefully the usage patterns on the servers and built agressive optimization strategies.
Marc Fleury (the vibrant voice behind JBoss) recently published an interesting white
paper about the optimizations built into modern EJB containers, as well as an
interesting view (I happen to share it) that with the flexibility introduced by CMP 2.0,
EJB containers are rapidly becoming elaborate caches. These caches keep the raw
database data in a format directly usable by Java code, taking care of synchronizing
memory and database when necessary.
The paper is really interesting, and it gived an interesting glimpse at what modern
technilogy based on dynamic class instrumentation has in store for the future of EJB
containers.
cheers,
laurent
In RMI we do not have any concept of conatiner services and in EJB, container use
the EJB Object to provide all the services like transacion, security etc. So this way we
use Home interface in EJB, in order to get the reference of EJB object and container
services
EJB is object invocation. i.e an instance of an object will be created and assinged to
the client through which several business methods will be invoked.
From a logical point of view, a Servlet/JSP session is similar to an EJB session. Using
a session, in fact, a client can connect to a server and maintain his state.
But, is important to understand, that the session is maintained in different ways and,
in theory, for different scopes.
A session in EJB is maintained using the SessionBeans. You design beans that can
contain business logic, and that can be used by the clients. You have two different
session beans: Stateful and Stateless. The first one is somehow connected with a
single client. It maintains the state for that client, can be used only by that client and
when the client "dies" then the session bean is "lost".
A Stateless Session Bean doesn't maintain any state and there is no guarantee that
the same client will use the same stateless bean, even for two calls one after the
other. The lifecycle of a Stateless Session EJB is slightly different from the one of a
Stateful Session EJB. Is EJB Container's responsability to take care of knowing
exactly how to track each session and redirect the request from a client to the
correct instance of a Session Bean. The way this is done is vendor dependant, and is
part of the contract.
What if ?
Author: rachna chadha (http://www.jguru.com/guru/viewbio.jsp?EID=1077370), Oct
8, 2003
I have seen that many times JSP session is still there but session bean's session expires
? Is there any way to manage this problem ?
Re: What if ?
Author: Bill Schnellinger
(http://www.jguru.com/guru/viewbio.jsp?EID=1120424), Oct 8, 2003
you have to match the <session-timeout> in your web.xml with the statefull
session timeout parameter in your application servers xml file.
For example, weblogic-ejb-jar.xml has a
<stateful-session-descriptor>
<stateful-session-cache>
<max-beans-in-cache>100</max-beans-in-cache>
<idle-timeout-seconds>0</idle-timeout-seconds>
</stateful-session-cache>
</stateful-session-descriptor>
entry.
http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd
An Alternative Description
Author: vimarsh vasavada (http://www.jguru.com/guru/viewbio.jsp?EID=972756),
Oct 8, 2003
The earlier explaination has cleared my clouds.Representing
in different way .
Container View Point :
1. Servlet Container
A HttpServlet.service() represents a client thread.
A logical session is maintaied per such different client
threads.The container manages the association rather
then the Servlet.Hence Servlet from the pool of servlet instances are reusable for
different threads and can be
swaped in between client threads.This is why Servlet
Instance variable are not thread-safe.
Designers Perspective :
1. Servlet
Helps the session management but the servlet developer
needs to invoke SessionManagement API to read/write.
Right candidate for UserInfo,AuthInfo etc.
2.SFB
A well designed component for the stateful processes.
An object state is automaticaly managed by container.Thread-
saftey is guranteed.Developer need not to bother.Right
candidate for Order/Shopping Process.
which is the best way to pass the value from one screen to another either
hiddenor session
Author: lekoria martin (http://www.jguru.com/guru/viewbio.jsp?EID=1124801), Oct
30, 2003
According to theory concept says, session is best way to pass the the value from one
screen to another since there is no limitation in session. what i feel is if u keep so
many data in session will it affect the network. all the session is going to be in
memory in application server only know. pls suggest me when to use hidden, cookie,
session.
Re: which is the best way to pass the value from one screen to another either
hiddenor session
Author: Kimbo Mundy (http://www.jguru.com/guru/viewbio.jsp?EID=1120338),
Nov 15, 2003
Perhaps it's obvious, but don't forget about the simplest way of passing state: For
small bits of data, like the page # in a list of search results, just use a parameter in
the URL.
Re[2]: which is the best way to pass the value from one screen to another
either hiddenor session
Author: sridhar Tirumala
(http://www.jguru.com/guru/viewbio.jsp?EID=1139770), Jan 18, 2004
URL rewriting gives moderate performance because the data has to pass
between the client and server for every request but there is a limitation on
amount of data that can pass through URL rewriting. It gives moderate
performance because of overhead involved on the network for passing data on
every request. But session object mechanism gives better performance because
it stores the session data in memory and reduces overhead on network. Only
session id will be passed between client and server. But it does not scale well
up on increasing session data and concurrent users because of increase in
memory overhead and also increase in overhead on garbage collection. There
choosing the session mechanism out of one of the above approaches not only
depends on performance but also depends on scaling and security factor . The
best approach to maintain a balance between performance, scalability and
security. Mixture of session mechanism and Hidden fields gives both
performance and scalability. By putting secure data in session and non secure
data in hidden fields you can achieve better security
Re[3]: which is the best way to pass the value from one screen to
another either hiddenor session
Author: Bill Bruns
(http://www.jguru.com/guru/viewbio.jsp?EID=1150451), Mar 1, 2004
Isn't it true that there are circumstances where the session variables cannot
be used?
In other words, that some items must be passed by means of URL rewriting
because they are being changed by javaScript code instead of JSP code.
The difference is that javaScript executes on the client but JSP exectues on
the server.
For example, consider a page that asks if the user is a man or a woman, and
has a dropdown list that changes depending on if a man or a woman is
choosing (clothing types: blouse versus shirt). The dropdown list might
only change at the client, not at the server. But the session variables only
exist at the server. In this case, the data can only be passed by URL
parameters. Unless someone knows of a way to use javaScript to change
items at the server, without using parameter passing (aka, URL rewriting)?
Bill
Re[4]: which is the best way to pass the value from one screen to
another either hiddenor session
Author: Shrinivas Vadavadagi
(http://www.jguru.com/guru/viewbio.jsp?EID=1170700), May 17, 2004
You can give the same name in the form, so that you can recognise what
the user has selected. Hence what ever you can do in URL re-writing
can be done through the session management. But there is a limitation in
this as this is no scalable. One study suggests that one can store upto 3K
of data in the session after whicg there will be drop in the performance.
Hence should store the data in the session which are necessary and clear
the session data, if not necessary.
Re[5]: which is the best way to pass the value from one screen to
another either hiddenor session
Author: sathish kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=1185907), Jul 18,
2004
i AM ACCEPTING ANY FIVE DIFFERENCE BETWEEN
THEM.PLEASE IF ANY ONE FOR THIS...
What are the additional features of EJB 2.1 over EJB 2.0
Location: http://www.jguru.com/faq/view.jsp?EID=1083000
Created: May 8, 2003 Modified: 2003-12-01 07:24:14.337
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Thrihesh Rai (http://www.jguru.com/guru/viewbio.jsp?EID=1080402
Compared to the 2.0 specifications, EJB 2.1 have focused the attention in trying to
be more "web-services" oriented, and with the improving of some important features
where the community have found some design or implementation issue, like the
Query Language, the addition of a Timer service, and other improvement like
Message-Driven Beans.
Everybody has noticed that the biggest addition in EJB 2.1 is the new support for the
Web-Services technology. With this new specifications, in fact, developers can expose
their Stateless Session and Message-Driven EJBs as Web Services based on SOAP.
This will mean that any client that complies with SOAP 1.1 will be able to access to
the exposed EJBs. The APIs that will allow this and that have been added, are JAXM
and JAX-RPC.
The first one, JAX-RPC, stands for Java API for XML-RPC, and it can be considered as
Java RMI, but unsing SOAP as the protocol.
The second one, JAXM, stands for Java API for XML Messaging, and it is a SOAP
messaging API similar to JMS (Java Message Service). JAXM is an API for sending
and receiving messages via Web services, conceptually similar to JMS that is an API
for sending and receiving messages via message-oriented middleware.
Another addition is the Timer Service, that can be seen as a scheduling built right
inside the EJB Container.
With EJB 2.1, any Stateless Session or Entity Bean can register itself with the Timer
Service, requesting a notification or when a given timeframe has elapsed, or at a
specific point in time.
From a developer point of view, the Timer Service uses a very simple programming
model based on the implementation of the TimedObject interface.
From the enhancement side, the Query Language is definitely the topic where the
improvements are definitely more visible.
The ORDER BY clause has finally been added. This will improve performance on
orederd queries, because this will be handled by the underneath database, and not
through the code by sorting the resulting collection.
The WHERE clause has been improved with the addition of MOD, while the SELECT
clause has been improved by adding aggregate functions, like COUNT, SUM, AVG,
MIN and MAX.
Additional information can be found at the Enterprise JavaBeans official page at Sun.
Additional Note
This is something related to snchronizing all the instances. If a user modify a
variable in Stateless Session Bean can it be reflected to all other instances in the
pool? so that if next/other user access the variable he/she will get the updated
value.
This is a little messy because you don't always know how many instances the EJB
Container has deployed in memory. Furthermore, you need to broadcast this
message to each and every instance. Session bean were not designed to be called
individually because the Container dynamically assigns an instance to handle the
method invocation before each invocation.
Because of this, I would suggest you move the data contained in your instance
variables outside the session bean. It could be placed into a database table which is
accessed by a read-only entity bean.
The session bean can read the values before every request. Plus, since these are
read-only entity beans, the values are cached in memory (provided you have a big
enough cache) and the database is only accessed once or after a configurable
amount of time.
This solution also works in a clustered environment and is portable across other app
servers.
If you don't like entity beans, you can always use static objects to store the data of
the instance variables. These would be stored in a static object in memory thereby
accessible and shareable by any and all instances of the session bean. This is a more
complex solution and you need to understand how classloaders work. Plus, it may
not work in a cluster nor be portable.
basic problem
Author: Shashank B (http://www.jguru.com/guru/viewbio.jsp?EID=1134131), Dec
16, 2003
Basically the difference offered from sun for stateless and statefull is to maintain a
state of object or not.. If you want to maintain a instance variable value..so you should
not go for stateless things..The design problem of this things can be patched with
using static variables ..but it is not considered as best practice
EJB and scalability EJB is scalable because it can run in cluster environment.
What is there in EJB specification and in Application Server that supports
this feature ?
Location: http://www.jguru.com/faq/view.jsp?EID=1105231
Created: Jul 31, 2003
Author: Satish Kumar Tedla (http://www.jguru.com/guru/viewbio.jsp?EID=1077558)
Question originally posed by devang parikh
(http://www.jguru.com/guru/viewbio.jsp?EID=427162
For example, if an application was developed to handle 100 concurrent users with a
performance of x. After sometime, the number of users/customers get doubled. In
this case, we have to increase the current processing capability of the application
with no degradation of the performance. We increase the number of application
server instances and cluster them.
about javabeans
Author: deeptichaitanya malapati
(http://www.jguru.com/guru/viewbio.jsp?EID=1145386), Feb 11, 2004
send a sample code how to create a sessionbean so that it must connect to the
database(oracle).
The Remote and Home interfaces have somewhat misleading names, because both
interfaces are used by the EJB client, which may be on a "remote" machine.
You will need to use both when working with EJBs. In very general terms, the Home
interface has methods that relate to all EJBs of a certain class as a whole. For
example, you will find the create() methods in the Home interface, which create new
beans. You'll also see the find() methods, in the case of entity beans, which return
handles on certain beans.
The Remote interface has the methods that relate to a particular bean instance. This
is usually where all the business methods go. For example, the Remote interface for
an entity bean will have all of the "getFoo()", "getBar()" methods that return
properties of a particular bean.
In some sense Home interface methods are analagous to the constructor and static
methods of a regular Java class, and Remote interface methods are like instance
methods of a regular Java class.
The Local and LocalHome interfaces are entirely analagous, but are used to more
efficiently access EJBs that are deployed in the same container.
Remote interfaces (i.e products generated by the home interface)are used to invoke
the business methods.
Local interfaces can be used if that bean will be invoked by an application residing on
the same App Server and vise versa.
Generally Remote and Local bean combination are used in the applications where
Session Facade has been implemented.
The home interface defines the methods a client uses to create, locate, and
destroy instances of an enterprise bean.
The remote or local interface defines the business methods implemented in the
bean. A client accesses these methods through the remote interface.
Once the bean is deployed in the EJB container, the client calls the create()
method defined in the home interface to instantiate the bean. The home interface
isn't implemented in the bean itself, but by the container. Other methods declared
in the home interface permit the client to locate an instance of a bean and to
remove a bean instance when it is no longer needed. EJB 2.0 beans also allow the
home interface to have business methods called ejbHome methods.
When the enterprise bean is instantiated, the client can call the business
methods within the bean. The client never calls a method in the bean instance
directly, however. The methods available to the client are defined in the remote or
local interface of the bean, and the remote or local interface is implemented by the
container. When the client calls a method, the container receives the request and
delegates it to the bean instance.
So if you want to deploy your EJB client and EJB in the same server/JVM
then you don't need the remote EJB but can use the local EJB .The local
EJB does not use RMI/RMI-IIOP for communication, it bypasses this
overhead and uses pass-by-reference as normal java mechanism and hence
is faster and efficient when compared to remote EJBs.
What is GlassFish?
Location: http://www.jguru.com/faq/view.jsp?EID=1255621
Created: Jul 29, 2005
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7)
The GlassFish Project is Sun's open source application server project. Found at
https://glassfish.dev.java.net/, you can participate in the development of the latest
version of Sun's Java System Application Server PE 9.0. It is based on Java
Enterprise Edition 5.