-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Problem in fetching object with one to one bidirectional rel
PostPosted: Wed Nov 02, 2005 3:29 pm 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 4:43 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
the error is from the Oracle db.

I think that either TBW_ENTRY is not the actual table name in your DB or that PATIENT_ID is supposed to be not capitalized. oracle is case sensitive.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 5:16 pm 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
TBW_ENTRY is the actul table name in mappings .Insteed of ENTRY it is TBW_ENTRY.And PATIENT_ID is also capitilized.

Any Idea ??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 10:00 am 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
It works fine with Hypersonic database but having problem with Oracle database.

I will appriciate if anybody helps me out.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 10:39 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
there is also a Oracle9Dialect, try that

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 10:57 am 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
I already tried that...
Do'nt know what's wrong....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 2:47 pm 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
Does anybody has idea about this problem of hibernate with oracle database.

I will appriciate your response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.