You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Paul Joseph <pj...@yahoo.com> on 2004/10/09 15:49:11 UTC

how to persist a Collection property to postgresql using jdo

Hi,

Basic question is - how does on persist a Java
Collection datatype to a postrgest table using jdo?

I am trying to persist a Collection property in a
bean, to a postgresql db, using JDO, but don't know
the datatype to use for this field in the table, and
also in the repository.xml.

I am using the following functions in the binding file
and (by means of the debug statement) see that the
correct values come through from my test bean (which
is currently non-persistent).

    <fb:javascript id="multivaluewidget" path="."
direction="load">
      <fb:load-form>
      var bean = jxpathPointer.getNode(); 
      var selection = bean.getUserChoices();
      java.lang.System.out.println("from the load
action in the binding, the bean values are: " +
bean.toString());
      widget.setValue(selection);
      java.lang.System.out.println("Selection is: " +
selection);
     </fb:load-form>
    </fb:javascript>

     <fb:javascript id="multivaluewidget" path="."
direction="save">
       <fb:save-form>
         var formValue = widget.getValue();
         var collection = new java.util.ArrayList();
         for(var i=0; i&lt;formValue.length; i++) {
           collection.add(new
java.lang.Integer(formValue[i]));
         }
         var bean = jxpathPointer.getNode();
         bean.setUserChoices(collection);
       </fb:save-form>
     </fb:javascript>

What datatypes should I use in the table and
repository.xml?  

I tried integer[] for the column data type and ARRAY
in the repository.xml, and various combinations, but
am not having much success....

Basic question is - how does on persist a collection
to a postrgest table using jdo?

thx
Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: how to persist a Collection property to postgresql using jdo

Posted by Paul Joseph <pj...@yahoo.com>.
I am using OJB/JDO from Apache/Sun.  

I am using a postrgesql database.

I do have an enhanced class with the following method:

class MyClass
{
   Vector collToPersist;

   void setCollToPersist(Vector collToPersist) {
       this.collToPersist = collToPersist;
   }

   Vector getCollToPersist() {
       return collToPerist;
   }
}

This part works - the problem I have is how do I
persist this to a table in a database, in a single
column (not multiple rows of a child table)

thx
Paul
--- Luca Garulli <l....@gmail.com> wrote:

> Hi,
> the right way to persist a collection in JDO is to
> create a class for
> the purpose with a collection member:
> 
> class MyClass
> {
>   Vector collToPersist;
> }
> 
> Then enhance the class and define the .jdo files and
> map the class to database.
> 
> What JDO implementation you are using?
> 
> 
> On Sat, 9 Oct 2004 12:01:22 -0700 (PDT), Paul Joseph
> <pj...@yahoo.com> wrote:
> > Thank you very much for the reply.  I think I
> > understand your method.
> > 
> > To simplify things however, I would like to save
> the
> > users selection as a column in the same table
> (parent)
> > and not in a separate table (child)
> > 
> > Thus the column will get data like [1,4] from the
> > multivalue widget, if the user chooses item ids
> 1,4 in
> > the multiselect.
> > 
> > The widget is using a set method in the fb:save
> that
> > sets a property that is a Java Collection.
> > 
> > My debug statments indicate it is trying to save
> > something like this [1,4] or [3,6,8] and so on.
> > 
> > so, to be more clear, I am trying to save a
> property
> > of type java.util.Collection in a column of table
> > Parent, in a postgresql db.
> > 
> > thx
> > Paul
> > 
> > 
> > --- Joose Vettenranta <jo...@iki.fi> wrote:
> > 
> > > >
> > > > Basic question is - how does on persist a
> > > collection
> > > > to a postrgest table using jdo?
> > >
> > > Normally collection is just a 1:n connection to
> > > another table, like
> > >
> > > create table parent (id integer);
> > > create table child (id integer, parent integer);
> > >
> > > so you map parent to have collection Childs and
> then
> > > that Childs
> > > collection you map to be of that child table.
> > >
> > > - Joose
> > >
> > > --
> > > "Always remember that you are unique, just like
> > > everyone else!"
> > > * http://iki.fi/joose/ * joose@iki.fi * +358 44
> 561
> > > 0270 *
> > >
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail:
> > > users-help@cocoon.apache.org
> > >
> > >
> > 
> > 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail:
> users-help@cocoon.apache.org
> > 
> > 
> 
> 
> -- 
> bye,
> Luca Garulli
> www.OrienTechnologies.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: how to persist a Collection property to postgresql using jdo

