-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: net.sf.hibernate.QueryException: in expected: b
PostPosted: Tue Apr 12, 2005 7:21 pm 
Newbie

Joined: Tue Apr 12, 2005 7:01 pm
Posts: 2
I have written a simple java class to fetch data using HQL. This is a standalone application and my database is not local. I have made the necessary entries in the hibernate.cfg.xml. However I am not sure of the entries and get the following error when I try to run the application -

[java] net.sf.hibernate.QueryException: in expected: b [select b from TransactionLog b where b.transSrcSystem = 'RFI']
[java] at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
[java] at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
[java] at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
[java] at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
[java] at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
[java] at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
[java] at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1602)
[java] at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:29)
[java] at com.echostar.requestforinfo.hibernate.createSession.main(Unknown Source)

I have searched various websites for this error and most of them suggest to check the mappings in the hibernate.cfg.xml file. Can anyone please go through the attached code and help? Any help will be highly appreciated.

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>   
   
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin@dcorpdb:1522:DCORP</property>
        <property name="connection.username">wls_bp</property>
        <property name="connection.password">wls_bp</property>       
        <property name="show_sql">true</property>
        <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>

        <mapping resource="com/echostar/requestforinfo/hibernate/TransactionLog.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

package com.echostar.requestforinfo.hibernate;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.HibernateException;

