I have not looked into the implementation details of your code, but is there any specific reason to user arraylist? And also, the arraylist is instantiated when declared, any specific reason why?
On Thu, Dec 24, 2009 at 5:12 AM, sahil mahajan <[email protected]> wrote: > I have "SomeClass" which I store in database. Code for the class is > /***************************************************/ > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > > public class SomeClass implements Serializable > > { > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Long id; > > @Persistent > > String val; > > @Persistent > > ArrayList<String> listval= new ArrayList<String>(); > > public void addlistval(String _val) > > { > > listval.add(_val); > > } > > public String getlistval(int _index) > > { > > return (String)listval.get(_index); > > } > > public void setval(String val) > > { > > this.val=val; > > } > > public String getname() > > { > > return val; > > } > > public int getCount() > > { > > return listval.size(); > > } > > } > > /*************************************************/ > > I have two functions > > /*********************************************/ > > void getSomeClassFromDatabase(String name) > > { > > SomeClass returnVal=null; > > > > PersistenceManager pm = PMF.get().getPersistenceManager(); > > Transaction tx = pm.currentTransaction(); > > > > try > > { > > tx.begin(); > > String query = "select from " + SomeClass.class.getName(); > > List<SomeClass> databaseSomeClass = (List<SomeClass>) > pm.newQuery(query).execute(); > > > > for (SomeClass element: databaseSomeClass) > > { > > if (name.equals(element.getname())) > > { > > returnVal=element; > > System.out.println("found"); > > break; > > } > > } > > > > tx.commit(); > > } > > finally > > { > > if (tx.isActive()) > > { > > tx.rollback(); > > } > > pm.close(); > > } > > > > System.out.println("returnVal.getval()="+returnVal.getname()); > > > System.out.println("returnVal.getCount()="+returnVal.getCount()); > > for(int k=0;k<returnVal.getCount();k++) > > { > > System.out.println("listvalue="+returnVal.getlistval(k)); > > } > > } > > /*******************************************************************/ > > > > void saveSomeClassToDatabase() > > { > > SomeClass sc=new SomeClass(); > > > > sc.setval("abcd"); > > sc.addlistval("a"); > > sc.addlistval("b"); > > sc.addlistval("c"); > > PersistenceManager pm = PMF.get().getPersistenceManager(); > > Transaction tx = pm.currentTransaction(); > > > > try > > { > > tx.begin(); > > pm.makePersistent(sc); > > tx.commit(); > > } > > finally > > { > > if (tx.isActive()) > > { > > tx.rollback(); > > } > > pm.close(); > > } > > } > > } > > /*****************************************************************/ > > I call saveSomeClassToDatabase() and then getSomeClassFromDatabase(“abcd”) > > But I get result as > > found > > returnVal.getval()=abcd > > returnVal.getCount()=0 > > > > I am not able to get ArrayList back from database. What could be the > problem? > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to > [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine-java%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > -- Regards, Michael Hoi Sang Chan MSc Advanced Software Engineering Department of Computer Science King's College London Strand, LONDON WC2R 2LS Tel: +447881900965 -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
