I am able to view a list of results from R_States table using createSQLQuery.
public List<String> getStates() throws Exception {
try
{
Session session = sessionFactory.openSession();
return session.createSQLQuery("select * from R_States").list();
}
catch(Exception e)
{
//Logging
}
finally
{
if(session !=null && session.isOpen())
{
session.close();
session=null;
}
}
return null;
}
But when I try to use HQL createQuery method I get a ORA-00942: table or view does not exist error.
return session.createQuery("from States").list();
This is my session factory (JNDI Datasource).
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>folder.dao</value>
<value>folder.domain.States</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</prop>
<prop key="hibernate.connection.datasource">java:/comp/env/jdbc/r</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
This is my domain class. What am i missing?
@Entity
@Table(name = "R_STATE")
public class States {
@Column(name = "SCode")
private String stateCode;
@Column(name = "SName")
private String stateName;
public String getStateCode() {
return stateCode;
}
public void setStateCode(String stateCode) {
this.stateCode = stateCode;
}
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
This is a class, not a package, so Hibernate probably won't find your mapped entity. Try changing with this: