0

这是我正在使用 hiberante 运行的查询:

String sqlStr = "SELECT {User.*}," +
                           "{Address.*}  from T_USER_DETAILS2 US,T_ADDRESS_DETAILS AD where US.ADDRESS_ID = AD.ADDRESS_ID" +
                           " AND US.USER_FIRSTNAME = :firstname";

    SQLQuery sql =  session.createSQLQuery(sqlStr).addEntity("User",User.class).addEntity("Address",Address.class);
    sql.setParameter("firstname", firstname);

    System.out.println("Query created, now executing the query in the database");

    List<Object[]> list = sql.list();

这是hibernate生成的查询:

Hibernate: 
    /* dynamic native SQL query */ SELECT
        User.USER_ID as USER1_1_0_,
        User.ADDRESS_ID as ADDRESS9_1_0_,
        User.USER_AGE as USER2_1_0_,
        User.USER_EMAIL as USER3_1_0_,
        User.USER_FIRSTNAME as USER4_1_0_,
        User.USER_LASTNAME as USER5_1_0_,
        User.USER_PASSWORD as USER6_1_0_,
        User.USER_COUNTRY_CODE as USER7_1_0_,
        User.USER_PHONE as USER8_1_0_,
        Address.ADDRESS_ID as ADDRESS1_0_1_,
        Address.ADDRESS_LINE1 as ADDRESS2_0_1_,
        Address.ADDRESS_LINE2 as ADDRESS3_0_1_,
        Address.CITY as CITY0_1_,
        Address.COUNTRY as COUNTRY0_1_,
        Address.STATE as STATE0_1_  
    from
        T_USER_DETAILS2 US,
        T_ADDRESS_DETAILS AD 
    where
        US.ADDRESS_ID = AD.ADDRESS_ID 
        AND US.USER_FIRSTNAME = ?

我收到此错误:

捕获:org.hibernate.exception.SQLGrammarException:ORA-00923:FROM 关键字未在预期的位置找到

我知道当我们错过 select 子句中的一些逗号时会出现此错误。但我可以看到选择中的一切都很完美。任何人都可以在这方面帮助我。

4

1 回答 1

3

当我<property name="validationQuery" value="SELECT 1"/>从数据源 bean 中删除时,它对我有用。您也可以将其更改为SELECT 1 from DUAL.

于 2013-08-28T15:40:56.057 回答