0 Replies Latest reply on Oct 2, 2006 1:13 PM by Antonel Pazargic

    ClassCastException

    Antonel Pazargic Newbie

      Hi,

      I am using JBoss EJB-3.0 embeddable. I have a hierarchy like following:

      Person>Individual>MedicalPersonnel>Nurse;
      Person>Individual>MedicalPersonnel>Physician;

      and a many-to-many relation between MedicalDoc and MedicalPersonnel:

      Annotations are (briefly):
      1.
      @Entity
      @Table(name=Names.TBL_PERSONS)
      @Inheritance(strategy = InheritanceType.JOINED)
      public abstract class Person extends PersistableObject

      2.
      @Entity
      @Table(name = Names.TBL_INDIVIDUALS)
      @Inheritance(strategy = InheritanceType.JOINED)
      public abstract class Individual extends Person

      3.
      @Entity
      @Table(name = Names.TBL_MEDICAL_PERSONNELS)
      @Inheritance(strategy = InheritanceType.JOINED)
      public abstract class MedicalPersonnel extends Individual

      4.
      @Entity
      @Table(name = Names.TBL_NURSES)
      public class Nurse extends MedicalPersonnel

      5.
      @Entity
      @Table(name = Names.TBL_PHYSICIANS)
      public class Physician extends MedicalPersonnel

      In MedicalPersonnel I put the followings:

      public enum MedicalPersonnelType {
      PHYSICIAN, NURSE;
      }

      @Enumerated(EnumType.STRING)
      @Basic(optional = false)
      private MedicalPersonnelType medicalPersonnelType = getMedicalPersonnelType();

      @ManyToMany(mappedBy = MedicalDoc.PROP_MEDICAL_PERSONNELS, cascade = REFRESH)
      private Set medicalDocs = new HashSet();

      public abstract MedicalPersonnelType getMedicalPersonnelType();

      public Set getMedicalDocs() {
      return this.medicalDocs;
      }

      public void addMedicalDoc(MedicalDoc medicalDoc) {
      this.medicalDocs.add(medicalDoc);
      }


      In MedicalDoc i wrote the following code:

      @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
      private Set medicalPersonnels = new HashSet();

      public Set getMedicalPersonnels() {
      return this.medicalPersonnels;
      }
      public void addMedicalPersonnel(MedicalPersonnel medicalPersonnel) {
      this.medicalPersonnels.add(medicalPersonnel);
      medicalPersonnel.addMedicalDoc(this);
      }

      In Nurse I have:

      @Override
      public MedicalPersonnelType getMedicalPersonnelType() {
      return MedicalPersonnelType.NURSE;
      }

      and in Physician:

      @Override
      public MedicalPersonnelType getMedicalPersonnelType() {
      return MedicalPersonnelType.PHYSICIAN;
      }

      and when I've tried in my code to do
      MedicalPersonnel medicalP = em.merge(medicalPersonnel);

      I've got a ClassCastException :(

      What can I do against that. It's something missing in my code (annotations), is that a bug? Certainly it drives me crazy.

      Thx in advance for your help, jtonic.


      Full stack trace of any exception that occurs:
      javax.ejb.EJBException: java.lang.ClassCastException: ro.iqbyte.arhimed.model.core.common.entities.adm.Physician
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:58)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
      at $Proxy59.visit(Unknown Source)
      at ro.iqbyte.arhimed.core.client.UtilsServiceClient.visit(UtilsServiceClient.java:28)
      at ro.iqbyte.arhimed.medical.client.ui.providers.ops.MedicalDocumentsOpAdapter.addVoucher(MedicalDocumentsOpAdapter.java:150)
      at ro.iqbyte.arhimed.medical.client.ui.providers.ops.MedicalDocumentsOpAdapter.doExecuteOpAdd(MedicalDocumentsOpAdapter.java:121)
      at ro.iqbyte.arhimed.core.client.ui.providers.ops.AbstractOpAdapter.execute(AbstractOpAdapter.java:36)
      at ro.iqbyte.arhimed.core.client.ui.actions.view.adaptable.AdaptableAbstractOpGenericVAD.run(AdaptableAbstractOpGenericVAD.java:52)
      at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:254)
      at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:539)
      at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
      at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:441)
      at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
      at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
      at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
      at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
      at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
      at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
      at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
      at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
      at ro.iqbyte.arhimed.core.client.ui.app.Application.run(Application.java:58)
      at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
      at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
      at org.eclipse.core.launcher.Main.run(Main.java:977)
      at org.eclipse.core.launcher.Main.main(Main.java:952)
      Caused by: java.lang.ClassCastException: ro.iqbyte.arhimed.model.core.common.entities.adm.Physician
      at org.hibernate.type.LongType.set(LongType.java:42)
      at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
      at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
      at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
      at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
      at org.hibernate.loader.Loader.doQuery(Loader.java:661)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
      at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
      at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1565)
      at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:365)
      at org.hibernate.type.EntityType.resolve(EntityType.java:306)
      at org.hibernate.type.EntityType.replace(EntityType.java:207)
      at org.hibernate.type.TypeFactory.replace(TypeFactory.java:431)
      at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:282)
      at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:246)
      at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:99)
      at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:51)
      at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:679)
      at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:663)
      at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:667)
      at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:201)
      at org.jboss.ejb3.entity.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:181)
      at ro.iqbyte.arhimed.model.core.server.beans.UtilsServiceBean.visitMedicalPersonnel(UtilsServiceBean.java:89)
      at ro.iqbyte.arhimed.model.core.server.beans.UtilsServiceBean.visit(UtilsServiceBean.java:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:121)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:110)
      at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      ... 49 more


      Name and version of the database you are using: HSQL-1.8.0.4

      The generated SQL (show_sql=true):

      Debug level Hibernate log excerpt: