The "Building an EJB Server" document must be completed before this
document will work.
Note that this document is not a complete, step by step example, it
can just be used as reference notes. Use this link to test your
examples:
http://localhost:8080/web-client.
Create an Entity EJB This example first makes some new packages for the new ejb.
Make a new package named "netdb.entities" under src/main/ejb.
Make a new class named NewEntityBean. The name of the class
must end in "Bean", or else the build.xml won't find it.
Extend the class from javax.ejb.EntityBean and make the class abstract.
Add netdb-ejb.jar and include "netdb/entities/**, netdb/interfaces/**"
to the build.xml file.
Add the netdb-jar file using Project-Properties-Java Build Path-Libraries.
Make a new package netdb.interfaces, and drag and drop the
AbstractData, InvalidValueException and ServiceUnavailable exceptions
into it.
Add the "entities" to the packageSubstitution in the xdoclet
generation of the build.xml file. The line should look like:
Build the default ant target.
Right click on the JBoss Template project and select Refresh. This
will update the build/generate package to include the new interfaces
that were created by Ant and XDoclet.
Referring to the new entity EJB To allow access from jsp's, add ejb-ref to web-client.xml and
jboss-web.xml.
If "cannot resolve symbol" displays while compiling a .jsp, then
make sure <%@ page import="..., netdb.interfaces.*"> is defined.
Add <localinterface/> and <localhomeinterface/> in the
<ejbdoclet> target of the build.xml file to support creation of
Local interfaces.
Adding an EJBSelect to an Entity Bean Do this to return a collection of field values from a table. Add
the appropriate get and set methods for a field named "MyNumber". Add the
following to the class header comment.
* @ejb:select signature="java.util.Collection ejbSelectAllMyNumbers()"
* query="SELECT DISTINCT o.myNumber FROM DataStream AS o"
* result-mapping="Local"
Add the following to the NewEntityBean class body. Note that comments must start
with "/**", not "/*".
/**
* Retrieve the myNumber.
*
* @return Returns the myNumber.
* @ejb:interface-method view-type="both"
**/
public abstract java.util.Collection ejbSelectAllMyNumbers();
/**
* Retrieve the myNumbers.
*
* @return Returns the myNumbers.
* @ejb:home-method view-type="both"
**/
public java.util.Collection ejbHomeGetAllMyNumbers()
{ return(ejbSelectAllMyNumbers()); }
Note that ejbSelectAllMyNumbers() will only show up in the remote interfaces.
The function getAllMyNumbers() will only show up in the home interfaces.
The error, "org.jboss.deployment.DeploymentException: Could not
find matching method for public abstract", will display in jboss when
the method in an entity bean must be abstract, or the ejb:home-method
is used, and the function does not start with ejbHome. Note that
ejbHomeGetAllMyNumbers must be called as getAllMyNumbers() from the home interface.
Add a new Session EJB Name it NewSessionBean, and add a method named findAllMyNumbers
that calls the entity bean's getAllMyNumbers().
Referring to the new EJB Session Bean from JSP This example shows building a combo box selection from the returned
information. To add it to another jsp page, simply create a jsp page
in the src/web directory next to the index.jsp page.
An error with the text, "can't create table invalid sql line 1",
can be caused by SQLCC. Disconnect SQLCC from the database, then start jboss.
An error "Every finder method except findByPrimaryKey(key) must
be associated with a query element in the deployment descriptor", will go
away if the ejb:finder has a query keyword specified.
An error similar to the following will display whenever the EJB-QL
syntax is wrong.
org.jboss.deployment.DeploymentException: Error compiling ejbql;
- nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException:
Encountered "xxx" at line 1, column 24. Was expecting: "AS" ... ... )
The syntax indicates it was expecting the AS keyword. Note that JBoss
will display the wrong jndiName in the error.
The error "Unknown terminal field", can be caused because of
an upper-case/lower-case problem.
An error with the text, "could not activate", "system cannot find"
, "file specified", can display if the bean is stateful.
The MySQL Control Center 0.9.1, can display the error, "The select
would examine too many records and probably take a very long time".
This is probably a bug. In this version, a where clause can be used
to return only one record. A parameter from "Options - Query Window
Options - Query Options" can be used to set SQL_BIG_SELECTS to 1,
but still only one record will display.