0 Replies Latest reply on Feb 1, 2006 5:20 PM by Michael Small

    EntityManager.merge() throws SQL Exception : could not find

    Michael Small Newbie

      I have a strange error occuring when I attempt to merge an EJB entity. Here's the overview, there is an embedded superclass named ValueObject that defines the primary key for all class inheriting from it. In this case, I have a entity named Relationship. A Relationship entity has a @OneToOne with another entity named Provider. When I attempt to call entityManager.merge(relationship), I get the following stack trace:

      org.hibernate.exception.GenericJDBCException: could not load an entity: [com.tasconline.provider.Provider#com.tasconline.relationship.Relationship@ec9361[internalKey=40,created=2006-01-30 08:23:10.0,createdBy=com.tasconline.relationship.RelationshipId@107e9af[id=0000000-0000001],lastUpdated=2006-01-30 08:23:10.0,lastUpdatedBy=com.tasconline.relationship.RelationshipId@1b60b98[id=0000000-0000001],version=0,relationshipId=com.tasconline.relationship.RelationshipId@95159b[id=4400000-0003939],loginId=com.tasconline.relationship.LoginId@103c2db[id=leadingedge],authenticationType=NATIVE,lockedOut=false]]
       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
       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:93)
       at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:85)
       at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1521)
       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:279)
       at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:245)
       at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:102)
       at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
       at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:636)
       at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:622)
       at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:140)
       at org.jboss.ejb3.entity.InjectedEntityManager.merge(InjectedEntityManager.java:102)
       at com.tasconline.util.service.bean.NoteServiceBean.addNoteAssociation(NoteServiceBean.java:299)
       at com.tasconline.util.service.bean.NoteServiceBean.addNote(NoteServiceBean.java:176)
       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.invokeNext(MethodInvocation.java:109)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:66)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:151)
       at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:85)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:204)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:37)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
       at $Proxy222.addNote(Unknown Source)
       at com.tasconline.note.web.ui.event.action.AddNoteAjaxAction.performAction(AddNoteAjaxAction.java:63)
       at com.tasconline.web.ui.ajax.AjaxPhaseListener.handleRequest(AjaxPhaseListener.java:96)
       at com.tasconline.web.ui.ajax.AjaxPhaseListener.afterPhase(AjaxPhaseListener.java:77)
       at org.apache.myfaces.lifecycle.LifecycleImpl.informPhaseListenersAfter(LifecycleImpl.java:536)
       at org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:164)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at com.tasconline.security.web.ui.filter.SecurityFilter.doFilter(SecurityFilter.java:102)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at com.tasconline.web.ui.filter.InitializeFilter.doFilter(InitializeFilter.java:67)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       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:595)
      Caused by: java.sql.SQLException: Statement parameter 1 not set.
       at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:992)
       at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)
       at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)
       at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:211)
       at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
       at org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
       at org.hibernate.loader.Loader.doQuery(Loader.java:662)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
       at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
       ... 81 more
      
      


      Looking into the server.log in jboss, I came across the following problem:

      2006-02-01 15:39:40,540 DEBUG [org.hibernate.SQL] select provider0_.internalKey as internal1_13_10_, provider0_.version as version13_10_, provider0_.created as created13_10_, provider0_.createdBy as createdBy13_10_, provider0_.lastUpdated as lastUpda5_13_10_, provider0_.lastUpdatedBy as lastUpda6_13_10_, provider0_.fk_tasc_relationship as fk11_13_10_, provider0_.taxId as taxId13_10_, provider0_.taxFilingStatus as taxFilin8_13_10_, provider0_.primaryContact_fk_tasc_contact as primary12_13_10_, provider0_.organizationName as organiza9_13_10_, provider0_.circleStatus as circleS10_13_10_, contacts1_.fk_tasc_contact as fk1_12_, contact2_.internalKey as fk2_12_, contact2_.internalKey as internal1_25_0_, contact2_.version as version25_0_, contact2_.created as created25_0_, contact2_.createdBy as createdBy25_0_, contact2_.lastUpdated as lastUpda5_25_0_, contact2_.lastUpdatedBy as lastUpda6_25_0_, contact2_.address1 as address7_25_0_, contact2_.address2 as address8_25_0_, contact2_.city as city25_0_, contact2_.state as state25_0_, contact2_.deliveryArea as deliver11_25_0_, contact2_.plusFour as plusFour25_0_, contact2_.lastName as lastName25_0_, contact2_.firstName as firstName25_0_, contact2_.middleName as middleName25_0_, contact2_.emailAddress as emailAd16_25_0_, contact2_.fk_tasc_relationship as fk34_25_0_, contact2_.contactId as contactId25_0_, contact2_.homeNumberNumber as homeNum18_25_0_, contact2_.homeNumberExtension as homeNum19_25_0_, contact2_.homeNumberAreaCode as homeNum20_25_0_, contact2_.homeNumberTrunk as homeNum21_25_0_, contact2_.businessNumberNumber as busines22_25_0_, contact2_.businessNumberExtension as busines23_25_0_, contact2_.businessNumberAreaCode as busines24_25_0_, contact2_.businessNumberTrunk as busines25_25_0_, contact2_.faxNumberNumber as faxNumb26_25_0_, contact2_.faxNumberExtension as faxNumb27_25_0_, contact2_.faxNumberAreaCode as faxNumb28_25_0_, contact2_.faxNumberTrunk as faxNumb29_25_0_, contact2_.mobileNumberNumber as mobileN30_25_0_, contact2_.mobileNumberExtension as mobileN31_25_0_, contact2_.mobileNumberAreaCode as mobileN32_25_0_, contact2_.mobileNumberTrunk as mobileN33_25_0_, relationsh3_.internalKey as internal1_16_1_, relationsh3_.version as version16_1_, relationsh3_.created as created16_1_, relationsh3_.createdBy as createdBy16_1_, relationsh3_.lastUpdated as lastUpda5_16_1_, relationsh3_.lastUpdatedBy as lastUpda6_16_1_, relationsh3_.relationshipId as relation7_16_1_, relationsh3_.loginId as loginId16_1_, relationsh3_.pin as pin16_1_, relationsh3_.authenticationType as authent10_16_1_, relationsh3_.lockedOut as lockedOut16_1_, relationsh4_.internalKey as internal1_16_2_, relationsh4_.version as version16_2_, relationsh4_.created as created16_2_, relationsh4_.createdBy as createdBy16_2_, relationsh4_.lastUpdated as lastUpda5_16_2_, relationsh4_.lastUpdatedBy as lastUpda6_16_2_, relationsh4_.relationshipId as relation7_16_2_, relationsh4_.loginId as loginId16_2_, relationsh4_.pin as pin16_2_, relationsh4_.authenticationType as authent10_16_2_, relationsh4_.lockedOut as lockedOut16_2_, client5_.internalKey as internal1_4_3_, client5_.version as version4_3_, client5_.created as created4_3_, client5_.createdBy as createdBy4_3_, client5_.lastUpdated as lastUpda5_4_3_, client5_.lastUpdatedBy as lastUpda6_4_3_, client5_.fk_tasc_relationship as fk10_4_3_, client5_.taxId as taxId4_3_, client5_.taxFilingStatus as taxFilin8_4_3_, client5_.clientName as clientName4_3_, client5_.primaryContact_fk_tasc_contact as primary11_4_3_, tascforce6_.internalKey as internal1_24_4_, tascforce6_.version as version24_4_, tascforce6_.created as created24_4_, tascforce6_.createdBy as createdBy24_4_, tascforce6_.lastUpdated as lastUpda5_24_4_, tascforce6_.lastUpdatedBy as lastUpda6_24_4_, tascforce6_.fk_tasc_relationship as fk7_24_4_, tascforce6_.fk_tasc_contact as fk8_24_4_, participan7_.internalKey as internal1_12_5_, participan7_.version as version12_5_, participan7_.created as created12_5_, participan7_.createdBy as createdBy12_5_, participan7_.lastUpdated as lastUpda5_12_5_, participan7_.lastUpdatedBy as lastUpda6_12_5_, participan7_.fk_tasc_relationship as fk8_12_5_, participan7_.ssn as ssn12_5_, participan7_.fk_tasc_contact as fk9_12_5_, notes8_.fk_tasc_note as fk1_13_, note9_.internalKey as fk2_13_, note9_.internalKey as internal1_10_6_, note9_.version as version10_6_, note9_.created as created10_6_, note9_.createdBy as createdBy10_6_, note9_.lastUpdated as lastUpda5_10_6_, note9_.lastUpdatedBy as lastUpda6_10_6_, note9_.contents as contents10_6_, note9_.noteId as noteId10_6_, assignedro10_.fk_tasc_role as fk1_14_, role11_.internalKey as fk2_14_, role11_.internalKey as internal1_19_7_, role11_.version as version19_7_, role11_.created as created19_7_, role11_.createdBy as createdBy19_7_, role11_.lastUpdated as lastUpda5_19_7_, role11_.lastUpdatedBy as lastUpda6_19_7_, role11_.name as name19_7_, contact12_.internalKey as internal1_25_8_, contact12_.version as version25_8_, contact12_.created as created25_8_, contact12_.createdBy as createdBy25_8_, contact12_.lastUpdated as lastUpda5_25_8_, contact12_.lastUpdatedBy as lastUpda6_25_8_, contact12_.address1 as address7_25_8_, contact12_.address2 as address8_25_8_, contact12_.city as city25_8_, contact12_.state as state25_8_, contact12_.deliveryArea as deliver11_25_8_, contact12_.plusFour as plusFour25_8_, contact12_.lastName as lastName25_8_, contact12_.firstName as firstName25_8_, contact12_.middleName as middleName25_8_, contact12_.emailAddress as emailAd16_25_8_, contact12_.fk_tasc_relationship as fk34_25_8_, contact12_.contactId as contactId25_8_, contact12_.homeNumberNumber as homeNum18_25_8_, contact12_.homeNumberExtension as homeNum19_25_8_, contact12_.homeNumberAreaCode as homeNum20_25_8_, contact12_.homeNumberTrunk as homeNum21_25_8_, contact12_.businessNumberNumber as busines22_25_8_, contact12_.businessNumberExtension as busines23_25_8_, contact12_.businessNumberAreaCode as busines24_25_8_, contact12_.businessNumberTrunk as busines25_25_8_, contact12_.faxNumberNumber as faxNumb26_25_8_, contact12_.faxNumberExtension as faxNumb27_25_8_, contact12_.faxNumberAreaCode as faxNumb28_25_8_, contact12_.faxNumberTrunk as faxNumb29_25_8_, contact12_.mobileNumberNumber as mobileN30_25_8_, contact12_.mobileNumberExtension as mobileN31_25_8_, contact12_.mobileNumberAreaCode as mobileN32_25_8_, contact12_.mobileNumberTrunk as mobileN33_25_8_, billingcon13_.fk_tasc_contact as fk1_15_, contact14_.internalKey as fk2_15_, contact14_.internalKey as internal1_25_9_, contact14_.version as version25_9_, contact14_.created as created25_9_, contact14_.createdBy as createdBy25_9_, contact14_.lastUpdated as lastUpda5_25_9_, contact14_.lastUpdatedBy as lastUpda6_25_9_, contact14_.address1 as address7_25_9_, contact14_.address2 as address8_25_9_, contact14_.city as city25_9_, contact14_.state as state25_9_, contact14_.deliveryArea as deliver11_25_9_, contact14_.plusFour as plusFour25_9_, contact14_.lastName as lastName25_9_, contact14_.firstName as firstName25_9_, contact14_.middleName as middleName25_9_, contact14_.emailAddress as emailAd16_25_9_, contact14_.fk_tasc_relationship as fk34_25_9_, contact14_.contactId as contactId25_9_, contact14_.homeNumberNumber as homeNum18_25_9_, contact14_.homeNumberExtension as homeNum19_25_9_, contact14_.homeNumberAreaCode as homeNum20_25_9_, contact14_.homeNumberTrunk as homeNum21_25_9_, contact14_.businessNumberNumber as busines22_25_9_, contact14_.businessNumberExtension as busines23_25_9_, contact14_.businessNumberAreaCode as busines24_25_9_, contact14_.businessNumberTrunk as busines25_25_9_, contact14_.faxNumberNumber as faxNumb26_25_9_, contact14_.faxNumberExtension as faxNumb27_25_9_, contact14_.faxNumberAreaCode as faxNumb28_25_9_, contact14_.faxNumberTrunk as faxNumb29_25_9_, contact14_.mobileNumberNumber as mobileN30_25_9_, contact14_.mobileNumberExtension as mobileN31_25_9_, contact14_.mobileNumberAreaCode as mobileN32_25_9_, contact14_.mobileNumberTrunk as mobileN33_25_9_ from tasc_provider provider0_ left outer join tasc_provider_contact contacts1_ on provider0_.internalKey=contacts1_.fk_tasc_contact left outer join tasc_contact contact2_ on contacts1_.fk_tasc_provider=contact2_.internalKey left outer join tasc_relationship relationsh3_ on contact2_.fk_tasc_relationship=relationsh3_.internalKey left outer join tasc_relationship relationsh4_ on provider0_.fk_tasc_relationship=relationsh4_.internalKey left outer join tasc_client client5_ on relationsh4_.internalKey=client5_.fk_tasc_relationship left outer join tasc_tascforce tascforce6_ on relationsh4_.internalKey=tascforce6_.fk_tasc_relationship left outer join tasc_participant participan7_ on relationsh4_.internalKey=participan7_.fk_tasc_relationship left outer join tasc_relationship_note notes8_ on relationsh4_.internalKey=notes8_.fk_tasc_note left outer join tasc_note note9_ on notes8_.fk_tasc_relationship=note9_.internalKey left outer join tasc_relationship_role assignedro10_ on relationsh4_.internalKey=assignedro10_.fk_tasc_role left outer join tasc_role role11_ on assignedro10_.fk_tasc_relationship=role11_.internalKey left outer join tasc_contact contact12_ on provider0_.primaryContact_fk_tasc_contact=contact12_.internalKey left outer join tasc_provider_billing_contact billingcon13_ on provider0_.internalKey=billingcon13_.fk_tasc_contact left outer join tasc_contact contact14_ on billingcon13_.fk_tasc_provider=contact14_.internalKey where provider0_.fk_tasc_relationship=?
      2006-02-01 15:39:40,540 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
      2006-02-01 15:39:40,545 DEBUG [org.hibernate.type.LongType] binding 'com.tasconline.relationship.Relationship@4e80d3[internalKey=42,created=2006-01-30 08:23:10.0,createdBy=com.tasconline.relationship.RelationshipId@adab12[id=0000000-0000001],lastUpdated=2006-01-30 08:23:10.0,lastUpdatedBy=com.tasconline.relationship.RelationshipId@e90879[id=0000000-0000001],version=0,relationshipId=com.tasconline.relationship.RelationshipId@1059fd6[id=4820000-0004127],loginId=com.tasconline.relationship.LoginId@2f3d17[id=douglasinsurance],authenticationType=NATIVE,lockedOut=false]' to parameter: 1
      2006-02-01 15:39:40,545 INFO [org.hibernate.type.LongType] could not bind value 'com.tasconline.relationship.Relationship@4e80d3[internalKey=42,created=2006-01-30 08:23:10.0,createdBy=com.tasconline.relationship.RelationshipId@adab12[id=0000000-0000001],lastUpdated=2006-01-30 08:23:10.0,lastUpdatedBy=com.tasconline.relationship.RelationshipId@e90879[id=0000000-0000001],version=0,relationshipId=com.tasconline.relationship.RelationshipId@1059fd6[id=4820000-0004127],loginId=com.tasconline.relationship.LoginId@2f3d17[id=douglasinsurance],authenticationType=NATIVE,lockedOut=false]' to parameter: 1
      
      


      It looks like the whole Relationship entity is being set as the statement parameter instead of it's primary key. Even more stranglely, other bits of code where I call entityManager.merge(relationship) do work correctly. Any ideas why this is occuring?