I dont know if my first message actually reached the list or not, if
so sorry for the dupe. But one more thing to add, I noticed bug 1299
covers this issue and I made a comment there as well.
>>>original message I tried to post.
Werner, I was actually thinking about that, and it would be possible
with some kind of delimeter or something. Of course this option would
only work with basic data types, such as Strings, ints, chars,
etc...but there are to many factors I think to do it cleanly, and in a
way that couldn't be broken.
-Nick
>
> On Fri, 05 Nov 2004 20:49:46 +0100, Werner Guttmann
> <[EMAIL PROTECTED]> wrote:
> >
> > Andreas,
> >
> > Out of curiosity, how would one go about storing an array of values in a varchar
> > field anyhow ?
> >
> > Werner
> >
> >
> >
> > On Fri, 5 Nov 2004 08:47:00 -0500, Nick Stuart wrote:
> >
> > >
> > >Andreas, I misunderstood your first post. This type of setup will not
> > >work unfortunately. When storing collections/arrays they need to be
> > >stored if a separate table and be linked by some kind of key back to
> > >the parent object.
> > >
> > >For now there is no way to store an array of objects directly in a
> > >field of a database.
> > >
> > >-Nick
> > >
> > >
> > >On Fri, 05 Nov 2004 14:38:18 +0100, Andreas Vombach
> > ><[EMAIL PROTECTED]> wrote:
> > >>
> > >> Hi Werner,
> > >>
> > >> thank you very much for your reply. No, it shall be only one one table like
> > >>
> > >> create table test (ID integer PRIMARY KEY NOT NULL, MYARRAY varchar(255));
> > >>
> > >> As said it works for the first element to be inserted and the MYARRAY
> > >> column looks like [Ljava.lang.String;@f42ad0 in the db
> > >> which appears to be the serialized form of new String[] {"1", "2", "3",
> > >> "4", "5"} and it is retrievable after insert.
> > >> Inserting a second row causes the exception on retrieve. Here the test
> > >> program: (the "mydb.xml" is as usual, engine is MySQL in my case)
> > >>
> > >> import java.util.*;
> > >> import org.exolab.castor.jdo.*;
> > >> import org.exolab.castor.mapping.*;
> > >>
> > >> public class jdotest
> > >> {
> > >> static JDO jdo;
> > >> static Database db;
> > >>
> > >> public static void main (String[] args)
> > >> {
> > >> jdo = new JDO("mydb");
> > >> try
> > >> {
> > >> jdo.loadConfiguration("mydb.xml");
> > >> }
> > >> catch (Exception ex)
> > >> {
> > >> System.out.println("JDO load Exception: " + ex);
> > >> }
> > >> try
> > >> {
> > >> db = jdo.getDatabase();
> > >> test t = new test();
> > >> t.setId(new Integer(1));
> > >> t.setMyarray(new String[] {"1", "2", "3", "4", "5"});
> > >> db.create(t);
> > >> db.commit();
> > >> db.close();
> > >> System.out.println("store ok, id: " + t.getId());
> > >> db = jdo.getDatabase();
> > >> db.begin();
> > >> OQLQuery query = db.getOQLQuery("SELECT a FROM test a WHERE id=$1");
> > >> query.bind(new Integer(1));
> > >> QueryResults results = query.execute(Database.ReadOnly);
> > >> test res = (test) results.next();
> > >> System.out.println("test retrieved");
> > >> System.out.println("id: " + res.getId());
> > >> String[] s = res.getMyarray();
> > >> for (int i = 0; i < s.length; i++) System.out.println("myarray:
> > >> " + s[i]);
> > >> }
> > >> catch (Exception ex)
> > >> {
> > >> System.out.println("JDO queryException: " + ex);
> > >> ex.printStackTrace();
> > >> }
> > >> try
> > >> {
> > >> db.close();
> > >> }
> > >> catch (PersistenceException ex) {}
> > >>
> > >>
> > >> }
> > >> }
> > >>
> > >> -----------------------------------------------------------
> > >> If you wish to unsubscribe from this mailing, send mail to
> > >> [EMAIL PROTECTED] with a subject of:
> > >> unsubscribe castor-user
> > >>
> > >
> > >
> > >
> > >-----------------------------------------------------------
> > >If you wish to unsubscribe from this mailing, send mail to
> > >[EMAIL PROTECTED] with a subject of:
> > > unsubscribe castor-user
> > >
> >
> >
> > -----------------------------------------------------------
> >
> >
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-user
> >
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user