• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

could I call findByPrimaryKey() without create()

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Kyle. It's good idea. I'll implement ejbLoad().
 
catch it before it slithers away! Oh wait, it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic