Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • 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().
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic