0 Replies Latest reply on Feb 14, 2007 11:18 AM by Carsten Rudat

    ClassCastException persist

    Carsten Rudat Novice

      Hi All,

      I have a problem, I cannot understand...

      I have two entites in a OneToOne-relationship:

      public class Konto ...
      
       @Id
       @GeneratedValue(strategy=GenerationType.TABLE, generator = "my_generator")
       @Column(name = "id")
       public java.lang.Long getId() {
       return this.id;
       }
      
       @OneToOne(cascade = {CascadeType.PERSIST,
       CascadeType.MERGE}, fetch = FetchType.EAGER)
       @JoinColumns({
       @JoinColumn(name="loanDecPxy_id_fk",
       referencedColumnName="id")
       })
       public LoanDecisionPxy getLoanDecisionPxy() {
       return this.loanDecisionPxy;
       }
      
       public void setLoanDecisionPxy(LoanDecisionPxy loanDecisionPxy) {
       this.loanDecisionPxy = loanDecisionPxy;
       }
      ...
      }
      
      
      and
      
      
      public class LoanDecisionPxy ...
      
       @OneToOne(mappedBy="loanDecisionPxy")
       public Konto getKonto() {
       return this.konto;
       }
      
       public void setKonto(Konto konto) {
       this.konto = konto;
       }
      ...
      }
      


      When i persist a "Konto" with a given "LoanDecisionPxy", which was persisted too, I get the following error (when the method ends and the transaction should be committed):


       java.lang.reflect.InvocationTargetException
      17:08:33,500 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      17:08:33,500 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      17:08:33,500 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      17:08:33,500 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      17:08:33,500 ERROR [STDERR] at com.genloop.session.base.SessionBase.createAction(SessionBase.java:2504)
      17:08:33,500 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      17:08:33,516 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      17:08:33,516 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      17:08:33,516 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.stateful.SessionSynchronizationInterceptor.invoke(SessionSynchronizationInterceptor.java:142)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      17:08:33,516 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
      17:08:33,516 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      17:08:33,516 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      17:08:33,516 ERROR [STDERR] Caused by: java.lang.ClassCastException: de.hanseatic.baufi.unterlagenmgmt.LoanDecisionPxy
      17:08:33,516 ERROR [STDERR] at org.hibernate.type.LongType.set(LongType.java:42)
      17:08:33,516 ERROR [STDERR] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
      17:08:33,516 ERROR [STDERR] at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
      17:08:33,516 ERROR [STDERR] at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1513)
      17:08:33,516 ERROR [STDERR] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1575)
      17:08:33,516 ERROR [STDERR] at org.hibernate.loader.Loader.doQuery(Loader.java:661)
      17:08:33,516 ERROR [STDERR] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      17:08:33,516 ERROR [STDERR] at org.hibernate.loader.Loader.loadEntity(Loader.java:1784)
      17:08:33,531 ERROR [STDERR] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
      17:08:33,531 ERROR [STDERR] at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
      17:08:33,531 ERROR [STDERR] at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1581)
      17:08:33,531 ERROR [STDERR] at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:365)
      17:08:33,531 ERROR [STDERR] at org.hibernate.type.EntityType.resolve(EntityType.java:306)
      17:08:33,531 ERROR [STDERR] at org.hibernate.type.EntityType.replace(EntityType.java:207)
      17:08:33,531 ERROR [STDERR] at org.hibernate.type.TypeFactory.replace(TypeFactory.java:437)
      17:08:33,531 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:340)
      17:08:33,531 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:267)
      17:08:33,531 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)
      17:08:33,547 ERROR [STDERR] at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
      17:08:33,547 ERROR [STDERR] at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
      17:08:33,547 ERROR [STDERR] at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
      17:08:33,547 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:390)
      17:08:33,547 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:266)
      



      I debugged the whole thing and I saw in "OneToOneType (extends EntityType)" the property "uniqueKeyPropertyName" for my "Konto" was set to "loanDecisionPxy". I didn't do that (see above).

      What can I do?


      I use JBoss 4.0.5.GA with build in Hibernate 3.2.GA.

      Thanks for help.

      Carsten