1 Reply Latest reply on Oct 11, 2001 10:55 PM by Erik Sliman

    Entity bean's ejbLoad not being invoked

    Erik Sliman Apprentice

      I am running Sun's Enroller tutorial in JBoss. So far I have been able to get each tutorial to work. This one works, halfway. The problem:

      ejbLoad() is never called on an EJB that is created, yet it depends on this for transactional integrity. Once an entity is created, it may get children assigned to it from another user. It should
      be able to see any newly added children, and depends on ejbLoad() for this. Additionally, this is taken
      from a tutorial where it presumably works on another server. So, is this a JBoss bug?

      In this example, you have three tables, and three EJBs.

      Student (Entity) --> Enroller (Session) <-- Course (Entity)

      The Student and Course EJBs are virtually identical, with the exception that where Student references courses, Course references students. They both derive each from the Enroller.

      I don't have any problems when I use findByPrimaryKey on an entity, just when it is instantiated with ejbCreate(). In this latter case, ejbLoad NEVER gets called, not matter how many business functions I call on it later, or even if it is later instantiated again from the client with findByPrimaryKey().

      Both Course and Student have their transaction set to 'Required' on the business methods, including the counterpart methods, Student.getCourseIds() and Course.getStudentIds().

      In the client, a JSP, I create a Student and a Course, adding to students and courses already loaded in the database. I then create entries in Enroll intersecting various students with courses. Then, I try to grab and display the courses the created student is enrolled in, and this fails because ejbLoad on that instance is never called. I then grab and display the students belonging to the course that was created, and this succeeds because ejbLoad is called. Furthermore, each student instance that belongs to the course has its ejbLoad called successfully, except for the one where the primary key matches the initially created student.

      In case you haven't figured out the solution, yet, and are generous enough to want to continue to try to help, here is the log output where I discovered the problem of ejbLoad not being invoked on the initial Student instance. Although this log doesn't include it, I later had it try to get the students for the course initially created, and it had the same problem. Likewise, I tried to obtain courses from a student loaded with findByPrimaryKey, but never created, and it worked. So it is clear that the problem is with instances initially created.

      ; Client creates Course:
      ; Course power = cHome.create("220", "Power J2EE Programming");

      [MySQLDB] Pool MySQLDB [1/1/200] gave out pooled object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@53fb57
      [Default] CourseBean: in ejbCreate for 220 - Power J2EE Programming
      [Default] CourseBean: about to leave ejbCreate
      [Default] StudentBean: in setEntityContext

      ; Client creates Student:
      ; Student denise = sHome.create("823", "Denise Smith");

      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] No transaction right now.
      [MySQLDB] Pool MySQLDB [1/1/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@3a83cc

      [Default] StudentBean: in ejbCreate for 823 - Denise Smith
      [Default] StudentBean: about to leave ejbCreate

      ; Client adds enrollments:
      ; Enroller enroller = eHome.create();
      ; enroller.enroll("823", "220");
      ; enroller.enroll("823", "333");
      ; enroller.enroll("823", "777");
      ; enroller.enroll("456", "777");
      ; enroller.enroll("388", "777");

      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] Resource 'org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl@3c9673' enlisted for 'org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@21b42f'.
      [MySQLDB] Pool MySQLDB [2/2/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@21b42f
      [Default] EnrollerBean: in enroll, enrolling student 823, course 220
      [Default] EnrollerBean: in insertEntry, inserted student 823, course 220
      [Default] EnrollerBean: in enroll, enrolling student 823, course 333
      [Default] EnrollerBean: in insertEntry, inserted student 823, course 333
      [Default] EnrollerBean: in enroll, enrolling student 823, course 777
      [Default] EnrollerBean: in insertEntry, inserted student 823, course 777
      [Default] EnrollerBean: in enroll, enrolling student 456, course 777
      [Default] EnrollerBean: in insertEntry, inserted student 456, course 777
      [Default] EnrollerBean: in enroll, enrolling student 388, course 777
      [Default] EnrollerBean: in insertEntry, inserted student 388, course 777

      ; Client tries to get courses for original student it created. Notice it does not invoke ejbLoad!!
      ; courses = denise.getCourseIds();

      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore
      [Default] StudentBean: in getCourseIds for Denise Smith with 0 courses
      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore

      ; Client locates a course:
      ; Course intro = cHome.findByPrimaryKey("777");

      [Default] CourseBean: in setEntityContext
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] No transaction right now.
      [MySQLDB] Pool MySQLDB [3/3/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6d54a0
      [Default] CourseBean: in ejbFindByPrimaryKey for 777
      [Default] CourseBean: ejbActivate called for courseId 777
      [CourseEJB] Activated bean CourseEJB with id = 777
      [Default] CourseBean: in ejbLoad for 777
      [Default] CourseBean: in loadCourse for 777
      [Default] CourseBean: in loadStudentIds for 777
      [Default] CourseBean: in loadStudentIds, about to try
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] Resource 'org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl@32b450' enlisted for 'org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6e3e28'.
      [MySQLDB] Pool MySQLDB [4/4/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6e3e28
      [Default] EnrollerBean: in getStudentIds for 777
      [Default] CourseBean: in loadStudentIds for 777 - An Introduction to Java Programming, students found: 3
      [Default] CourseBean: leaving loadStudentIds
      [Default] CourseBean: leaving ejbLoad
      [Default] CourseBean: in ejbStore for course 777
      [Default] CourseBean: leaving ejbStore
      [Default] CourseBean: in getStudentIds
      [Default] CourseBean: in ejbStore for course 777
      [Default] CourseBean: leaving ejbStore

      ; Client loads the students belonging to the course:

      [Default] StudentBean: in setEntityContext
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] No transaction right now.
      [MySQLDB] Pool MySQLDB [5/5/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6fa490
      [Default] StudentBean: in ejbFindByPrimaryKey for 388
      [Default] StudentBean: ejbActivate called for studentId 388
      [StudentEJB] Activated bean StudentEJB with id = 388
      [Default] StudentBean: in ejbLoad for 388
      [Default] StudentBean: in loadStudent for 388
      [Default] StudentBean: in loadCourseIds for 388 - Elizabeth Willis
      [Default] StudentBean: in loadCourseIds, about to try
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] Resource 'org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl@547f59' enlisted for 'org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6f45e0'.
      [MySQLDB] Pool MySQLDB [6/6/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@6f45e0
      [Default] EnrollerBean: in getCourseIds for student 388
      [Default] EnrollerBean: in selectCourse for 388
      [Default] EnrollerBean: in selectCourse - SQL: select courseid from enrollment where studentid = ?
      [Default] EnrollerBean: in selectCourse for 388 - course: 777
      [Default] StudentBean: in loadCourseIds for 388 - Elizabeth Willis, courses found: 1
      [Default] StudentBean: leaving loadCourseIds
      [Default] StudentBean: leaving ejbLoad
      [Default] StudentBean: in ejbStore for student 388
      [Default] StudentBean: leaving ejbStore
      [Default] StudentBean: in setEntityContext
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] No transaction right now.
      [MySQLDB] Pool MySQLDB [7/7/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@5c2fee
      [Default] StudentBean: in ejbFindByPrimaryKey for 456
      [Default] StudentBean: ejbActivate called for studentId 456
      [StudentEJB] Activated bean StudentEJB with id = 456
      [Default] StudentBean: in ejbLoad for 456
      [Default] StudentBean: in loadStudent for 456
      [Default] StudentBean: in loadCourseIds for 456 - Joe Smith
      [Default] StudentBean: in loadCourseIds, about to try
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] Resource 'org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl@12d7ae' enlisted for 'org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@3a5a9c'.
      [MySQLDB] Pool MySQLDB [8/8/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@3a5a9c
      [Default] EnrollerBean: in getCourseIds for student 456
      [Default] EnrollerBean: in selectCourse for 456
      [Default] EnrollerBean: in selectCourse - SQL: select courseid from enrollment where studentid = ?
      [Default] EnrollerBean: in selectCourse for 456 - course: 777
      [Default] StudentBean: in loadCourseIds for 456 - Joe Smith, courses found: 1
      [Default] StudentBean: leaving loadCourseIds
      [Default] StudentBean: leaving ejbLoad
      [Default] StudentBean: in ejbStore for student 456
      [Default] StudentBean: leaving ejbStore
      [Default] StudentBean: in setEntityContext
      [MySQLDB] org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl created new Connection (org.gjt.mm.mysql.jdbc2.Connection) with XAResource org.jboss.pool.jdbc.xa.wrapper.XAResourceImpl and XAConnection org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl.
      [MySQLDB] No transaction right now.
      [MySQLDB] Pool MySQLDB [9/9/200] gave out new object: org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@7e30af
      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore
      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore

      ; created student still fails to return her courses because ejbLoad() still hasn't been called:

      [Default] StudentBean: in getCourseIds for Denise Smith with 0 courses
      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore
      [Default] StudentBean: in ejbStore for student 823
      [Default] StudentBean: leaving ejbStore

        • 1. Re: Entity bean's ejbLoad not being invoked
          Erik Sliman Apprentice

          Note, in the above one paragraph incorrectly states that ejbLoad() was successfully invoked on the Course initially created. I did diagnosis in the middle of writing it, tried to rewrite it, but missed that. To make it clear:

          It NEVER calls ejbLoad() at any time on any entity bean that previously had ejbCreate() invoked! This is true even if you later use findByPrimaryKey() to get a reference to it!

          It does call ejbLoad() on instances created with findByPrimaryKey(), where the instance has never been previously created with ejbCreate().

          It is clear the find methods will grab a cached entity bean if it can match one up by the primary key, and whatever causes the problem to begin with is still there. This makes finding a work-around very difficult.