troubleshooting Question

EJB Entity Bean - from a database View did not create a primary key class but needs one

Avatar of Caro0101
Caro0101Flag for Canada asked on
JavaJava EE
6 Comments1 Solution559 ViewsLast Modified:
I hope someone can help..

I have a view which is grabbing information from many tables it does a union to retrieve all the units with multiple instructors associated to it and all the units without. Find below the view:

CREATE OR REPLACE VIEW QV_ADMIN_UNIT_LIST ( UNIT_KEY,
COURSE_NAME, TERM_YEAR, CD_SESSION_DSC_TX, COURSE_PREFIX,
COURSE_SUFFIX, CD_LOCATION_DESC, IS_DISPLAYED, FK_COURSE_TYPE_KEY,
FK_TERM_KEY, FK_DEPT_KEY, FK_CD_LOCATION_KEY, SORT_ORDER,
FK_SESSION_KEY, LOCATION_SORT_ORDER, TERM_END_DT, COURSE_TYPE_DESC,
FK_COURSE_KEY, FK_STATUS_KEY, FK_SECTION_KEY, WEIGHT_DESC,
SECTION_DESC, INSTRUCTOR_KEY, INSTRUCTOR_LAST_NAME, INSTRUCTOR_FIRST_NAME
 ) AS SELECT u.unit_key, c.course_name, t.term_year, s.cd_session_dsc_tx, c.course_prefix, c.course_suffix, l.cd_location_desc, u.is_displayed, c.fk_course_type_key, u.fk_term_key, u.fk_dept_key, u.fk_cd_location_key, ct.sort_order, t.fk_cd_session_key,l.sort_order, t.term_end_dt, ct.course_type_dsc_tx, u.fk_course_key, u.fk_cd_unit_status_key, u.fk_cd_section_key, w.cd_weight_dsc_tx, cs.cd_section_code, i.instructor_key, qp.last_name, qp.first_name                
FROM CRSE_UNIT u, CRSE_COURSE c, CRSE_TERM t, CD_SESSION s, CD_LOCATION l, CD_COURSE_TYPE ct, CD_WEIGHT w, CD_SECTION cs, CRSE_UNIT_INSTRUCTOR_TEACHES uit,INSTR_INSTRUCTOR i, qperson qp      
WHERE c.course_key = u.fk_course_key AND              
        l.cd_location_key = u.fk_cd_location_key AND              
        t.term_key = u.fk_term_key AND            
        t.fk_cd_session_key = s.cd_session_key AND            
        ct.course_type_key = c.fk_course_type_key AND    
        c.fk_cd_weight_key = w.cd_weight_key AND  
        u.fk_cd_section_key = cs.cd_section_key AND
        uit.fk_instructor_key = i.instructor_key AND
        i.ce_number = qp.userid AND
        u.unit_key = uit.fk_unit_key(+)
UNION ALL  
SELECT u.unit_key, c.course_name, t.term_year, s.cd_session_dsc_tx, c.course_prefix, c.course_suffix, l.cd_location_desc, u.is_displayed, c.fk_course_type_key, u.fk_term_key, u.fk_dept_key, u.fk_cd_location_key, ct.sort_order, t.fk_cd_session_key,l.sort_order, t.term_end_dt, ct.course_type_dsc_tx, u.fk_course_key, u.fk_cd_unit_status_key, u.fk_cd_section_key, w.cd_weight_dsc_tx, cs.cd_section_code, TO_NUMBER(NULL),TO_CHAR(NULL), TO_CHAR(NULL)              
FROM CRSE_UNIT u, CRSE_COURSE c, CRSE_TERM t, CD_SESSION s, CD_LOCATION l, CD_COURSE_TYPE ct, CD_WEIGHT w, CD_SECTION cs, CRSE_UNIT_INSTRUCTOR_TEACHES uit
WHERE c.course_key = u.fk_course_key AND              
        l.cd_location_key = u.fk_cd_location_key AND              
        t.term_key = u.fk_term_key AND            
        t.fk_cd_session_key = s.cd_session_key AND            
        ct.course_type_key = c.fk_course_type_key AND    
        c.fk_cd_weight_key = w.cd_weight_key AND  
        u.fk_cd_section_key = cs.cd_section_key AND
        u.unit_key = uit.fk_unit_key(+) AND
        uit.fk_instructor_key IS NULL
ORDER BY u.unit_key




My problem is that when I built the Entity bean from the view it did not create a Primary key class which it will actually need one since the unit_key is no longer unique since you can have multiple
instructors for a unit..

here is the classes it built:

package ca.queensu.conted.impl;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import java.sql.Timestamp;

public abstract class Qv_admin_unit_listBean implements EntityBean
{
  private EntityContext context;

  public Long ejbCreate()
  {
    return null;
  }

  public void ejbPostCreate()
  {
  }

  public void ejbActivate()
  {
  }

  public void ejbLoad()
  {
  }

  public void ejbPassivate()
  {
  }

  public void ejbRemove()
  {
  }

  public void ejbStore()
  {
  }

  public void setEntityContext(EntityContext ctx)
  {
    this.context = ctx;
  }

  public void unsetEntityContext()
  {
    this.context = null;
  }

  public abstract Long getUnit_key();

  public abstract void setUnit_key(Long newUnit_key);

  public abstract String getCourse_name();

  public abstract void setCourse_name(String newCourse_name);

  public abstract String getTerm_year();

  public abstract void setTerm_year(String newTerm_year);

  public abstract String getCd_session_dsc_tx();

  public abstract void setCd_session_dsc_tx(String newCd_session_dsc_tx);

