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].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.