Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

could I call findByPrimaryKey() without create()  RSS feed

 
dar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ALL.
I have BMP entity bean and
I need to find by "String findByPrimaryKey(String key_action)"
data field from DB table without calling create(String inAction).
Because I expect/know that datafield (datarecord, what I need)
already exists in DB, therefore I don't want Create/Insert a duplication.
I don't know how I use ejbLoad(). Is "automatic" called this method by EJB-container?
myBeanHome home = (myBeaHome) javax.rmi.PortableRemoteObject.narrow(objref, myBeanHome.class);
/*----------------
home.create("walker");
It creates and inserts duplication.
"walker"-object exists in DB and I need just read it from DB.
-------------------*/
myBean myejb = home.findByPrimaryKey("walker");
String nm = myejb.getName();
//i'm getting here "null"

Some advise please?
my findByPrimaryKey() is typical:
public String ejbFindByPrimaryKey(String key_action) throws ObjectNotFoundException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = getConnection().prepareStatement("SELECT 1 FROM PEOPLE WHERE ACTION = ?");
ps.setString(1, key_action);
rs = ps.executeQuery();
if(rs.next()){
return key_action;
}
else{
throw new ObjectNotFoundException ();
}
}
catch (SQLException ex) {
ex.printStackTrace();
throw new EJBException(ex);
}
}
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you read Richard Monson-Haefel's EJB book. It will explain this in great detail. In ejbLoad() you are responsible for querying the database and setting the persistent variables of your BMP that you want from the data returned by your query. The primary key found in the Entitycontext is used in the query to determine which row to get.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
dar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Kyle. It's good idea. I'll implement ejbLoad().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!