jpa中的@SqlResultSetMapping无效的列名错误

时间:2013-07-30 06:38:39

标签: hibernate jpa

我使用JOIN语句使用createNativeQuery从两个表(APPLICANT和ADDRESS)获取数据。  但是我收到了无效的列名错误。  实际情况是:

申请人类

@SqlResultSetMapping(name="menu-details",
        entities={
                 @EntityResult(entityClass=Applicant.class, fields = {
                        @FieldResult(name="id", column="APPLICANT_ID"),
                        @FieldResult(name="contactNo", column="CONTACT_NO"),
                        @FieldResult(name="dateOfBirth", column="DATE_OF_BIRTH"),
                        @FieldResult(name="name", column="APPLICANT_NAME"),
                        @FieldResult(name="status", column="STATUS")
                      }),
           @EntityResult(entityClass=AddressA.class, fields = {
                    @FieldResult(name="state", column="STATE")
            })
    }

In DAO, I am trying
String nativeQuery="select distinct (LA. APPLICANT_ID) as APPLICANT_ID, LA.CONTACT_NO       as CONTACT_NO,LA.DATE_OF_BIRTH as DATE_OF_BIRTH,LA.APPLICANT_NAME as APPLICANT_NAME,  
LA.STATUS as STATUS, LAA.STATE as STATE from loan_applicant LA,   
loan_address_a LAA where LA.applicant_id=LAA.applicant_id";  
Query q=entityManager.createNativeQuery (nativeQuery,"menu-details");
ArrayList<Applicant> menuList=new ArrayList<Applicant>();
List<Object> objects=q.getResultList();
System.out.println("the no of queries is "+objects.size());
    for(Object object:objects){
        if(object instanceof Applicant){
            Applicant applicant=(Applicant)object;
            System.out.println(applicant.getId());
            System.out.println(applicant.getName());
            System.out.println(applicant.getContactNo());
        }
        if(object instanceof  AddressA){
            AddressA address=(AddressA)object;
            System.out.println(address.getState());
        }
    }




while executing I am getting an error

Caused by: java.sql.SQLException: Invalid column name at oracle.jdbc.dbaccessdbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)

1 个答案:

答案 0 :(得分:0)

你写道:

from loan_applicant LA, loan_address_a LAA where La.applicant_id=la. applicant_id

也许你想要的是:

from loan_applicant LA, loan_address_a LAA where LA.applicant_id=LAA.applicant_id