Hibernate version: 2.1.8
To Whom It May Concern,
I recently moved from using Jenny from Java Ranch to using Hibernate to handle my object/relational mapping and I must say Hibernate is extremely impressive. I have been using the Hibernate book by Will Iverson to learn from.
I have been writting my hbm.xml files by handing and using an ant task to build my java classes. I am having trouble with the findAll method that is getting generated in my Finder classes. Below is one of my hbm.xml files:
<?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.echostorm.resumes.evaluator.hibernate.Skill" table="skill">
<id name="id" type="string" column="ID">
<meta attribute="finder-method">findByID</meta>
<generator class="uuid.hex" />
</id>
<version column="revision" name="revision" />
<property name="name" type="string"
column="name" length="100" >
<meta attribute="finder-method">findByName</meta>
</property>
<property name="description" type="string"
column="description" length="500" />
<property name="department" type="string"
column="department" length="100" >
<meta attribute="finder-method">findByDepartment</meta>
</property>
</class>
</hibernate-mapping>
It's straight forward and simple. The Finder classes has this method:
public static List findAll(Session session) throws SQLException, HibernateException {
List finds = session.find("from Skill in class com.echostorm.resumes.evaluator.hibernate.Skill");
return finds;
Now when I used this method I kept getting an Exception which was:
net.sf.hibernate.QueryException: unexpected token: in [from Skill in class com.echostorm.resumes.evaluator.hibernate.Skill]
I caught up with the CTO at work and he took a look at it and changed the Query in the findAll method to this:
public static List findAll(Session session) throws SQLException, HibernateException {
List finds = session.find("from com.echostorm.resumes.evaluator.hibernate.Skill as skill");
return finds;
Now it works. What I would really like is for hibernate to build my findAll methods with this structure and not the other. I guess what I would like to know is how is the findAll method defined? Can I make a change in my hbm.xml file to get it to generate the findAll like this?
I am not exactly sure where I can go for this? I know you time is important but any guidance would be much appreciated.
Sincerely,
Vince Cordaro
echostorm.net
|