Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.x
Mapping documents:
<?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 package="com.txdx.pojo">
<class name="PatientPOJO" table="patients" lazy="false" >
<id name="id" column="patient_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="salutation" type="string" length="4" not-null="true" />
<property name="firstName" type="string" length="25" not-null="true" />
<property name="initial" type="string" length="1" not-null="false"/>
<property name="lastName" type="string" length="25" not-null="true" />
<property name="suffix" type="string" length="3" not-null="false"/>
<property name="haddr1" type="string" length="35" not-null="true" />
<property name="haddr2" type="string" length="35" not-null="false"/>
<property name="hcity" type="string" length="15" not-null="true" />
<property name="hstate" type="string" length="2" not-null="true" />
<property name="hzip" type="string" length="10" not-null="true" />
<!-- other fields deleted for brevity -->
<property name="serialVersionUID" type="long"/>
<bag name="Rxs" cascade="all" inverse="true" lazy="false" order-by="rxDate">
<key column="patient_id"/>
<one-to-many class="com.txdx.pojo.RxPOJO"/>
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
// get context classloader
Thread cur = Thread.currentThread();
ClassLoader save = cur.getContextClassLoader();
cur.setContextClassLoader(getClass().getClassLoader());
// do usual hibernate thing
Session session = HibernateUtil.currentSession();
List patients = session.createQuery(
"select firstName, initial, lastName from Patient ").list();
Iterator iter = patients.iterator();
Full stack trace of any exception that occurs:
00:02:50,363 ERROR PARSER:35 - *** ERROR: Patient is not mapped.
Unhandled event loop exception
Reason:
No data type for node: org.hibernate.hql.ast.IdentNode
+-[IDENT] IdentNode: 'firstName' {originalText=firstName}
Name and version of the database you are using:
latest MySQL
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
OK, all I want to do is get a list of certain fields (first and last name, id, etc) for all rows in my table so the user can select a name to work on. They select a name, I use the id to do another lookup to get all the information on this person.
The documentation, although excellent as a reference, does not seem geared to someone just getting started.
When I bring up the hibernate console in eclipse, I get error messages about as meaningful (to me) as the one listed above. Things like "in expected", or with this code:
select firstName from Patient
I get
Error 2005-06-08 00:08:22.301 undefined alias: firstName [select firstName from Patient
]
org.hibernate.QueryException: undefined alias: firstName [select firstName from Patient
]
Can someone please show me a HQL statement that will give me a couple of fields so I can use something like the scalar results code shown in chapter 10 to make a collection to use in my gui? I just need to get my feet wet here.
Thanks for the help.