  public abstract String getCourse_prefix();

  public abstract void setCourse_prefix(String newCourse_prefix);

  public abstract String getCourse_suffix();

  public abstract void setCourse_suffix(String newCourse_suffix);

  public abstract String getCd_location_desc();

  public abstract void setCd_location_desc(String newCd_location_desc);

  public abstract String getIs_displayed();

  public abstract void setIs_displayed(String newIs_displayed);

  public abstract Long getFk_course_type_key();

  public abstract void setFk_course_type_key(Long newFk_course_type_key);

  public abstract Long getFk_term_key();

  public abstract void setFk_term_key(Long newFk_term_key);

  public abstract Long getFk_dept_key();

  public abstract void setFk_dept_key(Long newFk_dept_key);

  public abstract Long getFk_cd_location_key();

  public abstract void setFk_cd_location_key(Long newFk_cd_location_key);

  public abstract Long getSort_order();

  public abstract void setSort_order(Long newSort_order);

  public abstract Long getFk_session_key();

  public abstract void setFk_session_key(Long newFk_session_key);

  public abstract Long getLocation_sort_order();

  public abstract void setLocation_sort_order(Long newLocation_sort_order);

  public abstract Timestamp getTerm_end_dt();

  public abstract void setTerm_end_dt(Timestamp newTerm_end_dt);

  public abstract String getCourse_type_desc();

  public abstract void setCourse_type_desc(String newCourse_type_desc);

  public abstract Long getFk_course_key();

  public abstract void setFk_course_key(Long newFk_course_key);

  public abstract Long getFk_status_key();

  public abstract void setFk_status_key(Long newFk_status_key);

  public abstract Long getFk_section_key();

  public abstract void setFk_section_key(Long newFk_section_key);

  public abstract String getWeight_desc();

  public abstract void setWeight_desc(String newWeight_desc);

  public abstract String getSection_desc();

  public abstract void setSection_desc(String newSection_desc);

  public abstract Long getInstructor_key();

  public abstract void setInstructor_key(Long newInstructor_key);

  public abstract String getInstructor_last_name();

  public abstract void setInstructor_last_name(String newInstructor_last_name);

  public abstract String getInstructor_first_name();

  public abstract void setInstructor_first_name(String newInstructor_first_name);
}

package ca.queensu.conted;
import javax.ejb.EJBLocalObject;
import java.sql.Timestamp;

public interface Qv_admin_unit_listLocal extends EJBLocalObject
{
  Long getUnit_key();

  void setUnit_key(Long newUnit_key);

  String getCourse_name();

  void setCourse_name(String newCourse_name);

  String getTerm_year();

  void setTerm_year(String newTerm_year);

  String getCd_session_dsc_tx();

  void setCd_session_dsc_tx(String newCd_session_dsc_tx);

  String getCourse_prefix();

  void setCourse_prefix(String newCourse_prefix);

  String getCourse_suffix();

  void setCourse_suffix(String newCourse_suffix);

  String getCd_location_desc();

  void setCd_location_desc(String newCd_location_desc);

  String getIs_displayed();

  void setIs_displayed(String newIs_displayed);

  Long getFk_course_type_key();

  void setFk_course_type_key(Long newFk_course_type_key);

  Long getFk_term_key();

  void setFk_term_key(Long newFk_term_key);

  Long getFk_dept_key();

  void setFk_dept_key(Long newFk_dept_key);

  Long getFk_cd_location_key();

  void setFk_cd_location_key(Long newFk_cd_location_key);

  Long getSort_order();

  void setSort_order(Long newSort_order);

  Long getFk_session_key();

  void setFk_session_key(Long newFk_session_key);

  Long getLocation_sort_order();

  void setLocation_sort_order(Long newLocation_sort_order);

  Timestamp getTerm_end_dt();

  void setTerm_end_dt(Timestamp newTerm_end_dt);

  String getCourse_type_desc();

  void setCourse_type_desc(String newCourse_type_desc);

  Long getFk_course_key();

  void setFk_course_key(Long newFk_course_key);

  Long getFk_status_key();

  void setFk_status_key(Long newFk_status_key);

  Long getFk_section_key();

  void setFk_section_key(Long newFk_section_key);

  String getWeight_desc();

  void setWeight_desc(String newWeight_desc);

  String getSection_desc();

  void setSection_desc(String newSection_desc);

  Long getInstructor_key();

  void setInstructor_key(Long newInstructor_key);

  String getInstructor_last_name();

  void setInstructor_last_name(String newInstructor_last_name);

  String getInstructor_first_name();

  void setInstructor_first_name(String newInstructor_first_name);
}

package ca.queensu.conted;
import javax.ejb.EJBLocalHome;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import java.util.Collection;

public interface Qv_admin_unit_listLocalHome extends EJBLocalHome
{
  Qv_admin_unit_listLocal create() throws CreateException;

  Qv_admin_unit_listLocal findByPrimaryKey(Long primaryKey) throws FinderException;

  Collection findAll() throws FinderException;

  Collection findAllUnitDynamically(Long courseKey, Long termKey, Long courseTypeKey, Long sectionKey, Long statusKey, Long locationKey, Long instructorKey, Long deptKey) throws FinderException;
}


It made the unit_key the primary key.. which means when I loop through the unitLocal it always return the first one.. The only difference between the records is that one will have instructors and others won't so will have a null key for the instructor_key so I can't make that the primary key..

Is there a way to create a primary key class based on the unit_key & the instructor_key which are both LONG datatype.. I attempted this but it kept failing on me..


Thanks in advance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros