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