We help IT Professionals succeed at work.

Invalid sql error in Hibernate

prsubject
prsubject asked
on
3,841 Views
Last Modified: 2013-11-11
 My Named query -->            <sql-query name="validateAccount">
                                                     FROM  Acct a WHERE  a.acct_Nbr= :acctnum
                                                </sql-query>

Output
FROM
    Acct a
WHERE
    a.acct_Nbr= ?
2203 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 900, SQLState: 42000
2203 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00900: invalid SQL statement
Comment
Watch Question

Author

Commented:
My java code is



	public boolean isAccountEnabled(String acct)
	{
		boolean accountEnabled=false;
		Session session = getSession();
		Query query = session.getNamedQuery("com.main.test.entity.Acct.validateAccount");
		query.setString("acctnum", acct);
                //retriving Acct object from List
		Acct account=(Acct) query.list().get(0); 

		if(account!=null && account.getAcctStatus().equals("1"))
			accountEnabled=true;
		
		session.close();
		return accountEnabled;
	}

Open in new window

Author

Commented:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2297)
Top Expert 2010

Commented:
If it is an SQL, not HQL, query, it's got to start with SELECT..

Author

Commented:
I tried the
        <sql-query name="validateAccount">
            SELECT FROM  Acct a WHERE  a.acct_Nbr= :acctnum
        </sql-query>

I am getting the fiollowing error

2032 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 936, SQLState: 42000
2032 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00936: missing expression

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2297)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
    at org.hibernate.loader.Loader.list(Loader.java:2167)

Author

Commented:
I want the query to return list of Acct objects
Top Expert 2010

Commented:
Please post your Acct class and Hibernate mapping file

Author

Commented:

public class Acct implements java.io.Serializable {


     private Long acctSid;
     private String acct_Nbr;
     private String firstName;
     private String lastName;
}

//hbm file
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.main.best.entity.Acct" table="ACCT" schema="DEVRDC1SO">
        <id name="acctSid" type="java.lang.Long">
            <column name="ACCT_SID" precision="18" scale="0" />
            <generator class="assigned" />
        </id>
        
        <property name="acctNbr" type="java.lang.String">
            <column name="ACCT_NBR" length="20" not-null="true" />
        </property>

        <property name="firstName" type="java.lang.String">
            <column name="FIRST_NAME" length="30" />
        </property>
        <property name="lastName" type="java.lang.String">
            <column name="LAST_NAME" length="30" />
        </property>

<sql-query name="validateAccount">
    		FROM  Acct as a WHERE  a.acct_Nbr= :acctnum
		</sql-query>
  		
    </class>
</hibernate-mapping>

Open in new window

Top Expert 2010

Commented:
Is there a reason for the query to be an SQL query ? It would be better to use HQL:

<query name="validateAccount">
                FROM  Acct as a WHERE  a.acct_Nbr= :acctnum
</query>

P.S. Your SQL with SELECT is invalid anyway as it does not define any SELECT field list.

Author

Commented:
FROM  Acct as a WHERE  a.acct_Nbr= :acctnum --> even my query is the same.I posted it earlier
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.