Hibernate version:
2.1.3
Mapping documents:
2 of them, patient and rx. Here is patient
Code:
<?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 package="com.txdx.pojo">
<class name="Patient" table="patients">
<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" />
<property name="hphone" type="string" length="13" not-null="false"/>
<property name="hcell" type="string" length="13" not-null="false"/>
<property name="hphoneother" type="string" length="13" not-null="false"/>
<property name="hwebsite" type="string" length="50" not-null="false"/>
<property name="DOB" type="date"/>
<property name="SSN" type="string" length="11" not-null="false"/>
<property name="workplace" type="string" length="35" not-null="false"/>
<property name="waddr1" type="string" length="35" not-null="false" />
<property name="waddr2" type="string" length="35" not-null="false"/>
<property name="wcity" type="string" length="15" not-null="false" />
<property name="wstate" type="string" length="2" not-null="false" />
<property name="wzip" type="string" length="10" not-null="false" />
<property name="wphone" type="string" length="13" not-null="false"/>
<property name="wphone2" type="string" length="13" not-null="false"/>
<property name="wphoneother" type="string" length="13" not-null="false"/>
<property name="wwebsite" type="string" length="50" not-null="false"/>
<!-- TODO: link to authorized contact here, 1-to-1 contact null OK -->
<bag name="Rxs" cascade="all" inverse="true" lazy="false" order-by="rxDate">
<key column="patient_id"/>
<one-to-many class="com.txdx.pojo.Rx"/>
</bag>
<!--
<set name="Rxs" cascade="all" inverse="true" lazy="false">
<key column="patient_id"/>
<one-to-many class="com.txdx.pojo.Rx"/>
</set>
-->
</class>
</hibernate-mapping>
here is rx
Code:
<?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 package="com.txdx.pojo">
<class name="Rx" table="rxs">
<!-- we will try this without an ID for now... -->
<id name="id" column="rx_id"
type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="brandName" type="string" length="35" not-null="true"/>
<property name="genericName" type="string" length="35"/>
<property name="rxDate" type="date"/>
<property name="dosage" type="float"/>
<property name="instructions" type="string"/>
<many-to-one name="patient" class="com.txdx.pojo.Patient" column="patient_id" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Configuration cfg = new Configuration().addClass(Patient.class)
.addClass(Rx.class);
HibernateExample ex = new HibernateExample();
//generate our session and open it
SessionFactory factory = cfg.buildSessionFactory();
// cfg no longer used once session factory is created
// this session is opened on a JDBC connection handled by
// hibernate
Session session = factory.openSession();
...
Code:
System.out.println("*-*-*-*-*-*-*-*");
System.out.println("java.class.path="+System.getProperties().getProperty("java.class.path"));
System.out.println("*-*-*-*-*-*-*-*");
for (int i = 0; i < firstNames.length; i++) {
System.out.println("searching for "+firstNames[i]+" "+lastNames[i]);
List patients = session
.find(
"from medical patients as p where p.firstName=? and p.lastName=?",
new Object[] { firstNames[i], lastNames[i] },
new Type[] { Hibernate.STRING,
Hibernate.STRING });
System.out.println("found " + patients.size()
+ "matching records");
for (Iterator it = patients.iterator(); it.hasNext();) {
Patient p = (Patient) it.next();
System.out.println("===================");
System.out.println("name: " + p.getFirstName() + ", "
+ p.getLastName());
System.out.println("DOB: " + p.getDOB().toString());
System.out.println("------- RX info: -------");
List rxs = p.getRxs();
for (Iterator rxList = rxs.iterator(); rxList.hasNext();) {
Rx rx = (Rx) rxList.next();
System.out.println(" drug:" + rx.getBrandName()
+ "[" + rx.getGenericName() + "] at "
+ rx.getDosage());
System.out.println(" instructions:\n "
+ rx.getInstructions());
System.out.println(" ----------");
}
}
}
Full stack trace of any exception that occurs:
[java] (cfg.Environment 462 ) Hibernate 2.1.3
[java] (cfg.Environment 496 ) loaded properties from resource hibernate.properties: {hibernate.c3p0.timeout=1800, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.c3p0.max_statements=50, hibernate.c3p0.max_size=20, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.c3p0.min_size=5, hibernate.jdbc.batch_size=0, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost:3306/medical, hibernate.show_sql=true, hibernate.connection.password=password, hibernate.connection.pool_size=3}
[java] (cfg.Environment 518 ) using java.io streams to persist binary types
[java] (cfg.Environment 519 ) using CGLIB reflection optimizer
[java] (cfg.Configuration 347 ) Mapping resource: com/txdx/pojo/Patient.hbm.xml
[java] (cfg.Binder 229 ) Mapping class: com.txdx.pojo.Patient -> patients
[java] (cfg.Configuration 347 ) Mapping resource: com/txdx/pojo/Rx.hbm.xml
[java] (cfg.Binder 229 ) Mapping class: com.txdx.pojo.Rx -> rxs
[java] (cfg.Configuration 613 ) processing one-to-many association mappings
[java] (cfg.Binder 1168) Mapping collection: com.txdx.pojo.Patient.Rxs -> rxs
[java] (cfg.Configuration 622 ) processing one-to-one association property references
[java] (cfg.Configuration 647 ) processing foreign key constraints
[java] (dialect.Dialect 82 ) Using dialect: net.sf.hibernate.dialect.MySQLDialect
[java] (cfg.SettingsFactory 58 ) Maximim outer join fetch depth: 1
[java] (cfg.SettingsFactory 62 ) Use outer join fetching: false
[java] (connection.C3P0ConnectionProvider 48 ) C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/medical
[java] (connection.C3P0ConnectionProvider 49 ) Connection properties: {user=root, password=password}
[java] (transaction.TransactionManagerLookupFactory 33 ) No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
[java] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@c4fe76 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@dc6a77 [ acquireIncrement -> 1, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxIdleTime -> 1800, maxPoolSize -> 20, maxStatements -> 50, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@11e1e67 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost:3306/medical, properties -> {user=root, password=password} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
[java] (cfg.SettingsFactory 102 ) Use scrollable result sets: true
[java] (cfg.SettingsFactory 105 ) Use JDBC3 getGeneratedKeys(): true
[java] (cfg.SettingsFactory 108 ) Optimize cache for minimal puts: false
[java] (cfg.SettingsFactory 114 ) echoing all SQL to stdout
[java] (cfg.SettingsFactory 117 ) Query language substitutions: {}
[java] (cfg.SettingsFactory 128 ) cache provider: net.sf.ehcache.hibernate.Provider
[java] (cfg.Configuration 1093) instantiating and configuring caches
[java] (impl.SessionFactoryImpl 119 ) building session factory
[java] (impl.SessionFactoryObjectFactory 82 ) no JNDI name configured
[java] (cache.UpdateTimestampsCache 35 ) starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
[java] (config.Configurator 123 ) No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Eclipse30/workspace/MedicalRCP/lib/hibernate/ehcache-0.7.jar!/ehcache-failsafe.xml
[java] (hibernate.Plugin 95 ) Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
[java] (cache.QueryCache 39 ) starting query cache at region: net.sf.hibernate.cache.QueryCache
[java] (hibernate.Plugin 95 ) Could not find configuration for net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache settings.
[java] *-*-*-*-*-*-*-*
[java] java.class.path=D:\Eclipse30\workspace\MedicalRCP;D:\Eclipse30\plugins\org.eclipse.core.runtime_3.0.0\runtime.jar;D:\Eclipse30\plugins\org.eclipse.jface_3.0.0\jface.jar;D:\Eclipse30\plugins\org.eclipse.swt.win32_3.0.0\ws\win32\swt.jar;D:\Eclipse30\plugins\org.eclipse.ui.workbench_3.0.0\workbench.jar;D:\Eclipse30\workspace\MedicalRCP\src\properties;D:\Eclipse30\workspace\MedicalRCP\src;D:\Eclipse30\workspace\MedicalRCP\bin;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate-ext\jdom.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate-ext\velocity-1.3.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\ant-1.5.3.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\ant-optional-1.5.3.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\c3p0-0.8.4.5.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\cglib-full-2.0.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\commons-collections-2.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\commons-dbcp-1.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\commons-lang-1.0.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\commons-logging-1.0.3.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\commons-pool-1.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\concurrent-1.3.2.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\connector.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\dom4j-1.4.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\ehcache-0.7.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\hibernate-tools.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\hibernate2.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jaas.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jboss-cache.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jboss-common.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jboss-jmx.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jboss-system.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jcs-1.0-dev.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jdbc2_0-stdext.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jgroups-2.2.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\jta.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\junit-3.8.1.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\log4j-1.2.8.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\odmg-3.0.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\oscache-2.0.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\proxool-0.8.3.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\swarmcache-1.0rc2.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\xalan-2.4.0.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\xerces-2.4.0.jar;D:\Eclipse30\workspace\MedicalRCP\lib\hibernate\xml-apis.jar;D:\Eclipse30\workspace\MedicalRCP\lib\mysql\mysql-connector-java-3.0.15-ga-bin.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\aopalliance.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-aop.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-context.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-core.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-dao.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-orm.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-web.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring-webmvc.jar;D:\Eclipse30\workspace\MedicalRCP\lib\spring\spring.jar
[java] *-*-*-*-*-*-*-*
[java] searching for Bob Newhart
[java] net.sf.hibernate.QueryException: in expected: patients [from medical patients as p where p.firstName=? and p.lastName=?]
[java] at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
[java] at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
[java] at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
[java] at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
[java] at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
[java] at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
[java] at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1554)
[java] at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1525)
[java] at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
[java] at com.txdx.examples.HibernateExample.main(Unknown Source)
Name and version of the database you are using:
MySQL 4.0
The generated SQL (show_sql=true):
Don't know where it ends up.
Debug level Hibernate log excerpt:
I looked through the archives, and there are a few errors similar to this one being discussed, and I have loaded the patient and rx classes as discussed elsewhere. I am using a find command instead of a query. Maybe that is my mistake?
As an aside, this code used to work at one time. I had added some spring commands, trying to create DAOs with it, and backed off until I could get this hibernate code to work in my eclipse RCP project. I backed out all the spring jar files in the classpath, but to no avail. The MySQL database is up, the database and tables are there, and I verified the data is in the tables from a sql command prompt.
Any ideas?
--PK