Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Homeinterface does not recognize the ejbCreate() method in my entity class

843830Mar 1 2006 — edited Mar 4 2006
Hi,

I am developing a J2EE project (with web and EJB modules) for my course work. I am seeing the following error when calling home.create() method. With the same setup, however, I could successfully access a session beam. Infact, I should mention that I am seeing the same message in the console when deploying it to my Sun Application Server. However, the deployment is successful. I've been trying to figure this out since yesterday without any luck. I would really appreciate your help/suggestions.

Error - [#|2006-03-01T10:48:59.108-0800|WARNING|sun-appserver-pe8.1_02|javax.enterprise.system.container.ejb|_ThreadID=11;|EJB5111:Bean class for ejb [ClientRegistration] does not define a method corresponding to [Home] interface method [public abstract com.student.cs6580.ejb.interfaces.Client com.student.cs6580.ejb.interfaces.ClientHome.create(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int) throws java.rmi.RemoteException,javax.ejb.CreateException]|#]


When user submits the form, my controller class calls the entity bean as follows.
Context ctx = new InitialContext();
Object home = ctx.lookup(java:comp/env/ejb/ClientRegistration");
ClientHome chome = (ClientHome) PortableRemoteObject.narrow(home, ClientHome.class);
Client client = chome.create(fname, mName,lastName, street, city, state, zip, homePhone, workPhone, emailId, year);
String clientId = client.getClientId();

web.xml tags related to this process.
<ejb-ref>
<ejb-ref-name>ejb/ClientRegistration</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.student.cs6580.ejb.interfaces.ClientHome</home>
<remote>com.student.cs6580.ejb.interfaces.Client</remote>
</ejb-ref>

sun-web.xml tags related to this.
<ejb-ref>
<ejb-ref-name>ejb/ClientRegistration</ejb-ref-name>
<jndi-name>ClientRegistrationJNDI</jndi-name>
</ejb-ref>


EJB module:

Remote interface:

package com.student.cs6580.ejb.interfaces;

import java.util.*;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface Client extends EJBObject
{
public String getClientId() throws RemoteException;
}


Home Interface
package com.student.cs6580.ejb.interfaces;

import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.FinderException;


public interface ClientHome extends EJBHome
{
Client create(String firstname, String middleName, String lastName, String street, String city, String state, String zip,
String homePhone, String workPhone, String emailId, int year)
throws RemoteException, CreateException;


Client findByPrimaryKey(String primaryKey) throws RemoteException, FinderException;
}

Entity Bean:

package com.student.cs6580.ejb;

import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
import com.student.cs6580.ejb.interfaces.Client;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.ejb.*;
import com.student.cs6580.ejb.util.PrimaryKeyGenerator;

/**
* XDoclet-based BMP entity bean.
*
* To generate EJB related classes using XDoclet:
*
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration
* - Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="Client"
* display-name="Name for Client"
* description="Description for Client"
* jndi-name="ejb/Client"
* type="BMP"
* view-type="remote"
*/
public class ClientBean implements EntityBean
{

/** The entity context */
private EntityContext context;

private Connection conn;
private String clientId, firstName, middleName, lastName, isAddrVerified;
private String street, city, state, zip, workPhone, homePhone, emailId;
private int year;

public ClientBean() {
super();
}

/**
* There are zero or more ejbCreate<METHOD>(...) methods, whose signatures match
* the signatures of the create<METHOD>(...) methods of the entity bean?s home interface.
* The container invokes an ejbCreate<METHOD>(...) method on an entity bean instance
* when a client invokes a matching create<METHOD>(...) method on the entity bean?s
* home interface.<br>
*
* The entity bean provider?s responsibility is to initialize the instance in the ejbCreate<
* METHOD>(...) methods from the input arguments, using the get and set accessor
* methods, such that when the ejbCreate<METHOD>(...) method returns, the persistent
* representation of the instance can be created. <br>
*
* The entity bean provider must not attempt to modify the values of cmr-fields in an ejbCreate<
* METHOD(...) method; this should be done in the ejbPostCreate<METHOD(...) method instead.<br>
*
* The entity object created by the ejbCreate<METHOD> method must have a unique primary
* key. This means that the primary key must be different from the primary keys of all the existing
* entity objects within the same home. However, it is legal to reuse the primary key of a previously
* removed entity object. The implementation of the bean provider?s ejbCreate<
* METHOD>(...) methods should be coded to return a null.<br>
*
* An ejbCreate<METHOD>(...) method executes in the transaction context determined by
* the transaction attribute of the matching create<METHOD>(...) method.
* The database insert operations are performed by the container within the same
* transaction context after the Bean Provider?s ejbCreate<METHOD>(...) method completes.
*
* @throws CreateException Thrown if method fails due to system-level error.
*
* @throws CreateException
*
* @ejb.create-method
*/
public String ejbCreate(String firstname, String middleName, String lastName, String street, String city, String state, String zip,
String homePhone, String workPhone, String emailId, int year) throws RemoteException, CreateException
{
System.out.println("Entered ClientBean ejbCreate");
String strClientPK = null;
PreparedStatement pstmt = null;

try
{
conn = getConnection();
int clientPK = PrimaryKeyGenerator.nextVal("clientid",conn);

if(clientPK != -1)
{
strClientPK = Integer.toString(clientPK);
String sqlStmt = "INSERT INTO client VALUES(?, ?, ?, ?, ?,?,?,?,?,?,?, ?, ?, SYSDATE)";

pstmt = conn.prepareStatement(sqlStmt);

pstmt.setString(1, strClientPK);
pstmt.setString(2, lastName.toUpperCase());
pstmt.setString(3, firstName.toUpperCase());
pstmt.setString(4, middleName);
pstmt.setString(5, street);
pstmt.setString(6, city);
pstmt.setString(7, state);
pstmt.setString(8, zip);
pstmt.setString(9, homePhone);
pstmt.setString(10, workPhone);
pstmt.setString(11, emailId);
pstmt.setString(12, "N");
pstmt.setInt(13, year);

pstmt.executeUpdate();
}
else
{
throw new Exception("Primary key generator did not generate a valid client Pk");
}

} catch (Exception e)
{
throw new CreateException("Error in inserting the client data: "+e.toString());
}
finally
{
try
{
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();

}catch(Exception e){}

}
this.firstName=firstName;
this.middleName=middleName;
this.lastName=lastName;
this.street=street;
this.city=city;
this.state=state;
this.zip=zip;
this.workPhone=workPhone;
this.homePhone=homePhone;
this.emailId=emailId;
this.year=year;
this.isAddrVerified="N";
this.clientId = strClientPK;

return strClientPK;

}



/**
* For each ejbCreate<METHOD>(...) method, there is a matching ejbPostCreate<
* METHOD>(...) method that has the same input parameters but whose return type is
* void. The container invokes the matching ejbPostCreate<METHOD>(...) method on
* an instance after it invokes the ejbCreate<METHOD>(...) method with the same arguments.
* The instance can discover the primary key by calling getPrimaryKey() on its
* entity context object. <br>
*
* The entity object identity is available during the ejbPostCreate<METHOD>(...)
* method. The instance may, for example, obtain the component interface of the associated entity
* object and pass it to another enterprise bean as a method argument.<br>
*
* The entity Bean Provider may use the ejbPostCreate<METHOD>(...) to set the values
* of cmr-fields to complete the initialization of the entity bean instance.
* An ejbPostCreate<METHOD>(...) method executes in the same transaction context as
* the previous ejbCreate<METHOD>(...) method.
*
* @throws CreateException Thrown if method fails due to system-level error.
*/
public void ejbPostCreate() throws CreateException {
}

/**
* Set the associated entity context. The container calls this method
* after the instance creation. The entity bean must not attempt to
* access its persistent state and relationships using the accessor
* methods during this method. <br>
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable. <br>
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setEntityContext(EntityContext newContext) throws EJBException {
context = newContext;
}

/**
* Unset the associated entity context. A container invokes this method
* before terminating the life of the instance. The entity bean must not
* attempt to access its persistent state and relationships using the
* accessor methods during this method. <br>
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void unsetEntityContext() throws EJBException {
context = null;
}

public String getClientId()
{
return clientId;
}

public void ejbRemove()
throws RemoveException,
EJBException,
RemoteException
{
PreparedStatement pstmt = null;

try {
conn = getConnection();
String deleteStmt = "delete from client where clientid = ?";
pstmt = conn.prepareStatement(deleteStmt);

pstmt.setString(1,clientId);
pstmt.executeUpdate();


} catch (Exception e)
{
throw new EJBException("remove exception" + e.toString());
}
finally
{
try
{
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();

}catch(Exception e){}

}

}

public void ejbActivate() throws EJBException, RemoteException
{
clientId = (String) context.getPrimaryKey();

}

public void ejbPassivate() throws EJBException, RemoteException
{
clientId = null;

}

public void ejbLoad() throws EJBException, RemoteException
{
PreparedStatement pstmt=null;
ResultSet rs = null;

try
{
conn = getConnection();
String query = "select * from client where clientid=?";
pstmt = conn.prepareStatement(query);

pstmt.setString(1, this.clientId);
rs = pstmt.executeQuery();

if (rs.next())
{
this.firstName = rs.getString("fname");
this.lastName = rs.getString("lname");
this.middleName = rs.getString("mname");
this.street = rs.getString("street");
this.city= rs.getString("city");
this.state= rs.getString("state");
this.zip= rs.getString("zipcode");
this.workPhone=rs.getString("wtelno");
this.homePhone=rs.getString("htelno");
this.emailId=rs.getString("emailaddr");
this.year=rs.getInt("yearofbirth");
this.isAddrVerified = rs.getString("ISADDRVERIFIED");
}
else
{

throw new NoSuchEntityException("clientId="+clientId+" not found");
}
} catch (Exception ex)
{
throw new EJBException("ejbLoad: " + ex.getMessage());
}
finally
{
try
{
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();

}catch(Exception e){}

}
}

public void ejbStore() throws EJBException, RemoteException
{
PreparedStatement pstmt = null;

try
{
conn = getConnection();
StringBuffer updateStmt = new StringBuffer("update client set fname=?,lname=?, mname=? ");
updateStmt.append(" ,street=?, city=?, state=?, zipcode=?, htelno=?, wtelno=?");
updateStmt.append(",emailaddr=?, ISADDRVERIFIEd=?, yearofbirth=?, membersince=sysdate ");
updateStmt.append(" where clientid =?");

pstmt = conn.prepareStatement(updateStmt.toString());


pstmt.setString(1, firstName.toUpperCase());
pstmt.setString(2, lastName.toUpperCase());
pstmt.setString(3, middleName);
pstmt.setString(4, street);
pstmt.setString(5, city);
pstmt.setString(6, state);
pstmt.setString(7, zip);
pstmt.setString(8, homePhone);
pstmt.setString(9, workPhone);
pstmt.setString(10, emailId);
pstmt.setString(11, isAddrVerified);
pstmt.setInt(12,year);
pstmt.setString(13, clientId);

int n = pstmt.executeUpdate();

if(n == 0) throw new EJBException("ejbStore error:clientId="+clientId);

} catch (Exception ex)
{
throw new EJBException("ejbStore: " + ex.getMessage());
}
finally
{
try
{
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();

}catch(Exception e){}

}
}

protected Connection getConnection() throws SQLException, NamingException
{

InitialContext context = new InitialContext();
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/ClientDB");
return ds.getConnection();
}

public String ejbFindByPrimaryKey(String pk) throws FinderException
{
System.out.println("entered client bean ejbFind");
PreparedStatement pstmt = null;
ResultSet rs = null;

try
{
conn = getConnection();
String query = "select clientid from client where clientid= ?";

pstmt = conn.prepareStatement(query);
pstmt.setString(1,pk);

rs = pstmt.executeQuery();

if (!rs.next()) throw new FinderException("primary key not found");

} catch (Exception e)
{
throw new EJBException("primary key not found" + e.getMessage());
}
finally
{

try
{
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();

}catch(Exception e){}
}
return pk;
}

}

ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>cs6580JAR</display-name>
<enterprise-beans>
<session>
<ejb-name>Branches</ejb-name>
<home>com.student.cs6580.ejb.interfaces.BranchesHome</home>
<remote>com.student.cs6580.ejb.interfaces.Branches</remote>
<ejb-class>com.student.cs6580.ejb.BranchesBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>jdbc/BranchesDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
<entity>
<ejb-name>ClientRegistration</ejb-name>
<home>com.student.cs6580.ejb.interfaces.ClientHome</home>
<remote>com.student.cs6580.ejb.interfaces.Client</remote>
<ejb-class>com.student.cs6580.ejb.ClientBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Object</prim-key-class>
<reentrant>false</reentrant>
<resource-ref>
<res-ref-name>jdbc/ClientDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</entity>
</enterprise-beans>
</ejb-jar>


sun-ejb-jar.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server8.0 EJB 2.1//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_2_1-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<name>cs6580JAR</name>
<ejb>
<ejb-name>Branches</ejb-name>
<jndi-name>Branches</jndi-name>
<resource-ref>
<res-ref-name>jdbc/BranchesDB</res-ref-name>
<jndi-name>jdbc/Oracle</jndi-name>
</resource-ref>
</ejb>
<ejb>
<ejb-name>ClientRegistration</ejb-name>
<jndi-name>ClientRegistrationJNDI</jndi-name>
<resource-ref>
<res-ref-name>jdbc/ClientDB</res-ref-name>
<jndi-name>jdbc/Oracle</jndi-name>
</resource-ref>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2006
Added on Mar 1 2006
7 comments
467 views