Hi All,
I am using hibernate 3 and Oracle 9i.
I am having two Objects Patient and Entry.They are having one to one bidirectional
relationship.
<
Code:
class name="Patient" table="PATIENT">
<id name="id"
type="long"
column="PATIENT_ID"
access="field">
<generator class="native"/>
</id>
<one-to-one name="entry"
class="Entry"
property-ref="patient"/>
</class>
<class name="Entry" table="ENTRY">
<id name="id"
type="long"
column="WORKID"
access="field">
<generator class="native"/>
</id>
<many-to-one name="patient"
class="Patient"
column="PATIENT_ID"
unique="true"
not-null="true"/>
</class>
Following are the properties I am using in hibernate.cfg.xml file.
Code:
<property name="connection.url">url</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Show all SQL DML executed by Hibernate -->
<property name="show_sql">true</property>
<!-- Switch to built-in cache provider -->
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
I am having Patient object(Table) loaded and not having Entry table loaded.
When I am querying the patient object like
Code:
Query q3 = session.createQuery(
"from Patient p where p.number =:nbr "
);
q3.setParameter("nbr", "11453491");
// List qlist3 = q3.list();
List qlist3 = (List) q3.uniqueResult();
System.out.println("NAME IS " +qlist3);
//Patient p1 = (Patient)qlist3.get(0);
//String name1= p1.getName();
//System.out.println("NAME IS " +name1);
//p = new Patient(nonzerocpi,name);
// session.save(p);
tx.commit();
session.close();
I am getting two hibernate queries on console one is
Select from Patient...
other one is
Select from Entry....
Following are the show sql's
Code:
Hibernate: select patient0_.PATIENT_ID as PATIENT1_0_, patient0_.VERSION as VERSION0_, patient0_.PATIENT_NAME as PATIENT3_0_, patient0_.CPI_NUMBER as CPI4_0_, patient0_.CREATED as CREATED0_, patient0_.LAST_APPOINTMENT_ID as LAST6_0_ from PATIENT patient0_ where patient0_.CPI_NUMBER=?
Hibernate: select entry0_.WORKITEM_ID as WORKITEM1_4_0_, entry0_.VERSION as VERSION4_0_, entry0_.PATIENT_NAME as PATIENT3_4_0_, entry0_.CPI_NUMBER as CPI4_4_0_, entry0_.BEGIN_DATE as BEGIN5_4_0_, entry0_.CREATED as CREATED4_0_, entry0_.STATUS as STATUS4_0_, entry0_.USER_ID as USER8_4_0_, entry0_.SUSPEND_BY as SUSPEND9_4_0_, entry0_.FORWARD_BY as FORWARD10_4_0_, entry0_.SUSPEND_DATE as SUSPEND11_4_0_, entry0_.QUEUE_ID as QUEUE12_4_0_, entry0_.PATIENT_ID as PATIENT13_4_0_ from TBW_ENTRY entry0_ where entry0_.PATIENT_ID=?
and as result of second query I am getting exception that Entry could not be loaded.
Following is the exception:
Code:
14:18:08,789 WARN JDBCExceptionReporter:71 - SQL Error: 904, SQLState: 42000
14:18:08,789 ERROR JDBCExceptionReporter:72 - ORA-00904: "ENTRY0_"."PATIENT_ID": invalid identifier
org.hibernate.exception.SQLGrammarException: could not load an entity: [edu.umich.med.pbs.domain.model.Entry#13422]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1796)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1512)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:365)
at org.hibernate.type.EntityType.resolve(EntityType.java:306)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:296)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:992)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at edu.umich.med.pbs.dataload.otis.TestLoad.loadOTISData(TestLoad.java:165)
at edu.umich.med.pbs.dataload.otis.TestLoad.main(TestLoad.java:46)
Caused by: java.sql.SQLException: ORA-00904: "ENTRY0_"."PATIENT_ID": invalid identifier
I do'nt know why it is trying to load Entry when I am just querying for
one object i.e Patient.
If I delete the data from Patient table then I am getting just one query
Select from Patient with null results.
I am using Oracle database.
I am not sure but this might be some oracle related problem.
I will appriciate if someone helps me out.
Thanks.