Hi,
I am using Hibernate3.2.6.
MySQL database 5.0.51
MySQL connector 5.0.4.
JDK1.6.06.
The following is my project dir structure:
Sample:
src:
com/icalib/ocs/server
TechnologyArea.java
TechAreaApp.java
TechnologyArea.hbm.xml
under src/ i have hibernate.cfg.xml
The contents of hibernate.cfg.xml is:
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
<mapping resource="com/icalib/ocs/server/TechnologyArea.hbm.xml"/>
</session-factory>
</hibernate-configuration>
********************************************
The contents of TechnologyArea.hbm.xml is:
Code:
<hibernate-mapping>
<class name="com.icalib.ocs.server.TechnologyArea" table="techarea">
<id name="technologyId" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="technologyName" />
</class>
</hibernate-mapping>
***********************************************
TechAreaApp is where the error occurs:
I have two methods getAll() and main()
here it is:
getAll():
Code:
public List<TechnologyArea> getAll(){
Session session = HibernateUtil.getSession();
session.beginTransaction();
List<TechnologyArea> taList = session.createQuery("select h from techarea as h").list();
session.getTransaction().commit();
return taList;
}
main():
Code:
public static void main(String[] args) {
// TODO Auto-generated method stub
TechAreaApp taApp = new TechAreaApp();
List<TechnologyArea> list = taApp.getAll();
Iterator<TechnologyArea> itr = list.iterator();
while(itr.hasNext()){
TechnologyArea ta = itr.next();
System.out.println("TA "+ ta);
}
}
**************************
When I run the above code I get the following exception:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: techarea is not mapped [select h from techarea as h] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
...............
..........................
When I change createQuery() to createSQLQuery("select * from techarea") I get the following exception:
Exception in thread "main"
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.icalib.ocs.server.TechnologyArea
at com.icalib.ocs.server.TechAreaApp.main(TechAreaApp.java:32)
I am unable to solve this. I have added all the jar files from the hibernate 3.2.6 distribution...but I keep getting these two errors.
Thanks for any help in advance.
Gavin