I still am unable to retrieve objects from the database. I've stepped through the code, but am having problems understanding what is going on.
At line 158 of org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessIm plNew.java setValueFor() is being called with the Field's name = clientRelationship, and the type=Class model.client.ClientRelationship. However, the target and value objects are the same object (they have the same id), and are type NewClientGroup. Shouldn't the target and value objects be of type ClientRelationship? The other thing I noticed is the second time I run my code I don't get an exception, but I also don't get the NewClientGroups. I'm assuming this has something to do with the caching... -----Original Message----- From: Lemke, Wesley Sent: Tuesday, March 22, 2005 12:55 PM To: 'OJB Users List' Subject: RE: Updating instead of Inserting I am persisting the objects fine now, but I am getting an error when retrieving: [3/22/05 12:44:43:008 CST] 39432342 SystemOut O [PersistentField] ERROR: while set field: [try to set 'object value' in 'target object' target obj class: model.client.NewClientGroup target field name: clientRelationship target field type: class model.client.ClientRelationship object value class: model.client.NewClientGroup object value: [EMAIL PROTECTED] ] Here are the pertinent parts of repository.xml: In the class-descriptor for ClientRelationship: <collection-descriptor name="clientGroups" element-class-ref="model.client.NewClientGroup" auto-delete="true" auto-update="true" > <inverse-foreignkey field-ref="clientRelationshipId" /> </collection-descriptor> In the class-descriptor for NewClientGroup: <reference-descriptor name="clientRelationship" class-ref="model.client.ClientRelationship"> <foreignkey field-ref="objectId"/> </reference-descriptor> In the NewClientGroup Class: private ClientRelationship clientRelationship; // with getter and setter defined. Here is the code I am running: Query q = new QueryByCriteria(ClientRelationship.class); Collection clientRelationships = broker.getCollectionByQuery(q); <-- exception thrown here. Iterator i = clientRelationships.iterator(); writer.println("<br><br>"); while (i.hasNext()) { ClientRelationship cr2 = (ClientRelationship) i.next(); writer.println(cr2.getNameOfApproverOfNoContract()); List clientGroups = cr2.getClientGroups(); } I am assuming that when OJB pulls back the ClientRelationships, it is also pulling back the collection of NewClientGroups (and Subgroups). When it instantiates the NewClientGroup it is trying to set the clientRelationship field. Why is it trying to set it to a NewClientGroup, instead of the associated ClientRelationship? Here is the entire stack trace if it helps: [3/22/05 12:44:42:998 CST] 39432342 SystemOut O [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.CLASS_NAME,A0.client_grp_id,A0.INN_CLIENT_NB,A0.client_id,A0.LAST_MOD IFIED_USER,A0.SDD_COMP_I,A0.LAST_NAME_DT,A0.ETL_CLIENT_ID,A0.KEY_WORDS,A 0.LAST_NAME,A0.MAIL_MEMBERS,A0.PRIMARY_GRP_I,A0.group_id,A0.COMMENTS,A0. REPORTS_DESC,A0.EFF_DT,A0.NAME FROM client_group A0 WHERE ( A0.client_id = ?) AND (A0.CLASS_NAME = ?) [3/22/05 12:44:43:078 CST] 39432342 SystemErr R org.apache.ojb.broker.metadata.MetadataException: IllegalAccess error setting field:clientRelationship in object:model.client.NewClientGroup at org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessIm plNew.setValueFor(Unknown Source) at org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessIm plNew.set(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReference(Unknow n Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReferences(Unkno wn Source) at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unkn own Source) at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(Un known Source) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Un known Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Un known Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu ery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu ery(Unknown Source) at servlets.InheritanceServlet.doPost(InheritanceServlet.java:79) at servlets.InheritanceServlet.doGet(InheritanceServlet.java:44) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictSe rvletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLi fecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycle Servlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLif ecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance. java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(Vali dServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(Servle tInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa tch(WebAppRequestDispatcher.java:948) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe questDispatcher.java:530) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq uestDispatcher.java:176) at com.ibm.ws.webcontainer.servlet.InvokerServlet.service(InvokerServlet.ja va:255) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictSe rvletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLi fecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycle Servlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLif ecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance. java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(Vali dServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(Servle tInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa tch(WebAppRequestDispatcher.java:948) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe questDispatcher.java:530) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq uestDispatcher.java:176) at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:7 9) at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInv oker.java:201) at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocati on(CachedInvocation.java:71) at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Servle tRequestProcessor.java:182) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSELis tener.java:334) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection .java:56) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java: 610) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:431) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593) Caused by: java.lang.IllegalArgumentException: field type mismatch at java.lang.reflect.Field.set(Native Method) ... 49 more [3/22/05 12:44:43:008 CST] 39432342 SystemOut O [PersistentField] ERROR: while set field: [try to set 'object value' in 'target object' target obj class: model.client.NewClientGroup target field name: clientRelationship target field type: class model.client.ClientRelationship object value class: model.client.NewClientGroup object value: [EMAIL PROTECTED] ] [3/22/05 12:44:47:865 CST] 39432342 WebGroup E SRVE0026E: [Servlet Error]-[servlets.InheritanceServlet]: org.apache.ojb.broker.PersistenceBrokerException: org.apache.ojb.broker.metadata.MetadataException: IllegalAccess error setting field:clientRelationship in object:model.client.NewClientGroup at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Un known Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu ery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu ery(Unknown Source) at servlets.InheritanceServlet.doPost(InheritanceServlet.java:79) at servlets.InheritanceServlet.doGet(InheritanceServlet.java:44) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictSe rvletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLi fecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycle Servlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLif ecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance. java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(Vali dServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(Servle tInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa tch(WebAppRequestDispatcher.java:948) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe questDispatcher.java:530) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq uestDispatcher.java:176) at com.ibm.ws.webcontainer.servlet.InvokerServlet.service(InvokerServlet.ja va:255) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictSe rvletInstance.java:110) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLi fecycleServlet.java:174) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycle Servlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLif ecycleServlet.java:116) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance. java:283) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(Vali dServletReferenceState.java:42) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(Servle tInstanceReference.java:40) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa tch(WebAppRequestDispatcher.java:948) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe questDispatcher.java:530) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq uestDispatcher.java:176) at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:7 9) at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInv oker.java:201) at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocati on(CachedInvocation.java:71) at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Servle tRequestProcessor.java:182) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSELis tener.java:334) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection .java:56) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java: 610) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:431) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593) Caused by: org.apache.ojb.broker.metadata.MetadataException: IllegalAccess error setting field:clientRelationship in object:model.client.NewClientGroup at org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessIm plNew.setValueFor(Unknown Source) at org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessIm plNew.set(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReference(Unknow n Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveReferences(Unkno wn Source) at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unkn own Source) at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(Un known Source) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Un known Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk nown Source) ... 40 more Caused by: java.lang.IllegalArgumentException: field type mismatch at java.lang.reflect.Field.set(Native Method) ... 49 more -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 22, 2005 9:22 AM To: OJB Users List Subject: Re: Updating instead of Inserting Lemke, Wesley wrote: > Thanks Armen, that worked. I've made this same mistake before, you > would think I'd learn :) > ...you are in good company, the history of mankind is an endless list of repeated mistakes ;-) > The AdmObject will have many more extents in the full application. > Every persistent class will extend it, or a subclass of it. I only > had one class extending it in this subset. > I ask this each time, because using inheritance can be a performance killer and should be avoided if possible. So if you don't regular need query for AdmObject's, don't declare the mapping. Armin > -----Original Message----- > From: Armin Waibel [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 22, 2005 8:38 AM > To: OJB Users List > Subject: Re: Updating instead of Inserting > > > Hi Wes, > > why did you need mapping for AdmObject when only one class "extent" > AdmObject? > > In mapping for NCG > > <collection-descriptor > name="subgroups" > element-class-ref="model.client.Subgroup" > auto-delete="true" > auto-update="true" > > > <inverse-foreignkey field-ref="objectId" /> > </collection-descriptor> > > the inverse-foreignkey refer to the PK field of SG. Think this is not > correct, you need a FK field in SG to store the PK value of NCG. This FK > > field must also be used by the 'clientGroup' reference in SG [don't > use an anomymous field, because of the 1:n relation > http://db.apache.org/ojb/docu/guides/advanced-technique.html#How+do+ > ] > > regards, > Armin > > > > Lemke, Wesley wrote: > >>I have 4 classes: >> >>AdmObject -- highlevel class that all of our persistent classes >>extend. Contains objectId field. Generic Group -- Abstract. Extends >>AdmObject. Contains common fields for NewClientGroup and Subgroup and > > >>the ojbConcreteClass. NewClientGroup -- extends Generic Group, >>contains a collection of Subgroups. >>Subgroup -- extends Generic Group. Has a reference to the >>NewClientGroup. >> >>I am trying to persist NewClientGroup and Subgroup (along with common >>fields in Generic Group) to the same table. Here is a portion of my >>mapping document (most of the common fields from Generic group are >>removed to simplifiy): >> >><class-descriptor >> class="model.AdmObject"> >> <extent-class class-ref="model.client.GenericGroup" /> >></class-descriptor> >> >><class-descriptor >> class="model.client.GenericGroup"> >> <extent-class class-ref="model.client.Subgroup" /> >> <extent-class class-ref="model.client.NewClientGroup" /> >></class-descriptor> >> >><class-descriptor >> class="model.client.NewClientGroup" >> table="client_group"> >> <field-descriptor >> name="objectId" >> column="group_id" >> jdbc-type="INTEGER" >> primarykey="true" >> autoincrement="true" >> access="readonly" >> /> >> <field-descriptor >> name="internalClientNumber" >> column="INN_CLIENT_NB" >> jdbc-type="VARCHAR" >> /> >> <field-descriptor >> name="ojbConcreteClass" >> column="CLASS_NAME" >> jdbc-type="VARCHAR" >> /> >> <collection-descriptor >> name="subgroups" >> element-class-ref="model.client.Subgroup" >> auto-delete="true" >> auto-update="true" >> > >> <inverse-foreignkey field-ref="objectId" /> >> </collection-descriptor> >></class-descriptor> >><class-descriptor >> class="model.client.Subgroup" >> table="client_group" >> > >> <field-descriptor >> name="objectId" >> column="group_id" >> jdbc-type="INTEGER" >> primarykey="true" >> autoincrement="true" >> access="readonly" >> /> >> <field-descriptor >> name="name" >> column="NAME" >> jdbc-type="VARCHAR" >> /> >> <field-descriptor >> name="ojbConcreteClass" >> column="CLASS_NAME" >> jdbc-type="VARCHAR" >> /> >> <reference-descriptor name="clientGroup" >>class-ref="model.client.NewClientGroup"> >> <foreignkey field-ref="objectId"/> >> </reference-descriptor> >></class-descriptor> >> >>Here is the code I am using: >> broker.beginTransaction(); >> NewClientGroup ncg = new NewClientGroup(); >> ncg.setInternalClientNumber("IntClntNbr"); >> Subgroup sg = new Subgroup(); >> sg.setName("FirstSubgroup"); >> ncg.addSubgroup(sg); >> Subgroup sg2 = new Subgroup(); >> sg.setName("Second Subgroup"); >> ncg.addSubgroup(sg2); >> broker.store(ncg); >> broker.commitTransaction(); >> >>I would assume that after the above code, there would be one >>NewClientGroup and 2 Subgroups in my client_group table. However, >>there is only one row, the Second Subgroup. Here is the debug SQL >>generated: >> >>DEBUG: SQL:INSERT INTO client_group (INN_CLIENT_NB,CLASS_NAME) VALUES >>(?,?) >>DEBUG: SQL:UPDATE client_group SET NAME=?,CLASS_NAME=? WHERE group_id > > = > >>? >> >>Am I doing something wrong with my mapping or code? Is it possible to > > >>persist these classes to the same table? >> >>Any help would be appreciated. >> >>Thanks, >>Wes >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]