shashi
shashi

Reputation: 201

SQL query not working in hibernate : ORA-00923: FROM keyword not found where expected

here is my query which i am running using 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();

here is the query generated by 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 = ?

I am getting this error:

Caught : org.hibernate.exception.SQLGrammarException: ORA-00923: FROM keyword not found where expected

i know this error comes when we miss some comma in select clause. but i can see everything is perfect in the select. Could any one assist me on this.

Upvotes: 0

Views: 2432

Answers (1)

Hari
Hari

Reputation: 277

It worked for me when i removed <property name="validationQuery" value="SELECT 1"/> from the datasource bean. You can also change it to SELECT 1 from DUAL.

Upvotes: 3

Related Questions