• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate : problem in select query

 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii,
i have a problem in selecting data from database.I m working on following code.
Session session = HibernateUtil.currentSession();
Query query = session.createQuery("select u from Appmst as u where u.id=:id");
query.setInteger("id",1);
for (Iterator it = query.iterate(); it.hasNext()
{
System.out.println("login: " + loginbean.getAppMstLogin());
System.out.println("password: " + loginbean.getAppMstPassword());
if(it!=null)
{
return map.findForward("join");
}
}
session.close();
HibernateUtil.closeSession();

the error i got is Appmst is not mapped.

Plz give solution if anyone have.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the relevant mapping and configuration files so we can see if there's an issue there.
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my hibernate.cfg.hbm

<session-factory>
<property name="hibernate.connection.driver_class">com.sap.dbtech.jdbc.DriverSapDB</property>
<property name="hibernate.connection.url">jdbc:sapdb://localhost/BARSDB?sqlmode=oracle</property>
<property name="hibernate.connection.username">local</property>
<property name="hibernate.connection.password">local</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.SAPDBDialect</property>

<!-- Mapping files -->

<mapping resource="AppMst.hbm.xml"/>

</session-factory>

and

AppMst.hbm.xml

<?xml version="1.0"?>
<!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.bars.barsmlm.user.AppMstForm" table="APPMST">

<id name="id" type="int" column="ID">
<generator class="increment"/>
</id>


<property name="appMstUserId"
column="AppMstID"/>

<property name="appMstRegNo"
column="AppMstRegNo"/>

<property name="appMstLogin"
column="AppMstLogin"/>

<property name="appMstFName">
<column name="AppMstFName"/>
</property>

<property name="appMstLName">
<column name="AppMstLName"/>
</property>

<property name="appMstPassword"
column="AppMstPassword"/>

<property name="appMstCity">
<column name="AppMstCity"/>
</property>

<property name="appMstTown">
<column name="AppMstTown"/>
</property>

<property name="appMstAddress1">
<column name="AppMstAddress1"/>
</property>

<property name="appMstAddress2">
<column name="AppMstAddress2"/>
</property>

<property name="appMstPinCode">
<column name="AppMstPinCode"/>
</property>

<property name="appMstPrimaryPhone">
<column name="AppMstPrimaryPhone"/>
</property>


<property name="appMstTitle">
<column name="AppMstTitle"/>
</property>

</class>
</hibernate-mapping>
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an HQL query, you should refer to the object and not the table.

So your query should look like:

select u from com.bars.barsmlm.user.AppMstForm as u where u.id=:id
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii Scott ,
thanks i got the solution because of ur advice.
bye for now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic