Bagaiamana cara menampilkan data dari tiga tabel, menggunakan hql, berikut 
desain tabel nya

t_applicant
id_applicant
applicant_name

t_cv
id_cv
id_applicant
id_position
last_education

t_vacancy
id_position
description

saya ingin menampilkan

applicantid,applicant_name,last_education,description

ini kode nya


@Entity
@Table(name="t_applicant")
public class Applicant implements java.io.Serializable{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ID_APPLICANT")
    private long idApplicant;
        @Column(name="APPLICANT_NAME")   private String applicantName;

       @OneToOne
   @JoinColumn(name="ID_APPLICANT")
   private Cv cv;



@Entity
@Table(name="t_cv")
public class Cv implements java.io.Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID_CV")
private long idCv;

@Column(name="ID_APPLICANT")    private long idApplicant;
@Column(name="LAST_EDUCATION")  private String lastEducation;

@OneToOne
@JoinColumn(name="ID_POSITION")
private Vacancy vacancy;



@Entity
@Table(name="t_vacancy")
public class Vacancy implements java.io.Serializable{

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID_POSITION")
private Long idPosition;

@Column(name="DESCRIPTION") private String description;

perintah hql nya spt ini :
  protected List<Applicant> findAll(){
   startOperation();
   List<Applicant> applicant=null;
   try {
       applicant= HibernateConnection.session
                     .createQuery("select applicantId,applicantName, 
CV.lastEducation, "+
                                         "from Applicant as applicantId "+
                                         "inner join applicantId.Cv as idCv "+
                                         "left outer join idPosition.Vacancy as 
idPosition")
                     .list();
   }
    catch(Exception e){
                                e.printStackTrace();
                              }
    return applicant;
   }

utk menampilkannya

private void showDataApplicant(){
    applicantDao = new ApplicantDao();
    applicantDao.findAll();
     try{
        List<Applicant> applicant;
        applicant = applicantDao.findAll("showUser()");
        int x = 0;
        Object[][] data = new Object[applicant.size()][4];
        for(Applicant a : applicant){
              data[x][0] = a.getIdApplicant();
              data[x][1] = a.getApplicantName();
              data[x][2] = a.getCv().getLastEducation();
              data[x][3] = a.getCv().getVacancy().getDescription();
              ++x;
         }
         tblApplicant.setModel(new 
javax.swing.table.DefaultTableModel(data,JDLApplicanLang.header){
                         boolean[] canEdit = new boolean [] {
                         false, false, false
                         };

                         public boolean isCellEditable(int rowIndex, int 
columnIndex) {
                                return canEdit [columnIndex];
                                }
                          });
        }catch(Exception e){e.printStackTrace();
                           }
        }
   errornya 

2008-10-29 17:06:35,593 [AWT-EventQueue-0] ERROR org.hibernate.hql.PARSER line 
1:53: unexpected token: from
2008-10-29 17:06:35,609 [AWT-EventQueue-0] ERROR org.hibernate.hql.PARSER line 
1:118: unexpected token: inner
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: from near line 1, 
column 53 [select applicantId,applicantName, CV.lastEducation, from 
mst.hrd.hibernate.model.annotation.Applicant as applicantId inner join 
applicantId.Cv as idCv left outer join idPosition.Vacancy as idPosition]
        at 
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
        at 
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
        at 
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
        at 
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
        at 
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
        at 
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
        at 
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
      




      Ada Naruto, Sandra Dewi dan MU di Yahoo! Indonesia Top Searches 2008. 
http://id.promo.yahoo.com/topsearches2008

Kirim email ke