• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

EJB unable to find my Home interface

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pretty new to j2ee, so pls excuse for silly questions.
I had deployed my application at college which worked exactly but when I deployed it at my home, it got deployed well but its returning a error message when create is called. Also i had used mssql for jdbc connection but haven't set the j2ee_classpath, pls help me how to find jdbc drivers .jar file. Does j2ee_classpath has anything to do with my error.
Help me soon, i have to hurry up my proj...

Advanced Thanks To Your Good Heart.

- Suresh Kumar.R
coding snippet -->****Down
public AccountBean()
{
try
{
Context ic=new InitialContext();
java.lang.Object objref=ic.lookup("java:comp/env/ejb/Account");
accountHome=(AcHome)PortableRemoteObject.narrow(objref,AcHome.class);
}
catch(Exception re)
{
System.err.println("Couldn't locate Account Home");
re.printStackTrace();
}
reset();
}
********Error :********
Couldn't locate Account Home
javax.naming.NameNotFoundException: Account not found
<<no stack trace available>>
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


it got deployed well but its returning a error message when create is called.


That means that your container cannot create bean instances and your bean is unavailable to your clients. What type of bean is this? Is it a session bean or an entity bean? And what is your code in ejbCreate (if any)? Can you send the server error stack trace? Unless you won�t be able to correctly deploy and bind your bean to the JNDI tree, your client code will constantly fail.


Also i had used mssql for jdbc connection but haven't set the j2ee_classpath


That�s a must. Your server classpath must include those libraries. I have WebLogic and it requires these three libraries: msbase.jar, msutil.jar and mssqlserver.jar. Try a search on the net see if you can find any more info.


Does j2ee_classpath has anything to do with my error.


It has everything to do with your error. Install the mssql libraries corectely and we shall see from there. You might set data sources and connection pools as well, but you first need to install the required libraries.
Regards.
 
Suresh Kumar.R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Tanase:

It has everything to do with your error. Install the mssql libraries corectely and we shall see from there. You might set data sources and connection pools as well, but you first need to install the required libraries.
Regards.



Account.java---> remote interface
import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface Account extends EJBObject
{
public String getDate() throws RemoteException;
public String getVc() throws RemoteException;
public String getCheck() throws RemoteException;
public double getAmount() throws RemoteException;
}

AcHome.java-->Home Interface
import java.rmi.RemoteException;
import javax.ejb.*;
public interface AcHome extends EJBHome
{
public Account create(String id,String date,String vc,String check,double amount) throws RemoteException,CreateException;
public Account findByPrimaryKey(String id) throws FinderException,RemoteException;
}

AcEJB.java-->EJB java ( Entity bean )
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;