import net.sf.hibernate.JDBCException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class createSession
{
private Log LOG = LogFactory.getLog( createSession.class.getName() );

public static void main ( String[] args )

{
try
{
System.out.println("App Started");
Configuration cfg = new Configuration();
SessionFactory sessions = cfg.buildSessionFactory();

System.out.println("AFter creating sessions");

Transaction tx = null;

Session session = sessions.openSession();

Query query = session.createQuery(
"select b from TransactionLog b where b.transSrcSystem = 'RFI'");

System.out.println("AFter creating query"+query.getQueryString());

Iterator result = query.iterate();
int count = 0;

while(result.hasNext())
{
count++;
}
System.out.println("Number of Objects: " + count);
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

Code:

  <?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
 
  <hibernate-mapping>
 
          <class name="com.echostar.requestforinfo.hibernate.TransactionLog" table="BP_TRANSACTION_LOG">
                  <id name="transactionid" column="TRANSACTION_LOG_ID" type="long">
                  <generator class="sequence">
            <param name="sequence">BP_TRANSACTION_LOG_SEQ</param>
        </generator>
                  </id>
                 
                  <property name="transLogId"  column="TRANSACTION_LOG_ID"/>
                  <property name="appBodyInfo" column="APP_BODY_INFO"/>
                  <property name="transDate"   column="TRANSACTION_DATE"/>
                  <property name="transSrcSystem" column="TRANSACTION_SOURCE_SYSTEM"/>                 
          </class>
 
</hibernate-mapping>

My database details are as follows -

username=wls_bp
password=wls_bp
host=dcorpdb
protocol=tcp
port=1522
sid=DCORP


Top
 Profile  
 
 Post subject: Re: net.sf.hibernate.QueryException: in expected: b
PostPosted: Wed Apr 13, 2005 10:16 am 
Newbie

Joined: Tue Apr 12, 2005 7:01 pm
Posts: 2
Shefali_Shah wrote:
I have written a simple java class to fetch data using HQL. This is a standalone application and my database is not local. I have made the necessary entries in the hibernate.cfg.xml. However I am not sure of the entries and get the following error when I try to run the application -

[java] net.sf.hibernate.QueryException: in expected: b [select b from TransactionLog b where b.transSrcSystem = 'RFI']
[java] at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
[java] at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
[java] at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
[java] at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
[java] at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
[java] at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
[java] at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1602)
[java] at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:29)
[java] at com.echostar.requestforinfo.hibernate.createSession.main(Unknown Source)

I have searched various websites for this error and most of them suggest to check the mappings in the hibernate.cfg.xml file. Can anyone please go through the attached code and help? Any help will be highly appreciated.

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>   
   
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin@dcorpdb:1522:DCORP</property>
        <property name="connection.username">******</property>
        <property name="connection.password">******</property>       
        <property name="show_sql">true</property>
        <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>

        <mapping resource="com/echostar/requestforinfo/hibernate/TransactionLog.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

package com.echostar.requestforinfo.hibernate;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.HibernateException;

import net.sf.hibernate.JDBCException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class createSession
{
private Log LOG = LogFactory.getLog( createSession.class.getName() );

public static void main ( String[] args )

{
try
{
System.out.println("App Started");
Configuration cfg = new Configuration();
SessionFactory sessions = cfg.buildSessionFactory();

System.out.println("AFter creating sessions");

Transaction tx = null;

Session session = sessions.openSession();

Query query = session.createQuery(
"select b from TransactionLog b where b.transSrcSystem = 'RFI'");

System.out.println("AFter creating query"+query.getQueryString());

Iterator result = query.iterate();
int count = 0;

while(result.hasNext())
{
count++;
}
System.out.println("Number of Objects: " + count);
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

Code:

  <?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
 
  <hibernate-mapping>
 
          <class name="com.echostar.requestforinfo.hibernate.TransactionLog" table="BP_TRANSACTION_LOG">
                  <id name="transactionid" column="TRANSACTION_LOG_ID" type="long">
                  <generator class="sequence">
            <param name="sequence">BP_TRANSACTION_LOG_SEQ</param>
        </generator>
                  </id>
                 
                  <property name="transLogId"  column="TRANSACTION_LOG_ID"/>
                  <property name="appBodyInfo" column="APP_BODY_INFO"/>
                  <property name="transDate"   column="TRANSACTION_DATE"/>
                  <property name="transSrcSystem" column="TRANSACTION_SOURCE_SYSTEM"/>                 
          </class>
 
</hibernate-mapping>

My database details are as follows -

username=******
password=******
host=dcorpdb
protocol=tcp
port=1522
sid=DCORP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 10:39 am 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
Try
Code:
session.createQuery("from TransactionLog where transSrcSystem = 'RFI'");


See http://www.hibernate.org/hib_docs/v3/re ... /#queryhql
especially
http://www.hibernate.org/hib_docs/v3/re ... yhql-where


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 1:24 pm 
Newbie

Joined: Mon Apr 11, 2005 2:08 pm
Posts: 8
I had a similar problem recently:

Mapping:
Code:
<hibernate-mapping package="at.rehdie.test.product">

    <class name="Product" table="product">
        <composite-id name="id" class="ProductId">
            <key-property name="id" column="id" length="150"/>
        </composite-id>
       
        <property name="name" type="string" length="100"/>
                     
        <many-to-one name="company" class="Company"
             column="company"  not-null="false" lazy="true" />
    </class>

    <query name="findAllProducts">
        select p from product p
    </query>
 
</hibernate-mapping>


The mapping for Company is ommited here.

The Query

Code:
session.getNamedQuery("findAllProducts").list()


produced the message "in expected p"

The reason for this problem was the wrong class-name in the query: The class is Product not product! (The exception-message is quite confusing, it should be something like 'class product' not mapped).


So back to your problem:

try to add the package-attribut to your mapping and add a named query to the mapping file:

Code:
<?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

  <hibernate-mapping package="com.echostar.requestforinfo.hibernate">

          <class name="TransactionLog" table="BP_TRANSACTION_LOG">
                  <id name="transactionid" column="TRANSACTION_LOG_ID" type="long">
                  <generator class="sequence">
            <param name="sequence">BP_TRANSACTION_LOG_SEQ</param>
        </generator>
                  </id>
                 
                  <property name="transLogId"  column="TRANSACTION_LOG_ID"/>
                  <property name="appBodyInfo" column="APP_BODY_INFO"/>
                  <property name="transDate"   column="TRANSACTION_DATE"/>
                  <property name="transSrcSystem" column="TRANSACTION_SOURCE_SYSTEM"/>                 
          </class>

          <query name="findByTransSrcSystem">
              select b from TransactionLog b where b.transSrcSystem=:system
          </query>

</hibernate-mapping>


Change your code to:

Code:
    Query q = session.getNamedQuery("findByTransSrcSystem");
    q.setString("system", "RFI");
    Iterator i = q.iterate();
    .......



Hope, that helps.


Top
 Profile  
 
 Post subject: Checklist for hibernate configuration
PostPosted: Mon Oct 16, 2006 1:37 am 
Newbie

Joined: Mon Oct 16, 2006 1:26 am
Posts: 1
This exception could be due to wrong configuration or any of the following missing files.Check your Hibernate configuration:

    1. hibernate.cfg.xml is in web-inf/classes folder.
    2. hibernate.cfg.xml has an entry for the hbm file.
    3. hbm file is in class path.
    4. The dclass specified in hibernate.cfg.xml is available by the same name.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.