Joined: Mon Jun 14, 2004 12:59 pm Posts: 1
|
Using Hibernate 2.1
hbm2java tool automatically generates the following code in a finder:
public static List findAll() throws SQLException, HibernateException {
Session session = com.X.Util.currentSession();
List finds = session.find("from MyClass in class com.X.hibernate.MyClass");
return finds;
This code produces the follwing error:
net.sf.hibernate.QueryException: unexpected token: in [from MyClass in class X.hibernate.MyClass]
The codegen.xml file is as follows:
<codegen>
<meta attribute="class-description">
@author me
</meta>
<meta attribute="session-method">
com.X.Util.currentSession();
</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="extends">com.X.MyBaseClass</meta>
<generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
<generate package="com.X.hibernate.finders" prefix="Find" renderer="net.sf.hibernate.tool.hbm2java.FinderRenderer"/>
</codegen>
The hbm file is :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.X.hibernate">
<class name="MyClass" table="MyClass">
<meta attribute="class-code">
private java.util.List roomNames;
public java.util.List getRoomNames(){
return roomNames;
}
public java.util.List setRoomNames(){
try{
net.sf.hibernate.Session session = com.X.Util.currentSession();
roomNames =session.find("Select room.name from MyClass as room");
}catch(Exception e){
System.out.println("MyClass.getRoomNames "+e);
}catch(java.lang.NoClassDefFoundError e){
System.out.println("e");
}
if (roomNames==null){
roomNames= new java.util.ArrayList();
}
return roomNames;
}
</meta>
<id name="id" type="long" column="uid" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="clubID" type ="string" not-null="true" length="10">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="finder-method">findByClub</meta>
</property>
<property name="name" not-null="true" type="java.lang.String" length="50">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<component name="phoneNumber" class="com.X.hibernate.PhoneNumber">
<property name="areaCode" type="string" length="3" not-null="false"/>
<property name="exchange" type="string" length="3" not-null="false"/>
<property name="number" type="string" length="4" not-null="false"/>
</component>
<property name="maitred" type="java.lang.String" length="50" not-null="false"/>
<set name="menus">
<key column="uid"/>
<many-to-many class="com.X.hibernate.Menu"/>
</set>
<set name="tables">
<key column="uid"/>
<one-to-many class="com.X.hibernate.Table"/>
</set>
<set name="times">
<key column="uid"/>
<one-to-many class="com.X.hibernate.Time"/>
</set>
</class>
Class names were changed to protect privacy so it is not inconceivable I screwed somthing up in the cut and paste. If something looks odd then instead of spending time on it please let me know and I will clarify.
Is this in an error in the generator or some missing configuration element? Any ideas
|
|