aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes problem with finder method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "problem with finder method" Watch "problem with finder method" New topic
Author

problem with finder method

vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
Hi,
i have a problem
when ever i try to map 1:1 relationship at that time when at client side when i call the primary key of other table then the following error occurs
:-
non-static method findByPrimaryKey(java.lang.String) cannot be referenced from a static context

now can any one tell me why this occurs
i shall be thankful to you


Warm Regards<br />vikassheelgupta<br />9911005168
Adrian Bates
Greenhorn

Joined: Jun 01, 2005
Posts: 24
Are you testing this method inside a small test harness? Is the method you are calling static by any chance?
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
ya
i dont have any static method
even i dont have use static keyword
but because of CMP EJB the method i make in home interface automatically becomes Abstract so
i cant understand why this problem occurs
Adrian Bates
Greenhorn

Joined: Jun 01, 2005
Posts: 24
All methods in the home interface will just be method stubs (i.e. abstract) as this is an interface. The actual class that implements this interface is automatically generated and you don't need to worry about it. This is not your problem.
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
so can you tell me why this problem occurs
and even i didnt use any static keyword
thanks alot
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Please post your code, both client and server.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
Home Interface
public interface CnmasLocalHome extends EJBLocalHome
{
public CnmasLocal create() throws CreateException;

public CnmasLocal findByPrimaryKey(String cnDocNo) throws FinderException;

public Collection findAll() throws FinderException;

public CnmasLocal create(String cnDocNo, String docType, Date docDate, String despatchMode, String bookBr, String bookStation, String dlyBr, String dlyStation, String frType, String tbbBr, String tbbParty, String contractBr, String contractNo, String sharedFrType, String sharedDocNo, double rebookingAmt, String mrDocNo, String partyCode, String conseeCode, double noPkgs, double rPkg, double iPkg, String packingCode, String modeRate, double declWt, double chargeWt, double valueDecl, double rate, double freightAmt, double hamaliAmt, double surAmt, double stAmt, double tpndAmt, double checkPostAmt, double otherAmt, double extra1, double extra2, double extra3, double servTax, double advAmt, double totalAmt, String desgrpCode, String desCode, String formName, String goodsRem, String bookingTime, Date pickupDate, String privateMark, String dodDacc, double dodValue, String formcYn, String bookIncharge, String riskType, String gdYn, String modvatYn, String apprvYn, double dsrNo, Date dsrDate, String userName, Date entDate, String modifyBy, Date modifyDate, String billPrintYn, double dcrNo, Date dcrDate, String regionCode, String zoneCode, String stateCode, Collection dodAuthorisation_cnmtNo) throws CreateException;
}
Remote Interface
package model.cnmas;
import javax.ejb.EJBLocalObject;
import java.sql.Date;
import java.util.Collection;

