Hi,
I too have observed this behaviour, any local fields that haven't been
declared as cmp-fields are not initialised.
I assume this is part of the performance improvements made by the jonas
team, bean instances are reused rather than created each time, hence your
"subject" may already be pointing to some other EnrollmentBean's subject and
your "if (subject != null)" returns true.
To overcome this problem you could initialise all local fields in ejbLoad(),
e.g.
public void ejbLoad() {
subject = null;
}
Don't know how this behaviour relates to the spec, I note Richard
Monson-Haefel doesn't worry about initialisation when he examples lazy
loading of beans. Can anyone comment on whether this behaviour is correct?
----- Original Message -----
From: "Blasius Lofi Dewanto" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 28, 2001 10:29 PM
Subject: Error in JOnAS 2.2.7
> Hi all,
>
> I just upgraded my Jonas from 2.0 to 2.2.7 and I
> found some inconsistencies:
>
> - With 2.0 I didn't have a problem with this code
> by an entity bean (CMP):
>
> ...
> public class EnrollmentBean implements EntityBean {
>
> // Object state
> public String subjectPK;
>
> // Just for get and set methods
> protected Subject subject;
>
> // Get the subject
> public Subject getSubject() {
> // Lazy load...
> try {
> if (subject != null) {
> return subject;
> }
> else {
> SubjectHome subjectHome =
> (SubjectHome)HomeInterfaceFactory.create(
> SubjectHome.class, SubjectHome.COMP_NAME);
> subject = subjectHome.findByPrimaryKey(new
> SubjectPK(subjectPK));
>
> return subject;
> }
> }
> catch (Exception ex) {
> throw new EJBException(res.getString("Invalid_Subject") + ex);
> }
> }
> ...
>
> And call this from my client:
>
> ...
> SubjectObject subject = (SubjectObject)enrollment.getSubject();
> ...
>
> With 2.2.7 the result of the subject is unpredictable!
> This means that the lazy load method does not work
> any longer. Why?
>
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".