I think this one belongs in the Java Horror Stories somewhere. I bet none of
you guys/gals even noticed where the error was yet it was staring us all in
the face. It was in my setLinkSectionList setter... notice I did not call
this.linkSectionList(... rather I called linkSectionList(... without the
"this." appended. ARGHHHHHHHHHHH! Otherwise. It was all really simple. I
learned how retrieve a collection about 5 different ways though. So all is
good.

Thanks,
Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
[EMAIL PROTECTED]
http://www.phase.ws


> -----Original Message-----
> From: Phase Web and Multimedia [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 11, 2002 1:18 PM
> To: OJB Users List
> Subject: RE: MtoN Questions
>
>
> I have tried it both ways. It fails when I pass an integer and a
> String. It
> even fails when I do a cut and paste from the NtoMapping example from the
> OJB sample code.
>
> Brandon Goodin
> Phase Web and Multimedia
> P (406) 862-2245
> F (406) 862-0354
> [EMAIL PROTECTED]
> http://www.phase.ws
>
>
> > -----Original Message-----
> > From: Pete Gieser [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, December 11, 2002 12:50 PM
> > To: 'OJB Users List'
> > Subject: RE: MtoN Questions
> >
> >
> > Just a thought, does it matter if the database is storing
> > id as an int and you are using a String for it in your Criteria?
> > Maybe that's why there is no match, and hence an empty result.
> >
> > Pete
> >
> >
> > > -----Original Message-----
> > > From: Phase Web and Multimedia [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, December 11, 2002 1:04 PM
> > > To: OJB Users List
> > > Subject: RE: MtoN Questions
> > >
> > >
> > > Following is my code and my repository cut. I am still
> > > receiving no results
> > > and my database has all the data in the tables.
> > >
> > >
> > > --- method to get Category and LinkSectionList ---
> > >
> > > public static Collection linkSectionList(int categoryId) {
> > >
> > >           //Vector linkSectionList = new Vector();
> > >           Collection result = null;
> > >       Criteria criteria = new Criteria();
> > >           PersistenceBroker broker = null;
> > >
> > >           try {
> > >
> > >                   broker =
> > >
> > > PersistenceBrokerFactory.defaultPersistenceBroker();
> > >
> > >                   broker.clearCache();
> > >
> > >                   criteria.addEqualTo("id",
> > > String.valueOf(categoryId));
> > >
> > >                   Query query =
> > >                           new QueryByCriteria(
> > >                                   Category.class,
> > >                                   criteria);
> > >
> > >                   Category category=
> > > (Category)broker.getObjectByQuery(query);
> > >
> > >                   result = category.getLinkSectionList();
> > >
> > >
> > >           } catch (PBFactoryException ex) {
> > >                   logger.error(ex.getMessage(),
> > > ex.fillInStackTrace());
> > >
> > >           } finally {
> > >
> > >                   if (broker != null)
> > >                           broker.close();
> > >
> > >           }
> > >
> > >           return result;
> > >   }
> > >
> > > --- model bean ---
> > > /*
> > >  * Insert.java
> > >  *
> > >  * Created on September 17, 2002, 8:18 AM
> > >  */
> > >
> > > package ws.phase.content.model;
> > >
> > > import java.util.ArrayList;
> > > import java.util.List;
> > >
> > > import org.apache.commons.collections.ListUtils;
> > > import ws.phase.core.collections.GenericFactory;
> > > import ws.phase.core.db.DBBase;
> > > /**
> > >  *
> > >  * @author  Administrator
> > >  */
> > > public class Category extends DBBase implements java.io.Serializable {
> > >
> > >   private String name;
> > >   private String description;
> > >
> > >   private List linkSectionList;
> > >
> > >   private boolean selected;
> > >
> > >   /** Creates new Insert */
> > >   public Category() {
> > >           linkSectionList =
> > >                   ListUtils.lazyList(
> > >                           new ArrayList(),
> > >                           new
> > > GenericFactory("ws.phase.content.model.LinkSection"));
> > >   }
> > >
> > >   /** Getter for property name.
> > >    * @return Value of property name.
> > >    *
> > >    */
> > >   public java.lang.String getName() {
> > >           return name;
> > >   }
> > >
> > >   /** Setter for property name.
> > >    * @param name New value of property name.
> > >    *
> > >    */
> > >   public void setName(java.lang.String name) {
> > >           this.name = name;
> > >   }
> > >
> > >   /** Getter for property description.
> > >    * @return Value of property description.
> > >    *
> > >    */
> > >   public java.lang.String getDescription() {
> > >           return description;
> > >   }
> > >
> > >   /** Setter for property description.
> > >    * @param description New value of property description.
> > >    *
> > >    */
> > >   public void setDescription(java.lang.String description) {
> > >           this.description = description;
> > >   }
> > >
> > >   /** Getter for property selected.
> > >    * @return Value of property selected.
> > >    *
> > >    */
> > >   public boolean isSelected() {
> > >           return selected;
> > >   }
> > >
> > >   /** Setter for property selected.
> > >    * @param selected New value of property selected.
> > >    *
> > >    */
> > >   public void setSelected(boolean selected) {
> > >           this.selected = selected;
> > >   }
> > >
> > >   /**
> > >    * Returns the linkSectionList.
> > >    * @return List
> > >    */
> > >   public List getLinkSectionList() {
> > >           return linkSectionList;
> > >   }
> > >
> > >   /**
> > >    * Sets the linkSectionList.
> > >    * @param linkSectionList The linkSectionList to set
> > >    */
> > >   public void setLinkSectionList(List linkSectionList) {
> > >           linkSectionList =
> > >                   ListUtils.lazyList(
> > >                           linkSectionList,
> > >                           new
> > > GenericFactory("ws.phase.content.model.LinkSection"));
> > >   }
> > >
> > > }
> > >
> > > --- repository.xml section ---
> > >
> > > <collection-descriptor
> > >          name="linkSectionList"
> > >          element-class-ref="ws.phase.content.model.LinkSection"
> > >          auto-retrieve="true"
> > >          auto-update="true"
> > >          indirection-table="PH_CATEGORY_LINKSECTION"
> > >       >
> > >          <fk-pointing-to-this-class column="CATEGORY_ID"/>
> > >          <fk-pointing-to-element-class column="LINKSECTION_ID"/>
> > >       </collection-descriptor>
> > >
> > > Brandon Goodin
> > > Phase Web and Multimedia
> > > P (406) 862-2245
> > > F (406) 862-0354
> > > [EMAIL PROTECTED]
> > > http://www.phase.ws
> > >
> > >
> > > > -----Original Message-----
> > > > From: Raymond Lukas [mailto:[EMAIL PROTECTED]]
> > > > Sent: Wednesday, December 11, 2002 9:49 AM
> > > > To: OJB Users List
> > > > Subject: RE: MtoN Questions
> > > >
> > > >
> > > > Can I call you at the number below.. I will try and walk you through
> > > > this if I can.. Basically the trick is in the xml
> > > repository file..  I
> > > > just got this working so it is pretty fresh in my mind. It
> > > is not hard
> > > > just a little tricky.
> > > >
> > > > I started to send you my code but it is huge.. Instead maybe it is
> > > > better for me to point you to an example which you already
> > > have. If you
> > > > download the source version of OJB you will find the test
> > > scripts. They
> > > > have a lot of really good things in there. The one that I
> > > used to get
> > > > this working for me was the NtoMapping. I think that it is in
> > > > src/test/org/apache/obj/broker...
> > > > Also on the web page there is a section called advanced OR
> > > mapping. Look
> > > > at the section which talks about collection-descriptors.
> > > This is how you
> > > > describe a Vector inside of an java data object. Now you are lucky
> > > > because the intermediate table only contains the ids of the
> > > two tables
> > > > you are mapping.. This is the easier case. I have to run
> > > right now but
> > > > take
> > > > A few minutes and take a peek there. Just get one way
> > > working the other
> > > > way is exactly the same.
> > > >
> > > >
> > > > ------------------ data object definition
> > > > package com.cadence.apps.cadencepdk.model;
> > > >
> > > > import java.util.Collection;
> > > > import java.util.Iterator;
> > > > import java.io.Serializable;
> > > >
> > > > public class UserPrivileges implements Serializable {
> > > >
> > > >     private int userID;
> > > >     private Collection documents;
> > > >
> > > >     public UserPrivileges(){
> > > >     }
> > > >
> > > >     public int getUserID(){
> > > >         return userID;
> > > >     }
> > > >     public Collection getDocuments(){
> > > >         return documents;
> > > >     }
> > > >
> > > >     public void setUserID(int userID){
> > > >         this.userID = userID;
> > > >     }
> > > >     public void setDocuments(Collection documents){
> > > >         this.documents = documents;
> > > >     }
> > > >
> > > >     public String toString(){
> > > >         String returnStr = "UserPrivileges userID=>" +
> > > userID + "\n";
> > > >         if (documents != null){
> > > >             Iterator objIter = documents.iterator();
> > > >             while (objIter.hasNext()){
> > > >                 if (returnStr != null){
> > > >                     returnStr = returnStr + "\n" +
> > > > (Document)objIter.next();
> > > >                 }
> > > >                 else {
> > > >                     returnStr = "\n" + (Document)objIter.next();
> > > >                 }
> > > >             }
> > > >         }
> > > >         else {
> > > >             returnStr = returnStr + "\n documents is NULL";
> > > >         }
> > > >         return returnStr;
> > > >     }
> > > > }
> > > >
> > > > ------------------------------------------ the query
> > > >
> > > >     public Response execute(){
> > > >         //  this give me all the docs this user can access.
> > > >         //  with the filters you requested
> > > >         ResponseImpl response = null;
> > > >         List userAccessDocs = new Vector();
> > > >             UserPrivileges  userObj = new UserPrivileges();
> > > >                 //      super criteria is just a
> > > criteria object which
> > > > filters the             //      results, for now you
> > > can just pass
> > > > null..
> > > >             Query query = new QueryByCriteria(UserPrivileges.class,
> > > > super.criteria);
> > > >
> > > >         try {
> > > >             broker.beginTransaction();
> > > >                         userObj = (UserPrivileges)
> > > > broker.getObjectByQuery(query);
> > > >
> userAccessDocs.addAll(userObj.getDocuments());
> > > >                         broker.commitTransaction();
> > > >         }
> > > >         catch (Exception exc) {
> > > >             exc.printStackTrace();
> > > >         }
> > > >
> > > >
> > > > IN THE XML FILE UNDER UserPrivileges
> > > >
> > > >         <collection-descriptor name="documents"
> > > >
> > > > element-class-ref="com.cadence.apps.cadencepdk.model.Document"
> > > >                 auto-retrieve = "true"
> > > >                 auto-update = "false"
> > > >                 indirection-table = "udaccess">
> > > >                 <fk-pointing-to-this-class column="userid"/>
> > > >                 <fk-pointing-to-element-class column="docid"/>
> > > >         </collection-descriptor>
> > > >
> > > >
> > > > I am sorry for the disorganized brain dump.. Listen if you need some
> > > > more help send me an email at [EMAIL PROTECTED] I will
> > > try and grab
> > > > some time and call you if I can.. Okay.. I ma just working
> > > like crazy
> > > > but I promised myself that if I got it working I would help
> > > someone else
> > > > get it working.. I got to run now though, let me know how
> > > this works out
> > > > for you.. :)
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <mailto:ojb-user-> [EMAIL PROTECTED]>
> > > > For
> > > additional commands,
> > > e-mail: <mailto:[EMAIL PROTECTED]>
> > > >
> > > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:ojb-user-> [EMAIL PROTECTED]>
> > > For
> > > additional commands,
> > > e-mail: <mailto:[EMAIL PROTECTED]>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
> >
>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to