-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Query Problem
PostPosted: Tue Dec 06, 2005 2:02 pm 
Newbie

Joined: Wed Nov 02, 2005 2:03 pm
Posts: 15
Hi All,

I am using Spring and Hibernate 3 with oracle 9i.
I am getting following exception


Code:
org.hibernate.HibernateException: More than one row with the given identifier was found: 1131506, for class: edu.umich.med.pbs.domain.model.Task
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:68)
   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 org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:809)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:800)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:796)
   at edu.umich.med.pbs.dao.hibernate.TaskDaoImpl.getTasks(TaskDaoImpl.java:15)
   at edu.umich.med.pbs.domain.WorkflowFacadeImpl.getTasks(WorkflowFacadeImpl.java:91)
   at sun.reflect.GeneratedMethodAccessor248.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
   at $Proxy53.getTasks(Unknown Source)
   at edu.umich.med.pbs.web.OnetofivedayController.handleNextItem(OnetofivedayController.java:96)
   at sun.reflect.GeneratedMethodAccessor249.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:403)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:358)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:347)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:534)



Here is what I am doing.

Following are the mapping files.

1.Task.hbm.xml


Code:
<?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="domain.model">

<class name="Task" table="TBW_TASK">
   <id name="id"
      type="long"
      column="TASK_ID"
      access="field">
      <generator class="native"/>
   </id>

   <!-- A versioned entity. -->
   <version name="version"
          column="VERSION"
          access="field"/>

   <!-- We don't change the cpi number, so map it with update="false". -->
   <property   name="cpiNumber"
            type="string"
            column="CPI_NUMBER"
            not-null="true"
            update="false"
            length="20"/>
            
   <!-- We don't change the visit number, so map it with update="false". -->
   <property   name="visitNumber"
            type="string"
            column="VISIT_NUMBER"
            not-null="true"
            update="false"
            length="10"/>

   <!-- We don't change the appointment date, so map it with update="false".
       This is an immutable property. -->
   <property   name="appointmentDate"
            type="java.util.Date"
            column="APPOINTMENT_DATE"
            not-null="true"
            update="false"
            access="field">
   </property>


   <!-- We can't change the creation time, so map it with update="false". -->
   <property   name="created"
            column="CREATED"
            type="java.util.Date"
            update="false"
            not-null="true"
            access="field"/>


   <property   name="status"
            type="int"
            column="STATUS"
            not-null="true"/>
            
   <property   name="userID"
            type="string"
            column="USER_ID"
            length="30"/>      
            
            
   <property   name="resourceAbbr"
            type="string"
            column="CLINIC_RESOURCE_ID"
            length="40"/>   
            
                     
   <property   name="resourceName"
            type="string"
            column="CLINIC_RESOURCE_NAME"
            length="80"/>                           
            
   <!-- Bidirectional, required as TBWtask is WORKITEM_ID NOT NULL. This is also
        a read-only property that will never be updated. -->
   <many-to-one name="entry"
             class="Entry"
             column="WORKITEM_ID"
             update="false"
             access="field"
             foreign-key="FK3_WORKITEM_ID"/>
            
   <!-- Mapping for Comment association. -->
   <set    name="comments"
         cascade="save-update"
         inverse="true"
         access="field">
      <key>
         <column name="TASK_ID" not-null="true"/>
      </key>
      <one-to-many class="Comment"/>
   </set>            

   <many-to-one name="appointment"
         class="Appointment"
         column="APPOINTMENT_ID"
         unique="true"
         not-null="true"/>
</class>

</hibernate-mapping>


2.Appointment.hbm.xml

Code:
<?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="domain.model">

<class name="Appointment" table="APPOINTMENT">
   <id name="id"
      type="long"
      column="APPOINTMENT_ID"
      access="field">
      <generator class="native"/>
   </id>

   <!-- A versioned entity. -->
   <version name="version"
          column="VERSION"
          access="field"/>

   <!-- We don't change the cpi number, so map it with update="false".
       This is an immutable property. -->
   <property   name="cpiNumber"
            type="string"
            column="CPI_NUMBER"
            not-null="true"
            update="false"
            length="20"/>

   <!-- We don't change the visit number, so map it with update="false".
       This is an immutable property. -->
   <property   name="visitNumber"
            type="string"
            column="VISIT_NUMBER"
            not-null="true"
            update="false"
            length="10"/>

   <!-- We don't change the appointment date, so map it with update="false".
       This is an immutable property. -->
   <property   name="appointmentDate"
            type="java.util.Date"
            column="APPOINTMENT_DATE"
            not-null="true"
            update="false"
            access="field">
   </property>


   <!-- We can't change the creation time, so map it with update="false". -->
   <property   name="created"
            column="CREATED"
            type="java.util.Date"
            update="false"
            not-null="true"
            access="field"/>


   <property   name="financialClass"
            type="string"
            column="FINANCIAL_CLASS"
            length="50"/>
            
   <property   name="clinicGroup"
            type="string"
            column="CLINIC_GROUP"
            length="50"/>   
            
            
   <property   name="resourceAbbr"
            type="string"
            column="CLINIC_RESOURCE_ID"
            length="40"/>   
            
                     
   <property   name="resourceName"
            type="string"
            column="CLINIC_RESOURCE_NAME"
            length="80"/>                                    
            
   <!-- Bidirectional, required as Appointment is PATIENT_ID NOT NULL. This is also
        a read-only property that will never be updated. -->
   <many-to-one name="patient"
             class="Patient"
             column="PATIENT_ID"
             update="false"
             access="field"
             foreign-key="FK2_PATIENT_ID"/>
            
            
   <list       name="insurances"
            table="APPOINTMENT_INSURANCE"
            lazy="true"
            cascade="save-update">
            <key column="APPOINTMENT_ID"/>
            <index column="COB_POSITION"/>
            <many-to-many class="Insurance" column="INSURANCE_ID"/>
   </list>   
   
   
   <one-to-one name="task"
            class="Task"
            property-ref="appointment"/>

</class>

</hibernate-mapping>


Following is the method call from controller.

Code:
model.put("taskList", this.workflow.getTasks(entry));


Following is the Query.

Code:
public List getTasks(Entry entry) throws DataAccessException {
      return getHibernateTemplate().find("from Task t join fetch t.appointment where t.entry = ? ", entry);

}


The problem which I am facing is .
I am having appointment_id in appointment table say for example in exception '1131506'
Also in Task table I am having two entries for appointment_id '1131506'

This is the problem that I am having more than one value in Task for appointment_id '1131506'
and I am getting exception.


I will really appriciate if somebody helps me out.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 3:34 pm 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
Quote:
This is the problem that I am having more than one value in Task for appointment_id '1131506'

Then you cannot map it as a one-to-one. You must use one-to-many.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.