My BMP does not throw a finderException if the bean is not found.
It did work in 2.0_Final but not PRE2.1.
It may have something to do with the new optimization and how my BMP is implemented
In My BMP findByPrimaryKey method, I do the following:
1. Immediately print a log message
2. Thow a FinderExecption if no row is found
When I call findByPrimaryKey from the client:
1. I never see the log message
2. If the bean exists, I do get the correct reference
3. If the bean does not exist,
-- no finder exception is thrown
--It does return a remote interface reference
--If I try to call a get method on the remote interface, ejbLoad throws a
RemoteException as I would expect.
In other words, I have no way of telling if the bean does not exist unless a remote
exception is thrown from ejbLoad after trying to access a field using a get method.
Then, my current transaction rolls back.
Can someone tell me what I may be doing wrong. Here is my finder metod.
Thanks for your time.
/************************************************************
* finder methods
************************************************************/
/**
* Find by a primary key
*/
public Tbh3LstPk ejbFindByPrimaryKey(Tbh3LstPk pk) throws FinderException,
RemoteException {
log("ejbFindByPrimaryKey");
PreparedStatement ps = null;
//set class level variables to primary key values
this.cmpy = pk.cmpy;
this.btch_num = pk.btch_num;
this.pk = pk
try {
connection = dataSource.getConnection();
String sql =
"SELECT "
+ "CMPY, "
+ "BTCH_NUM "
+ "FROM TBH3LST "
+ "WHERE "
+ "CMPY= '" + pk.cmpy + "' "
+ "AND BTCH_NUM= " + pk.btch_num + " ";
ps = connection.prepareStatement(sql);
//set primary key in prepared statement
log(sql);
ps.executeQuery();
ResultSet rs = ps.getResultSet();
if (rs.next()) {
//set class level variables
this.cmpy = rs.getString(1);
this.btch_num = rs.getInt(2);
log("ejbFindByPrimaryKey: found");
} else {
log("ejbFindByPrimaryKey: not found");
throw new FinderException();
}
} catch (SQLException sqe) {
log("SQLException: " + sqe);
throw new EJBException(sqe);
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {e.printStackTrace();}
}
this.modified = false;
return pk;
}
Paul Russo wrote:
> I guess I got confused because I never see a log message from findByPrimaryKey
> from my print statement.
> I would expect to see at least one log message the fist time the bean is loaded.
>
> I would like to see the log so I know what sql gets issued.
> The call to ejbLoad was not related to the findByPrimaryKey. :)
> After I findByPrimaryKey, I call a get method and then I see ejbLoad log message
>
> public TbcAddrPk ejbFindByPrimaryKey(TbcAddrPk pk)
> throws FinderException, RemoteException {
> log("ejbFindByPrimaryKey"); // ** I never see this
> ->> added this line this.pk = pk;
> .....
> }
>
> marc fleury wrote:
>
> > The passivation with the id null is a fixed bug
> >
> > the findByPK is an optimization that was put in recently. If your bean is
> > already in cache then we don't issue a findByPK but we ping the instance in
> > cache instead.
> >
> > That ejbLoad is called is strange (on a findByPK) are you sure about that?
> > there should be no call on your target bean at all (in fact sometimes there
> > isn't a target bean) please verify that on a duplicate findByPK you get that
> > called....
> >
> > marc
> >
> > |-----Original Message-----
> > |From: [EMAIL PROTECTED]
> > |[mailto:[EMAIL PROTECTED]]On Behalf Of Paul Russo
> > |Sent: Sunday, December 03, 2000 7:47 AM
> > |To: jBoss
> > |Subject: [jBoss-User] PRE-2.1 BMP findByPrimaryKey
> > |
> > |
> > |I built sources PRE-2.1 from cvs on 12/3
> > |The findByPrimaryKey method in my BMP implimentation is not being called
> > |
> > |when I issue the call from the client. It appears that ejbLoad is
> > |getting called instead.
> > |It works fine in jBoss-2.0_FINAL. The findByPrimaryKey method gets
> > |called but not the ejbStore.
> > |
> > |In a possible unrelated observation, my beans are benig passivated with
> > |id = null in jBoss-2.0_FINAL.
> > |In PRE-2.1, passivated beans the have the id = primary key class id.
> > |
> > |I was wondering if i'm doing something wrong.
> > |
> >
> > --
> > --------------------------------------------------------------
> > To subscribe: [EMAIL PROTECTED]
> > To unsubscribe: [EMAIL PROTECTED]
> > Problems?: [EMAIL PROTECTED]
>
> --
> --------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Problems?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]