Link to home
Start Free TrialLog in
Avatar of arkhls
arkhls

asked on

Hibernate Exception : HQL uses underscore for SQL server table separator,Could not execute query

Hibernate HQL uses underscore for SQL server  schema separator,
  When  I try to run  the HQL --->   list = session.createQuery(" from Trade").list();
 I'm getting  " could not executed query"  but when I look at the execption I do not underestand how come my  table name is changed from Trade to Trade0_
  below is all my hibernate configuration file
 
 
 EXCEPTION
----------
  Hibernate:  select trade0_.TradeID as TradeID0_, trade0_.SecurityID as SecurityID0_,
        trade0_.Description as Descript3_0_,trade0_.Symbol as Symbol0_,
        org.hibernate.exception.SQLGrammarException: could not execute query
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.loader.Loader.doList(Loader.java:2223)
       at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)

 
Hibernate COnfiguration :

hibernate.cfg.xml
-----------------
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
        <property name="hibernate.connection.password">abcd123</property>
        <property name="hibernate.connection.url">jdbc:jtds:sqlserver://ssdevelopmenetl:1433/DPP</property>
        <property name="hibernate.connection.username">a_dpp</property>
        <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>    
        <property name="current_session_context_class">thread</property>        
        <property name="show_sql">true</property>      
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>        
      <property name="hibernate.hbm2ddl.auto">update</property>
       
        <mapping class="ca.dpp.hibernate.model.Trade"  resource="ca/dpp/hibernate/resources/DppTrade.hbm.xml"  />
    </session-factory>
</hibernate-configuration>
 
Trade.hbm.xml
 -------------------
 <hibernate-mapping package="ca.dpp.hibernate.model">
   <class name="ca.dpp.hibernate.model.Trade" schema="DPP">
          <id column="TradeID" name="tradeId" type="int">
          <generator class="native"/>
          </id>
          <property  name="securityId">
                <column name="SecurityID"/>
          </property>
 
         <property  name="description"  >
              <column name="Description"/>
         </property>
 
         <property  name="symbol" >
             <column name="Symbol"/>
        </property>
  </class>
 </hibernate-mapping>




Avatar of arkhls
arkhls

ASKER

I just tried below code but the Exception is the same and Strig[] x = quesry.getNamedParameters() returns zero value;

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();            
Query query = session.createQuery(" from Trade");
String x[] = query.getNamedParameters();
 list =  query.list();
Avatar of Mick Barry
add table attibute

   

Avatar of arkhls

ASKER

Hi
well I just tried  table attribute="trade" , but the same exception ,also  tested the same configuration in MySQL and code ran just fine , so I really do not know what the problem is , I'm using Eclipse hibernate plugin and everything seems fine and there is no exception or crashed in hibernate console but when comes to actual code , Query is not created

have you checked the whole query? you only posted half of it above.

Sounds like the problem is in your db, check your schema.

Avatar of arkhls

ASKER

Sorry  I did not get you , Here is teh code I;m trying to run :  I did both with Query  query = session.createQuery("from Trade");  and also List list = session.createQuery("Trade").list();

to see what is in query object please check out the  attachment

public List<?> retrive() {

List<?>  list = new ArrayList();
ry {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
list = session.createQuery(" from Trade").list();    <------  Exception raised here
tx.commit();

}catch(HibernateException ex) {
ex.printStackTrace();
}
return list;
}
      


org.hibernate.exception.DataException: could not execute query
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at org.hibernate.loader.Loader.doList(Loader.java:2223)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
      at org.hibernate.loader.Loader.list(Loader.java:2099)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
      at ca.penson.dpp.hibernate.manager.dao.TradeDAO.retrive(TradeDAO.java:27)
      at ca.penson.dpp.test.retrieveTest.main(retrieveTest.java:11)
Caused by: java.sql.SQLException: The value supplied cannot be converted to DOUBLE.
      at net.sourceforge.jtds.jdbc.Support.convert(Support.java:570)
      at net.sourceforge.jtds.jdbc.JtdsResultSet.getDouble(JtdsResultSet.java:649)
      at net.sourceforge.jtds.jdbc.JtdsResultSet.getDouble(JtdsResultSet.java:947)
      at org.hibernate.type.DoubleType.get(DoubleType.java:22)
      at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
      at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
      at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
      at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
      at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
      at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
      at org.hibernate.loader.Loader.getRow(Loader.java:1206)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
      at org.hibernate.loader.Loader.doQuery(Loader.java:701)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
      at org.hibernate.loader.Loader.doList(Loader.java:2220)
      ... 9 more

screenSh.JPG
Avatar of arkhls

ASKER

.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arkhls

ASKER

Thanks for your quiclk respond I will do it now and I will let you know .... Tnx again
Avatar of arkhls

ASKER

That was a great help Thank U
Avatar of arkhls

ASKER

.