public class AcEJB implements EntityBean
{
private String id;
private String date;
private String vc;
private String check;
private double amount;
private EntityContext context;
private Connection con;
private String dbName="java:comp/env/jdbc/MyDataSource";

public String getDate()
{
return date;
}
public String getVc()
{
return vc;
}
public String getCheck()
{
return check;
}
public double getAmount()
{
return amount;
}
public String ejbCreate(String id,String date,String vc,String check,double amount) throws CreateException
{
try
{
insertRow(id,date,vc,check,amount);
}
catch(Exception ex)
{
throw new EJBException("ejbCreate: "+ex.getMessage());
}
this.id=id;
this.date=date;
this.vc=vc;
this.check=check;
this.amount=amount;
return id;
}

public String ejbFindByPrimaryKey(String primaryKey)throws FinderException
{
boolean result;
try
{
result=selectByPrimaryKey(primaryKey);
}
catch(Exception ex)
{
throw new EJBException("ejbFindByPrimaryKey: "+ex.getMessage());
}
if(result)
{
return primaryKey;
}
else
{
throw new ObjectNotFoundException("Row for id "+primaryKey+" not found");
}
}

public void ejbRemove()
{
try
{
deleteRow(id);
}
catch (Exception ex)
{
throw new EJBException("ejbRemove: "+ex.getMessage());
}
}

public void setEntityContext(EntityContext context)
{
this.context=context;
try
{
makeConnection();
}
catch (Exception ex)
{
throw new EJBException("Unable to connect to Database."+ex.getMessage());
}
}
public void unsetEntityContext()
{
try
{
con.close();
}
catch (SQLException ex)
{
throw new EJBException("unsetEntityContext: "+ex.getMessage());
}
}

public void ejbActivate()
{
id=(String)context.getPrimaryKey();
}

public void ejbPassivate()
{
id=null;
}

public void ejbLoad()
{
try
{
loadRow();
}
catch(Exception ex)
{
throw new EJBException("ejbLoad: "+ex.getMessage());
}
}

public void ejbStore()
{
try
{
storeRow();
}
catch(Exception ex)
{
throw new EJBException("ejbLoad: "+ex.getMessage());
}
}

public void ejbPostCreate(String id,String date,String vc,String check,double amount){}

private void makeConnection() throws NamingException,SQLException
{
InitialContext ic=new InitialContext();
DataSource ds=(DataSource)ic.lookup(dbName);
con=ds.getConnection();
}

private void insertRow(String id,String date,String vc,String check,double amount) throws SQLException
{
String insertStatement="insert into Account_Holder_Transaction values (?,?,?,?,?)";
PreparedStatement prepStmt=con.prepareStatement(insertStatement);
prepStmt.setString(1,id);
prepStmt.setString(2,date);
prepStmt.setString(3,vc);
prepStmt.setString(4,check);
prepStmt.setDouble(5,amount);
prepStmt.executeUpdate();
prepStmt.close();
}


private void deleteRow(String id) throws SQLException
{
String deleteStatement="delete from Account_Holder_Transaction where cAccount_id=?";
PreparedStatement prepStmt=con.prepareStatement(deleteStatement);
prepStmt.setString(1,id);
prepStmt.executeUpdate();
prepStmt.close();
}

private boolean selectByPrimaryKey(String primaryKey) throws SQLException
{
String selectStatement="select cAccount_id "+"from Account_Holder where cAccount_id=?";
PreparedStatement prepStmt=con.prepareStatement(selectStatement);
prepStmt.setString(1,primaryKey);
ResultSet rs=prepStmt.executeQuery();
boolean result=rs.next();
prepStmt.close();
return result;
}

private void loadRow() throws SQLException
{
String selectStatement="select dDate_of_transaction,vcParticulars,cCheck_no,mAmount from Account_Holder_Transaction where cAccount_id=?";
PreparedStatement prepStmt=con.prepareStatement(selectStatement);
prepStmt.setString(1,this.id);
ResultSet rs=prepStmt.executeQuery();
if(rs.next())
{
this.date=rs.getString(1);
this.vc=rs.getString(2);
this.check=rs.getString(3);
this.amount=rs.getDouble(4);
prepStmt.close();
}
else
{
prepStmt.close();
throw new NoSuchEntityException("Row for id"+id+" not found in database.");
}
}

private void storeRow() throws SQLException
{
String updateStatement="update Account_Holder_Transaction set dDate_of_transaction=?,vcParticulars=?,cCheck_no=?,mAmount=? where cAccount_id=?";
PreparedStatement prepStmt=con.prepareStatement(updateStatement);
prepStmt.setString(1,date);
prepStmt.setString(2,vc);
prepStmt.setString(3,check);
prepStmt.setDouble(4,amount);
prepStmt.setString(5,id);
prepStmt.executeUpdate();
prepStmt.close();
int rowcount=prepStmt.executeUpdate();
prepStmt.close();
if(rowcount==0)
{
throw new EJBException("Storing Row for id "+id+" failed.");
}
}
}

AccountBean.java-->Bean Accessing EJB
import java.util.*;
import java.io.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class AccountBean
{
private String action;
private String id;
private String dateTran;
private String vc;
private String check;
private double amount;
private AcHome accountHome;
private Account account;
public AccountBean()
{
try
{
Context ic=new InitialContext();
java.lang.Object objref=ic.lookup("java:comp/env/ejb/Account");
accountHome=(AcHome)PortableRemoteObject.narrow(objref,AcHome.class);
}
catch(Exception re)
{
System.err.println("Couldn't locate Account Home");
re.printStackTrace();
}
reset();
}
public String processRequest()
{
String message="";
System.out.println("Process request called ");
System.out.println(this);
try
{
if(action.equals("save"))
{
account=accountHome.create(id,dateTran,vc,check,amount);message="Recorded details for account '"+id+"'";
}
}
catch(Exception e)
{
message=e.toString();
}
return message;
}
public String getAction()
{
System.out.println("Getting Action");
return action;
}
public void setAction(String a)
{
System.out.println("Setting Action : "+a);
action=a;
}
public String getId()
{
System.out.println("Getting id");
return id;
}
public void setId(String i)
{
System.out.println("Setting id : "+i);
id=i;
}
public String getDateTran()
{
System.out.println("Getting transaction date");
return dateTran;
}
public void setDateTran(String f)
{
System.out.println("Setting transaction date : "+f);
dateTran=f;
}
public String getVc()
{
System.out.println("Getting particulars");
return vc;
}
public void setVc(String l)
{
System.out.println("Setting Action : "+l);
vc=l;
}
public String getCheck()
{
System.out.println("Getting check number");
return check;
}
public void setCheck(String b)
{
System.out.println("Setting check number : "+b);
check=b;
}
public double getAmount()
{
System.out.println("Getting amount");
return amount;
}
public void setAmount(double a)
{
System.out.println("Setting Amount : "+a);
amount=a;
}
private void reset()
{
final String emptyString="";
final double zero=0.0;
setAction(emptyString);
setId(emptyString);
setDateTran(emptyString);
setVc(emptyString);
setCheck(emptyString);
setAmount(zero);
}
private void loadFromEJB()
{
try
{
dateTran=account.getDate();
setDateTran(dateTran);
setVc(account.getVc());
setCheck(account.getCheck());
double a=account.getAmount();
setAmount(a);
}
catch(Exception re)
{
System.err.println("Failed to load AccountBean from AcEJB.");
re.printStackTrace();
}
}
public String toString()
{
StringBuffer output=new StringBuffer();
output.append("Action : "+action);
output.append("Id : "+id);
output.append("Transaction Date : "+dateTran);
output.append("Particulars : "+vc);
output.append("Check Number : "+check);
output.append("Amount : "+amount);
return output.toString();
}
}