Posted by Luca Garulli <l....@gmail.com>.
Hi,
the right way to persist a collection in JDO is to create a class for
the purpose with a collection member:

class MyClass
{
  Vector collToPersist;
}

Then enhance the class and define the .jdo files and map the class to database.

What JDO implementation you are using?


On Sat, 9 Oct 2004 12:01:22 -0700 (PDT), Paul Joseph
<pj...@yahoo.com> wrote:
> Thank you very much for the reply.  I think I
> understand your method.
> 
> To simplify things however, I would like to save the
> users selection as a column in the same table (parent)
> and not in a separate table (child)
> 
> Thus the column will get data like [1,4] from the
> multivalue widget, if the user chooses item ids 1,4 in
> the multiselect.
> 
> The widget is using a set method in the fb:save that
> sets a property that is a Java Collection.
> 
> My debug statments indicate it is trying to save
> something like this [1,4] or [3,6,8] and so on.
> 
> so, to be more clear, I am trying to save a property
> of type java.util.Collection in a column of table
> Parent, in a postgresql db.
> 
> thx
> Paul
> 
> 
> --- Joose Vettenranta <jo...@iki.fi> wrote:
> 
> > >
> > > Basic question is - how does on persist a
> > collection
> > > to a postrgest table using jdo?
> >
> > Normally collection is just a 1:n connection to
> > another table, like
> >
> > create table parent (id integer);
> > create table child (id integer, parent integer);
> >
> > so you map parent to have collection Childs and then
> > that Childs
> > collection you map to be of that child table.
> >
> > - Joose
> >
> > --
> > "Always remember that you are unique, just like
> > everyone else!"
> > * http://iki.fi/joose/ * joose@iki.fi * +358 44 561
> > 0270 *
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail:
> > users-help@cocoon.apache.org
> >
> >
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 


-- 
bye,
Luca Garulli
www.OrienTechnologies.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: how to persist a Collection property to postgresql using jdo

Posted by Paul Joseph <pj...@yahoo.com>.
Thank you very much for the reply.  I think I
understand your method.

To simplify things however, I would like to save the
users selection as a column in the same table (parent)
and not in a separate table (child)

Thus the column will get data like [1,4] from the
multivalue widget, if the user chooses item ids 1,4 in
the multiselect.

The widget is using a set method in the fb:save that
sets a property that is a Java Collection.

My debug statments indicate it is trying to save
something like this [1,4] or [3,6,8] and so on.

so, to be more clear, I am trying to save a property
of type java.util.Collection in a column of table
Parent, in a postgresql db.  

thx
Paul
--- Joose Vettenranta <jo...@iki.fi> wrote:

> >
> > Basic question is - how does on persist a
> collection
> > to a postrgest table using jdo?
> 
> Normally collection is just a 1:n connection to
> another table, like
> 
> create table parent (id integer);
> create table child (id integer, parent integer);
> 
> so you map parent to have collection Childs and then
> that Childs 
> collection you map to be of that child table.
> 
> - Joose
> 
> --
> "Always remember that you are unique, just like
> everyone else!"
> * http://iki.fi/joose/ * joose@iki.fi * +358 44 561
> 0270 *
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail:
> users-help@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: how to persist a Collection property to postgresql using jdo

Posted by Joose Vettenranta <jo...@iki.fi>.
>
> Basic question is - how does on persist a collection
> to a postrgest table using jdo?

Normally collection is just a 1:n connection to another table, like

create table parent (id integer);
create table child (id integer, parent integer);

so you map parent to have collection Childs and then that Childs 
collection you map to be of that child table.

- Joose

--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org