public interface CnmasLocal extends EJBLocalObject
{
String getCnDocNo();

String getDocType();

void setDocType(String docType);

Date getDocDate();

void setDocDate(Date docDate);

String getDespatchMode();

void setDespatchMode(String despatchMode);

String getBookBr();

void setBookBr(String bookBr);

String getBookStation();

void setBookStation(String bookStation);

String getDlyBr();

void setDlyBr(String dlyBr);

String getDlyStation();

void setDlyStation(String dlyStation);

String getFrType();

void setFrType(String frType);

String getTbbBr();

void setTbbBr(String tbbBr);

String getTbbParty();

void setTbbParty(String tbbParty);

String getContractBr();

void setContractBr(String contractBr);

String getContractNo();

void setContractNo(String contractNo);

String getSharedFrType();

void setSharedFrType(String sharedFrType);

String getSharedDocNo();

void setSharedDocNo(String sharedDocNo);

double getRebookingAmt();

void setRebookingAmt(double rebookingAmt);

String getMrDocNo();

void setMrDocNo(String mrDocNo);

String getPartyCode();

void setPartyCode(String partyCode);

String getConseeCode();

void setConseeCode(String conseeCode);

double getNoPkgs();

void setNoPkgs(double noPkgs);

double getRPkg();

void setRPkg(double rPkg);

double getIPkg();

void setIPkg(double iPkg);

String getPackingCode();

void setPackingCode(String packingCode);

String getModeRate();

void setModeRate(String modeRate);

double getDeclWt();

void setDeclWt(double declWt);

double getChargeWt();

void setChargeWt(double chargeWt);

double getValueDecl();

void setValueDecl(double valueDecl);

double getRate();

void setRate(double rate);

double getFreightAmt();

void setFreightAmt(double freightAmt);

double getHamaliAmt();

void setHamaliAmt(double hamaliAmt);

double getSurAmt();

void setSurAmt(double surAmt);

double getStAmt();

void setStAmt(double stAmt);

double getTpndAmt();

void setTpndAmt(double tpndAmt);

double getCheckPostAmt();

void setCheckPostAmt(double checkPostAmt);

double getOtherAmt();

void setOtherAmt(double otherAmt);

double getExtra1();

void setExtra1(double extra1);

double getExtra2();

void setExtra2(double extra2);

double getExtra3();

void setExtra3(double extra3);

double getServTax();

void setServTax(double servTax);

double getAdvAmt();

void setAdvAmt(double advAmt);

double getTotalAmt();

void setTotalAmt(double totalAmt);

String getDesgrpCode();

void setDesgrpCode(String desgrpCode);

String getDesCode();

void setDesCode(String desCode);

String getFormName();

void setFormName(String formName);

String getGoodsRem();

void setGoodsRem(String goodsRem);

String getBookingTime();

void setBookingTime(String bookingTime);

Date getPickupDate();

void setPickupDate(Date pickupDate);

String getPrivateMark();

void setPrivateMark(String privateMark);

String getDodDacc();

void setDodDacc(String dodDacc);

double getDodValue();

void setDodValue(double dodValue);

String getFormcYn();

void setFormcYn(String formcYn);

String getBookIncharge();

void setBookIncharge(String bookIncharge);

String getRiskType();

void setRiskType(String riskType);

String getGdYn();

void setGdYn(String gdYn);

String getModvatYn();

void setModvatYn(String modvatYn);

String getApprvYn();

void setApprvYn(String apprvYn);

double getDsrNo();

void setDsrNo(double dsrNo);

Date getDsrDate();

void setDsrDate(Date dsrDate);

String getUserName();

void setUserName(String userName);

Date getEntDate();

void setEntDate(Date entDate);

String getModifyBy();

void setModifyBy(String modifyBy);

Date getModifyDate();

void setModifyDate(Date modifyDate);

String getBillPrintYn();

void setBillPrintYn(String billPrintYn);

double getDcrNo();

void setDcrNo(double dcrNo);

Date getDcrDate();

void setDcrDate(Date dcrDate);

String getRegionCode();

void setRegionCode(String regionCode);

String getZoneCode();

void setZoneCode(String zoneCode);

String getStateCode();

void setStateCode(String stateCode);

Collection getDodAuthorisation_cnmtNo();

void setDodAuthorisation_cnmtNo(Collection dodAuthorisation_cnmtNo);
}
BEAN CLASS
package model.cnmas;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import java.sql.Date;
import java.util.Collection;
import java.sql.Date;

public abstract class CnmasBean implements EntityBean
{
private EntityContext context;

public String ejbCreate()
{
return null;
}

public void ejbPostCreate()
{
}

public String ejbCreate(String cnDocNo, String docType, Date docDate, String despatchMode, String bookBr, String bookStation, String dlyBr, String dlyStation, String frType, String tbbBr, String tbbParty, String contractBr, String contractNo, String sharedFrType, String sharedDocNo, double rebookingAmt, String mrDocNo, String partyCode, String conseeCode, double noPkgs, double rPkg, double iPkg, String packingCode, String modeRate, double declWt, double chargeWt, double valueDecl, double rate, double freightAmt, double hamaliAmt, double surAmt, double stAmt, double tpndAmt, double checkPostAmt, double otherAmt, double extra1, double extra2, double extra3, double servTax, double advAmt, double totalAmt, String desgrpCode, String desCode, String formName, String goodsRem, String bookingTime, Date pickupDate, String privateMark, String dodDacc, double dodValue, String formcYn, String bookIncharge, String riskType, String gdYn, String modvatYn, String apprvYn, double dsrNo, Date dsrDate, String userName, Date entDate, String modifyBy, Date modifyDate, String billPrintYn, double dcrNo, Date dcrDate, String regionCode, String zoneCode, String stateCode, Collection dodAuthorisation_cnmtNo)
{
setCnDocNo(cnDocNo);
return cnDocNo;
}

public void ejbPostCreate(String cnDocNo, String docType, Date docDate, String despatchMode, String bookBr, String bookStation, String dlyBr, String dlyStation, String frType, String tbbBr, String tbbParty, String contractBr, String contractNo, String sharedFrType, String sharedDocNo, double rebookingAmt, String mrDocNo, String partyCode, String conseeCode, double noPkgs, double rPkg, double iPkg, String packingCode, String modeRate, double declWt, double chargeWt, double valueDecl, double rate, double freightAmt, double hamaliAmt, double surAmt, double stAmt, double tpndAmt, double checkPostAmt, double otherAmt, double extra1, double extra2, double extra3, double servTax, double advAmt, double totalAmt, String desgrpCode, String desCode, String formName, String goodsRem, String bookingTime, Date pickupDate, String privateMark, String dodDacc, double dodValue, String formcYn, String bookIncharge, String riskType, String gdYn, String modvatYn, String apprvYn, double dsrNo, Date dsrDate, String userName, Date entDate, String modifyBy, Date modifyDate, String billPrintYn, double dcrNo, Date dcrDate, String regionCode, String zoneCode, String stateCode, Collection dodAuthorisation_cnmtNo)
{
}

public void ejbActivate()
{
}

public void ejbLoad()
{
}

public void ejbPassivate()
{
}

public void ejbRemove()
{
}

public void ejbStore()
{
}

public void setEntityContext(EntityContext ctx)
{
this.context = ctx;
}

public void unsetEntityContext()
{
this.context = null;
}

public abstract String getCnDocNo();

public abstract void setCnDocNo(String cnDocNo);

public abstract String getDocType();

public abstract void setDocType(String docType);

public abstract Date getDocDate();

public abstract void setDocDate(Date docDate);

public abstract String getDespatchMode();

public abstract void setDespatchMode(String despatchMode);

public abstract String getBookBr();

public abstract void setBookBr(String bookBr);

public abstract String getBookStation();

public abstract void setBookStation(String bookStation);

public abstract String getDlyBr();

public abstract void setDlyBr(String dlyBr);

public abstract String getDlyStation();

public abstract void setDlyStation(String dlyStation);

public abstract String getFrType();

public abstract void setFrType(String frType);

public abstract String getTbbBr();

public abstract void setTbbBr(String tbbBr);

public abstract String getTbbParty();

public abstract void setTbbParty(String tbbParty);

public abstract String getContractBr();

public abstract void setContractBr(String contractBr);

public abstract String getContractNo();

public abstract void setContractNo(String contractNo);

public abstract String getSharedFrType();

public abstract void setSharedFrType(String sharedFrType);

public abstract String getSharedDocNo();

public abstract void setSharedDocNo(String sharedDocNo);

public abstract double getRebookingAmt();

public abstract void setRebookingAmt(double rebookingAmt);

public abstract String getMrDocNo();

public abstract void setMrDocNo(String mrDocNo);

public abstract String getPartyCode();

public abstract void setPartyCode(String partyCode);

public abstract String getConseeCode();

public abstract void setConseeCode(String conseeCode);

public abstract double getNoPkgs();

public abstract void setNoPkgs(double noPkgs);

public abstract double getRPkg();

public abstract void setRPkg(double rPkg);

public abstract double getIPkg();

public abstract void setIPkg(double iPkg);

public abstract String getPackingCode();

public abstract void setPackingCode(String packingCode);

public abstract String getModeRate();

public abstract void setModeRate(String modeRate);

public abstract double getDeclWt();

public abstract void setDeclWt(double declWt);

public abstract double getChargeWt();

public abstract void setChargeWt(double chargeWt);

public abstract double getValueDecl();

public abstract void setValueDecl(double valueDecl);

public abstract double getRate();

public abstract void setRate(double rate);

public abstract double getFreightAmt();

public abstract void setFreightAmt(double freightAmt);

public abstract double getHamaliAmt();

public abstract void setHamaliAmt(double hamaliAmt);

public abstract double getSurAmt();

public abstract void setSurAmt(double surAmt);

public abstract double getStAmt();

public abstract void setStAmt(double stAmt);

public abstract double getTpndAmt();

public abstract void setTpndAmt(double tpndAmt);

public abstract double getCheckPostAmt();

public abstract void setCheckPostAmt(double checkPostAmt);

public abstract double getOtherAmt();

public abstract void setOtherAmt(double otherAmt);

public abstract double getExtra1();

public abstract void setExtra1(double extra1);

public abstract double getExtra2();

public abstract void setExtra2(double extra2);

public abstract double getExtra3();

public abstract void setExtra3(double extra3);

public abstract double getServTax();

public abstract void setServTax(double servTax);

public abstract double getAdvAmt();

public abstract void setAdvAmt(double advAmt);

public abstract double getTotalAmt();

public abstract void setTotalAmt(double totalAmt);

public abstract String getDesgrpCode();

public abstract void setDesgrpCode(String desgrpCode);

public abstract String getDesCode();

public abstract void setDesCode(String desCode);

public abstract String getFormName();

public abstract void setFormName(String formName);

public abstract String getGoodsRem();

public abstract void setGoodsRem(String goodsRem);

public abstract String getBookingTime();

public abstract void setBookingTime(String bookingTime);

public abstract Date getPickupDate();

public abstract void setPickupDate(Date pickupDate);

public abstract String getPrivateMark();

public abstract void setPrivateMark(String privateMark);

public abstract String getDodDacc();

public abstract void setDodDacc(String dodDacc);

public abstract double getDodValue();

public abstract void setDodValue(double dodValue);

public abstract String getFormcYn();

public abstract void setFormcYn(String formcYn);

public abstract String getBookIncharge();

public abstract void setBookIncharge(String bookIncharge);

public abstract String getRiskType();

public abstract void setRiskType(String riskType);

public abstract String getGdYn();

public abstract void setGdYn(String gdYn);

public abstract String getModvatYn();

public abstract void setModvatYn(String modvatYn);

public abstract String getApprvYn();

public abstract void setApprvYn(String apprvYn);

public abstract double getDsrNo();

public abstract void setDsrNo(double dsrNo);

public abstract Date getDsrDate();

public abstract void setDsrDate(Date dsrDate);

public abstract String getUserName();

public abstract void setUserName(String userName);

public abstract Date getEntDate();

public abstract void setEntDate(Date entDate);

public abstract String getModifyBy();

public abstract void setModifyBy(String modifyBy);

public abstract Date getModifyDate();

public abstract void setModifyDate(Date modifyDate);

public abstract String getBillPrintYn();

public abstract void setBillPrintYn(String billPrintYn);

public abstract double getDcrNo();

public abstract void setDcrNo(double dcrNo);

public abstract Date getDcrDate();

public abstract void setDcrDate(Date dcrDate);

public abstract String getRegionCode();

public abstract void setRegionCode(String regionCode);

public abstract String getZoneCode();

public abstract void setZoneCode(String zoneCode);

public abstract String getStateCode();

public abstract void setStateCode(String stateCode);

public abstract Collection getDodAuthorisation_cnmtNo();

public abstract void setDodAuthorisation_cnmtNo(Collection dodAuthorisation_cnmtNo);
}
Client Code



Context ctx = new InitialContext();

DodAuthorisationHome dodAuthHome = (DodAuthorisationHome)PortableRemoteObject.narrow(ctx.lookup("DodAuthorisation"), DodAuthorisationHome.class);

DodAuthorisation dodAuthorisation;
dodAuthorisation=dodAuthHome.create( dpa_name, dpb_name, dpi_no, dpi_date, dpi_value, dprb_days, dpdb_name, dppo_no, dppo_date, dpcr_no, dpsr_no, dpwb_no, dpa_date, dpa_amount, dformc, dpd_amount, dpc_amount, dpd_favourof, dpc_favourof, dpd_payableat, dpc_payableat, dcancel, username, sqlToday, emodify_by, emodify_date);
Cnmas cn= CnmasHome.findByPrimaryKey("101");
System.out.println("vikas");

This is a JSP file and i just give u the code which i use to make relationship




now we have local home and local remote interface too
and the 1:1 mapping bean also with name dodauthorisation
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Surely both your ejbCreate methods must return null.
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
Hi,
The problem is not related to the return type but when ever i call the findByPrimaryKey method in the jsp page finder method of the foreign key table's bean. Then my IDE able to import the class but unable to call the findByPrimaryKey method
so if i forcefuly write this method and compile my program then this error occurs
non-static method findByPrimaryKey(java.lang.String) cannot be referenced from a static context
sunny sri
Greenhorn

Joined: Jul 28, 2005
Posts: 3
Hi,
make sure that getting the homeobject correctly.

Thankq
Balazs Borbely
Ranch Hand

Joined: Oct 11, 2004
Posts: 33
Cnmas cn= CnmasHome.findByPrimaryKey("101");

You didn't provide any detail about 'CnmasHome', it seams as a static methot call.


'Make everything as simple as possible, but not simpler.' --Albert Einstein
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
hi all
thanks alot
i got the solution related to that problem
the solution will be the confinguring foreign key bean in JNDI
i didnt lookup the other bean
so this problem occurs
thanks alot
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem with finder method