Account.jsp
<html>
<jsp:useBean id="accountBean" scope="session" class="AccountBean"/>
<jsp:setProperty name="accountBean" property="*"/>
<%! String status; %>
<% status=accountBean.processRequest(); %>
<html>
<head>
<title>Account Interface</title>
</head>
<body bgcolor="pink">
<font size=5 color="#CC0000">
<h1><b><center>Earnest Bank ATM</center></b></h1>
<br>
<form method=POST action=Account.jsp>
<BR>
<br>
<table border=0>
<tr>
<td>
Account ID
</td>
<td>
<INPUT type=text name="id" size="8" value="<jsp:getProperty name="accountBean" property="id"/>">
</td>
<td>
Date Of Transaction
</td>
<td>
<INPUT type=text name="dateTran" size="8" value="<jsp:getProperty name="accountBean" property="dateTran"/>">
</td>
</tr>
<tr>
<td>
Particulars
</td>
<td>
<INPUT type=text name="vc" size="8" value="<jsp:getProperty name="accountBean" property="vc"/>">
</td>
<td>
Check Number
</td>
<td>
<INPUT type=text name="check" size="8" value="<jsp:getProperty name="accountBean" property="check"/>">
</td>
</tr>
<tr>
<td>
Amount
</td>
<td>
<INPUT type=text name="amount" size="8" value="<jsp:getProperty name="accountBean" property="amount"/>">
</td>
</tr>
</table>
<br>
<br>
<INPUT type=hidden name="action" value="save">
<br>
<br>
<InPUT type=submit name="submit" value="Submit">
</form>
</FONT>
</body>
</html>
<hr>
<h3><b>Status :</b></h3> <%=status%>
</html>
</html>

--> I feel that the code doesn't have any error

-->Could U tell where to find jar file[MS-SQL],either on cd or sql installation directory
 
Suresh Kumar.R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Valentin Tanase Gor Your Reply
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are very welcome Suresh. Try this link:
http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&DisplayLang=en
Regards.
 
Suresh Kumar.R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Valentin Tanase!
As you told I told JDBC Driver sp3(instead of sp1),and installed it.
Also i set the J2EE_CLASSPATH as driver's jar file but still it returns erroe saying Could Not Create Entity EJB.I copied all my class files to <j2ee>/lib/classes directory.
Also just explain me about diff. in classpath & j2ee_classpath,and where to copy class files & jar files(incl. j2ee.jar).
please remove my confusion.


-Suresh
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suresh,

There are couple of things you might know: the container�s classpath and the container classloader architecture. Usually the container vendor provides you a set of scripts to startup your application server. Among other things these scripts initializes the container�s classpath as well. Usually you�ll find here all libraries that your container needs in order to run properly. If you need to create connection pools, using a specific type of JDBC driver (like MSSQL) you have to add the libraries to the container�s classpath as well. Otherwise the container won�t be able to create the connection you specified. Notice that application specific libraries are not usually part of the system classpath (this could be done of course, but it�s not a good practice).
The container classloader architecture helps you to understand how application specific libraries are loaded. If you deploy an ear for example, then the container will provide a way to load your ejb libraries, web app libraries and common libraries, deployed within the ear. If you don�t pack your application properly then you�ll very often receive a ClassNotFoundException. Although there are couple of ways to deploy j2ee applications the best and most recommended practice is to deploy them as enterprise archives (ear files). Ear files have a standard architecture and most containers will honor the deployment contract. Please check your container�s documentation and understand these two concepts.
Another thing that you need to check is whether the DataSource and the connection pools are set up properly. Check your container�s log file and make sure the connection pool was initialized properly (otherwise you�ll receive bunch of error messages).
Regards.
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic