Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

some problem with Entity Bean with PK

 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I am having problem with creating an entity bean with PK class. Please somebody let me know what is wrong in the code.


Remote Class
---------------------------------
public interface PKEntity extends EJBObject{
public String getName() throws RemoteException;
public int getId() throws RemoteException;
}

---------------------------------

PK Class
---------------------------------
public class PKEntityBeanPK implements Serializable{
public String name = null;

public String getName() {
return this.name;
}

public void setName(String s) {
this.name = s;
}

public PKEntityBeanPK(String s){
this.name = s;
}

public PKEntityBeanPK(){
}

public int hashCode(){
return this.hashCode();
}

public boolean equals(Object pk){
PKEntityBeanPK other = (PKEntityBeanPK) pk;
if(other.name == this.name ){
return true;
}
return false;
}
}
---------------------------------

Bean Class
--------------------------------
public abstract class PKEntityBean implements EntityBean{

EntityContext context = null;

public abstract void setName(String s) ;

public abstract String getName() ;

public abstract void setId(int s) ;

public abstract int getId() ;

public void ejbActivate(){
}

public void ejbPassivate(){
}

public void ejbRemove(){
}

public void setEntityContext(EntityContext conx){
context=conx;
}
public void unsetEntityContext(){
}

public void ejbLoad(){
}

public void ejbStore(){
}

public PKEntityBeanPK ejbCreate(String name, int id) throws CreateException{
this.setName(name);
this.setId(id);
System.out.println("I am Here");
return null;
}

public void ejbPostCreate(String name, int id) throws CreateException {
}
}
--------------------------------

Home Class
---------------------------------
public interface PKEntityHome extends EJBHome{

public PKEntity create(String name, int id) throws CreateException, RemoteException;

public PKEntity findByPrimaryKey(PKEntityBeanPK pk) throws FinderException, RemoteException;

}
---------------------------------


It was deployed properly. When i execute the create method, i am getting runtime exception and i am also getting output "I am Here" which is ejbCreate method.

Please somebody help me.

Thanks,
Prashant
 
Nadeem Awad
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Prashant,
What is the Exception that you get exactly?
and I noticed that you are using one field only in the Primary Key class, so why do you need a primary key class? why don't you just set the <primkey-field> element in the DD to the name field?
 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nadeem,
Ya, I know that. But just i wanted to write one Entity Bean with PK class. I got some RemoteException with ClassCastException. Do i need to take care of something?
 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi prashant

Please put your ejb-jar.xml file, then we can see any problem in that file also.

Regards
Kasimurugan R.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!