IntelliJ Java IDE
The moose likes EJB and Other Java EE Technologies and the fly likes could I call findByPrimaryKey() without create() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "could I call findByPrimaryKey() without create()" Watch "could I call findByPrimaryKey() without create()" New topic
Author

could I call findByPrimaryKey() without create()

dar
Ranch Hand

Joined: Nov 08, 2001
Posts: 45
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

Joined: Aug 10, 2001
Posts: 3878
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.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
dar
Ranch Hand

Joined: Nov 08, 2001
Posts: 45
Thank You Kyle. It's good idea. I'll implement ejbLoad().
 
 
subject: could I call findByPrimaryKey() without create()
 
Threads others viewed
How to put Row level lock in java while inserting a row in MSSQL table
BMP, Jboss, and mysql configuring
ejbFind() in Entity Bean
Exception
Out of Memory when testing a BMP Bean
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture