简体   繁体   中英

When i try to execute createSQLQuery() coming this exception Caused by: java.sql.SQLException: Invalid column name

hql = "SELECT USER_CODE, USER_NAME, USER_SHORT_NAME, PRINT_NAME, USER_PASSWORD, REMARKS, RECORD_ACTIVE,"+
                        " INACTIVE_WEF, CREATED_BY, CREATED_ON, MODIFIED_BY, MODIFIED_ON " +
                        "(SELECT DESGN_NAME FROM MCDESIGNATIONMASTER WHERE DESGN_CODE = :DESIGNATION_CODE)TSUSERMASTER_DESIGNATION " +
                        " FROM MCUSERMASTER WHERE USER_CODE LIKE NVL(:USER_CODE,'%') AND USER_NAME LIKE NVL(:USER_NAME,'%')";
                System.out.println("hql----"+hql);
                Query query = session.createSQLQuery(hql).addEntity(UserMasterModel.class).setParameter("USER_CODE",roleMasterModel.getUserCode()).setParameter("USER_NAME", roleMasterModel.getUserName());
  1. You missed a comma after MODIFIED_ON, but it's difficult to see it without an SQL code indentation:

  2. You can't mix column selects with query results. What if the second query returns more than one row.

  3. You only use two parameters USER_CODE and USER_NAME, but your second subselect adds one more (DESIGNATION_CODE) and you never supply its value.

  4. Since there is no correlation between those two queries I think this is what you must have:

     Query mcMasterQuery = session .createSQLQuery( "SELECT "+ " USER_CODE, "+ " USER_NAME, "+ " USER_SHORT_NAME, "+ " PRINT_NAME, "+ " USER_PASSWORD, "+ " REMARKS, "+ " RECORD_ACTIVE, "+ " INACTIVE_WEF, "+ " CREATED_BY, "+ " CREATED_ON, "+ " MODIFIED_BY, "+ " MODIFIED_ON "+ "FROM MCUSERMASTER "+ "WHERE "+ " USER_CODE LIKE NVL(:USER_CODE,'%') AND "+ " USER_NAME LIKE NVL(:USER_NAME,'%')" ) .addEntity(UserMasterModel.class) .setParameter("USER_CODE", roleMasterModel.getUserCode()) .setParameter("USER_NAME", roleMasterModel.getUserName()); Query mcDesignationQuery = session .createSQLQuery( "SELECT " + " DESGN_NAME " + "FROM MCDESIGNATIONMASTER " + "WHERE " + " DESGN_CODE = :DESIGNATION_CODE" ) .addEntity(UserMasterModel.class) .setParameter("DESIGNATION_CODE", designationCode); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM