Search Results

Search found 21 results on 1 pages for 'pmf'.

Page 1/1 | 1 

  • How to programmatically call a Maven-task

    - by pmf
    I'm using Maven in the context of another build-tool (leiningen for Clojure, but this should not matter), and I would like to know how I would call a plugin like dependency:build-classpath programmatically (i.e. via the Maven-API, not via the mvn-command).

    Read the article

  • Google app engine - what is the lifecycle of PersistenceManager?

    - by Domchi
    What is the preferred way of using GAE datastore PersistenceManager for web app? GAE instructions are a bit ambiguous on the matter. Do I instantiate PersistenceManagerFactory for each RPC call, or do I use only one factory for all requests? Do I call PMF.get().getPersistenceManager(), or do I call PMF.get().getPersistenceManagerProxy()? Do I close PM after each RPC call, or do I leave it open? What are you guys doing? Furthermore, I'm not certain how GAE handles 30-second-per-request limit. Is it even possible to reference the same PM between requests?

    Read the article

  • Google App Engine PersistenceManager can process multiple objects ?

    - by Frank
    I have some code like this : PersistenceManager pm=PMF.get().getPersistenceManager(); String query="select from "+PayPal_Message.class.getName()+" where processed == false order by time desc"; List<PayPal_Message> messages=(List<PayPal_Message>)pm.newQuery(query).execute(); if (messages.isEmpty()) { } else { for (PayPal_Message g : messages) { Contact_Info_Entry A_Contact_Entry=Process_PayPal_Message_To_Get_A_License(g.getContent().getValue()); pm=PMF.get().getPersistenceManager(); try { pm.makePersistent(A_Contact_Entry); g.setProcessed(true); pm.makePersistent(g); } catch (Exception e) { Send_Email(Email_From,"[email protected]","Servlet Error Message [ "+time+" ]",new Text(e.toString())); } // finally { pm.close(); } } } pm.close(); I wonder if it's ok to use the pm above to process multiple objects before closing it. Or do I have to get and close pm for processing each object ?

    Read the article

  • Filtering records in app-engine (Java)

    - by Manjoor
    I have following code running perfectly. It filter records based on single parameter. public List<Orders> GetOrders(String email) { PersistenceManager pm = PMF.get().getPersistenceManager(); Query query = pm.newQuery(Orders.class); query.setFilter("Email == pEmail"); query.setOrdering("Id desc"); query.declareParameters("String pEmail"); query.setRange(0,50); return (List<Orders>) query.execute(email); } Now i want to filter on multiple parameters. sdate and edate is Start Date and End Date. In datastore it is saved as Date (not String). public List<Orders> GetOrders(String email,String icode,String sdate, String edate) { PersistenceManager pm = PMF.get().getPersistenceManager(); Query query = pm.newQuery(Orders.class); query.setFilter("Email == pEmail"); query.setFilter("ItemCode == pItemCode"); query.declareParameters("String pEmail"); query.declareParameters("String pItemCode"); .....//Set filter and declare other 2 parameters .....// ...... query.setRange(0,50); query.setOrdering("Id desc"); return (List<Orders>) query.execute(email,icode,sdate,edate); } Any clue?

    Read the article

  • Run shell command with variable in filename via Python

    - by rajitha
    I have files with naming convention st009_out.abc1.dat st009_out.abc2.dat st009_out.abc3.dat .................. .................. I am writing Python code where I want to use data from the file to perform a math function and need to extract the second column from the file. I have tried it this way: for k in range(1,10): file1=open('st009_out.abc'+str(k)+'.dat','r') ........... os.system("awk '{print $2}' st009_out.abc${k}.pmf > raj.dat") but this is not working as it is not taking the value of k in the shell command. How do I progress?

    Read the article

  • unable to add objects to saved collection in GAE using JDO

    - by Jeffrey Chee
    I have a ClassA containing an ArrayList of another ClassB I can save a new instance of ClassA with ClassB instances also saved using JDO. However, When I retrieve the instance of Class A, I try to do like the below: ClassA instance = PMF.get().getPersistenceManager().GetObjectByID( someid ); instance.GetClassBArrayList().add( new ClassB(...) ); I get an Exception like the below: Uncaught exception from servlet com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.. So I was wondering, Is it possible to add a new item to the previously saved collection? Or was it something I missed out. Best Regards

    Read the article

  • GAE transaction exceptions

    - by bach
    Hi, In this example IS the exception being thrown if ANY of the Table elements are being changed by another client OR only if the element that we changed has been changed by another client? Just to verify - the exception is thrown from the commit() isn't it? PersistenceManager pm = PMF.get().getPersistenceManager(); try { pm.currentTransaction().begin(); List<Row> Table = (List<Row>) pm.newQuery(query).execute(); Table.get(0).setReserved(true); // <----- we change only this element pm.currentTransaction().commit(); } catch (JDOCanRetryException ex) { pm.currentTransaction().rollback() // <----- if Table.get(1) was changed by another client do we get to this point??? }

    Read the article

  • Google App Engine update an object from servlet not working ?

    - by Frank
    I use the following code to update an object from servlet in Google App Engine : String Time_Stamp=Get_Date_Format(6),query="select from "+Contact_Info_Entry.class.getName()+" where Contact_Id == '"+Contact_Id+"' order by Contact_Id desc"; PersistenceManager pm=null; try { pm=PMF.get().getPersistenceManager(); // note that this returns a list, there could be multiple, DataStore does not ensure uniqueness for non-primary key fields List<Contact_Info_Entry> results=(List<Contact_Info_Entry>)pm.newQuery(query).execute(); Contact_Info_Entry A_Contact_Entry=results.get(0); A_Contact_Entry.Extra_10=Time_Stamp; pm.makePersistent(A_Contact_Entry); } catch (Exception e) { Send_Email(Email_From,Email_To,"Check_License_Servlet Error [ "+Time_Stamp+" ]",new Text(e.toString()+"\n"+Get_Stack_Trace(e)),null); } finally { pm.close(); } The value "[ 2010-05-13 Thu 15:58:31 ]" was in A_Contact_Entry.Extra_10, but it seems "pm.makePersistent(A_Contact_Entry);" was not executed. The object was not updated and there was no error message, why ? How to fix it ?

    Read the article

  • unable to add objects to saved collection in GAE

    - by Jeffrey Chee
    I have a ClassA containing an ArrayList of another ClassB I can save a new instance of ClassA with ClassB instances also saved using JDO. However, When I retrieve the instance of Class A, I try to do like the below: ClassA instance = PMF.get().getPersistenceManager().GetObjectByID( someid ); instance.GetClassBArrayList().add( new ClassB(...) ); I get an Exception like the below: Uncaught exception from servlet com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.. So I was wondering, Is it possible to add a new item to the previously saved collection? Or was it something I missed out. Best Regards

    Read the article

  • Committed JDO writes do not apply on local GAE HRD, or possibly reused transaction

    - by eeeeaaii
    I'm using JDO 2.3 on app engine. I was using the Master/Slave datastore for local testing and recently switched over to using the HRD datastore for local testing, and parts of my app are breaking (which is to be expected). One part of the app that's breaking is where it sends a lot of writes quickly - that is because of the 1-second limit thing, it's failing with a concurrent modification exception. Okay, so that's also to be expected, so I have the browser retry the writes again later when they fail (maybe not the best hack but I'm just trying to get it working quickly). But a weird thing is happening. Some of the writes which should be succeeding (the ones that DON'T get the concurrent modification exception) are also failing, even though the commit phase completes and the request returns my success code. I can see from the log that the retried requests are working okay, but these other requests that seem to have committed on the first try are, I guess, never "applied." But from what I read about the Apply phase, writing again to that same entity should force the apply... but it doesn't. Code follows. Some things to note: I am attempting to use automatic JDO caching. So this is where JDO uses memcache under the covers. This doesn't actually work unless you wrap everything in a transaction. all the requests are doing is reading a string out of an entity, modifying part of the string, and saving that string back to the entity. If these requests weren't in transactions, you'd of course have the "dirty read" problem. But with transactions, isolation is supposed to be at the level of "serializable" so I don't see what's happening here. the entity being modified is a root entity (not in a group) I have cross-group transactions enabled Another weird thing is happening. If the concurrent modification thing happens, and I subsequently edit more than 5 more entities (this is the max for cross-group transactions), then nothing happens right away, but when I stop and restart the server I get "IllegalArgumentException: operating on too many entity groups in a single transaction". Could it be possible that the PMF is returning the same PersistenceManager every time, or the PM is reusing the same transaction every time? I don't see how I could possibly get the above error otherwise. The code inside the transaction just edits one root entity. I can't think of any other way that GAE would give me the "too many entity groups" error. The relevant code (this is a simplified version) PersistenceManager pm = PMF.getManager(); Transaction tx = pm.currentTransaction(); String responsetext = ""; try { tx.begin(); // I have extra calls to "makePersistent" because I found that relying // on pm.close didn't always write the objects to cache, maybe that // was only a DataNucleus 1.x issue though Key userkey = obtainUserKeyFromCookie(); User u = pm.getObjectById(User.class, userkey); pm.makePersistent(u); // to make sure it gets cached for next time Key mapkey = obtainMapKeyFromQueryString(); // this is NOT a java.util.Map, just FYI Map currentmap = pm.getObjectById(Map.class, mapkey); Text mapData = currentmap.getMapData(); // mapData is JSON stored in the entity Text newMapData = parseModifyAndReturn(mapData); // transform the map currentmap.setMapData(newMapData); // mutate the Map object pm.makePersistent(currentmap); // make sure to persist so there is a cache hit tx.commit(); responsetext = "OK"; } catch (JDOCanRetryException jdoe) { // log jdoe responsetext = "RETRY"; } catch (Exception e) { // log e responsetext = "ERROR"; } finally { if (tx.isActive()) { tx.rollback(); } pm.close(); } resp.getWriter().println(responsetext); EDIT: so I have verified that it fails after exactly 5 transactions. Here's what I do: I create a Foo (root entity), do a bunch of concurrent operations on that Foo, and some fail and get retried, and some commit but don't apply (as described above). Then, I start creating more Foos, and do a few operations on those new Foos. If I only create four Foos, stopping and restarting app engine does NOT give me the IllegalArgumentException. However if I create five Foos (which is the limit for cross-group transactions), then when I stop and restart app engine, I do get the exception. So it seems that somehow these new Foos I am creating are counting toward the limit of 5 max entities per transaction, even though they are supposed to be handled by separate transactions. It's as if a transaction is still open and is being reused by the servlet when it handles the new requests for the 2nd through 5th Foos. EDIT2: it looks like the IllegalArgument thing is independent of the other bug. In other words, it always happens when I create five Foos, even if I don't get the concurrent modification exception. I don't know if it's a symptom of the same problem or if it's unrelated. EDIT3: I found out what was causing the (unrelated) IllegalArgumentException, it was a dumb mistake on my part. But the other issue is still happening. EDIT4: added pseudocode for the datastore access EDIT5: I am pretty sure I know why this is happening, but I will still award the bounty to anyone who can confirm it. Basically, I think the problem is that transactions are not really implemented in the local version of the datastore. References: https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/gVMS1dFSpcU https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/deGasFdIO-M https://groups.google.com/forum/?hl=en&fromgroups=#!msg/google-appengine-java/4YuNb6TVD6I/gSttMmHYwo0J Because transactions are not implemented, rollback is essentially a no-op. Therefore, I get a dirty read when two transactions try to modify the record at the same time. In other words, A reads the data and B reads the data at the same time. A attempts to modify the data, and B attempts to modify a different part of the data. A writes to the datastore, then B writes, obliterating A's changes. Then B is "rolled back" by app engine, but since rollbacks are a no-op when running on the local datastore, B's changes stay, and A's do not. Meanwhile, since B is the thread that threw the exception, the client retries B, but does not retry A (since A was supposedly the transaction that succeeded).

    Read the article

  • Google Datastore w/ JDO: Access Times?

    - by Bosh
    I'm hitting what appears (to me) strange behavior when I pull data from the google datastore over JDO. In particular, the query executes quickly (say 100 ms), but finding the size of the resulting List< takes about one second! Indeed, whatever operation I try to perform on the resulting list takes about a second. Has anybody seen this behavior? Is it expected? Unusual? Any way around it? PersistenceManager pm = PMF.getPersistenceManager(); Query q = pm.newQuery("select from " + Person.class.getName() +" order by key limit 1000 "); System.out.println("getting all at " + System.currentTimeMillis()); mcs = (List<Med>) q.execute(); System.out.println("got all at " + System.currentTimeMillis()); int size = mcs.size(); System.out.println("size was " + size + " at " + System.currentTimeMillis()); getting all at 1271549139441 got all at 1271549139578 size was 850 at 1271549141071 -B

    Read the article

  • Appengine datastore phantom entity - inconsistent state?

    - by aloo
    Getting a weird error on java appengine code that used to work fine (nothing has changed but the data in the datastore). I'm trying to iterate over the results of a query and change a few properties of the entities. The query does return a set of results, however, when I try to access the first result in the list, it throws an exception when trying to access any of its properties (but its key). Here's the exception: org.datanucleus.state.JDOStateManagerImpl isLoaded: Exception thrown by StateManager.isLoaded Could not retrieve entity of kind OnTheCan with key OnTheCan(3204258) org.datanucleus.exceptions.NucleusObjectNotFoundException: Could not retrieve entity of kind OnTheCan with key OnTheCan(3204258) at org.datanucleus.store.appengine.DatastoreExceptionTranslator.wrapEntityNotFoundException(DatastoreExceptionTranslator.java:60) And here is my code: PersistenceManager pm = PMF.get().getPersistenceManager(); Query query = null; List<OnTheCan> cans; query = pm.newQuery("SELECT this FROM " + OnTheCan.class.getName() + " WHERE open == true ORDER BY onTheCanId ASC"); query.setRange(0, num); cans = (List<OnTheCan>) query.execute(); for (OnTheCan c : cans) { System.err.println(c.getOnTheCanId()); // this works fine! getting the key works c.setOpen(false); // failure here with the above exception c.setAutoClosed(true); c.setEndTime(new Date(c.getStartTime().getTime() + 600000/*10*60*1000*/)); } pm.close(); The code throws the exception when trying to execute c.setOpen(false) - thats the first time I'm accessing or setting a property that isnt the key. So it seems there is a phantom entity in my datastore with key 3204258. THis entity doesn't really exist (queried the datastore from admin console) but for some reason its being returned by the query. Could my data store be in an inconsistent state? I've managed the following workaround by placing it as the first line in my for loop. Clearly an ugly hack: if (c.getOnTheCanId() == 3204258) { continue; } Any ideas?

    Read the article

  • JDO difficulties in retrieving persistent vector

    - by Michael Omer
    I know there are already some posts regarding this subject, but although I tried using them as a reference, I am still stuck. I have a persistent class as follows: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class GameObject implements IMySerializable{ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) protected Key m_databaseKey; @NotPersistent private final static int END_GAME_VAR = -1000; @Persistent(defaultFetchGroup = "true") protected GameObjectSet m_set; @Persistent protected int m_databaseType = IDatabaseAccess.TYPE_NONE; where GameObjectSet is: @PersistenceCapable(identityType = IdentityType.APPLICATION) @FetchGroup(name = "mySet", members = {@Persistent(name = "m_set")}) public class GameObjectSet { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key id; @Persistent private Vector<GameObjectSetPair> m_set; and GameObjectSetPair is: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class GameObjectSetPair { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key id; @Persistent private String key; @Persistent(defaultFetchGroup = "true") private GameObjectVar value; When I try to fetch the entire structure by fetching the GameObject, the set doesn't have any elements (they are all null) I tried adding the fetching group to the PM, but to no avail. This is my fetching code Vector<GameObject> ret = new Vector<GameObject>(); PersistenceManager pm = PMF.get().getPersistenceManager(); pm.getFetchPlan().setMaxFetchDepth(-1); pm.getFetchPlan().addGroup("mySet"); Query myQuery = pm.newQuery(GameObject.class); myQuery.setFilter("m_databaseType == objectType"); myQuery.declareParameters("int objectType"); try { List<GameObject> res = (List<GameObject>)myQuery.execute(objectType); ret = new Vector<GameObject>(res); for (int i = 0; i < ret.size(); i++) { ret.elementAt(i).getSet(); ret.elementAt(i).getSet().touchSet(); } } catch (Exception e) { } finally { pm.close(); } Does anyone have any idea? Thanks Mike

    Read the article

  • Illegal Argument Exception in Google Wave App

    - by Yoenhofen
    I'm writing a Google Wave robot and I just messed something up. It was working just fine but now I'm getting an IllegalArgument exception on the line that includes query.execute. Am I doing something stupid? I've seen several code samples very similar to what I'm doing. I can include the code of the WaveUpdate class if necessary. The intent here is to select all WaveUpdate members that have an updateDateTime in the last hour. PersistenceManager pm = PMF.get().getPersistenceManager(); try { Query query = pm.newQuery(WaveUpdate.class); query.setFilter("emailAddress > '' && updateDateTime > referenceDateTime"); query.declareParameters("java.util.Date referenceDateTime"); Calendar referenceDateTime = Calendar.getInstance(); referenceDateTime.add(Calendar.HOUR_OF_DAY, -1); List<WaveUpdate> updates = (List<WaveUpdate>) query.execute(referenceDateTime.getTime());

    Read the article

  • Can't wrap my head around appengine data store persistence

    - by aloo
    Hi, I've run into the "can't operate on multiple entity groups in a single transaction." problem when using APPENGINE FOR JAVA w/ JDO with the following code: PersistenceManager pm = PMF.get().getPersistenceManager(); Query q = pm.newQuery("SELECT this FROM " + TypeA.class.getName() + " WHERE userId == userIdParam "); q.declareParameters("String userIdParam"); List<TypeA> poos = (List<TypeA>) q.execute(userIdParam); for (TypeA a : allTypeAs) { a.setSomeField(someValue); } pm.close(); } The problem it seems is that I can't operate on a multiple entities at the same time b/c they arent in the same entity group while in a transaction. Even though it doesn't seem like I'm in a transaction, appengine generates one because I have the following set in my jdoconfig.xml: <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/> Fine. So far I think I understand. BUT - if I replace TypeA in the above code, with TypeB - I don't get the error. I don't believe there is anything different between type a and type b - they both have the same key structure. They do have different fields but that shouldn't matter, right? My question is - what could possible be different between TypeA and TypeB that they give this different behavior? And consequently what do you I fundamentally misunderstand that this behavior could even exist.... Thanks.

    Read the article

  • Google App-Engine Java Batch Update

    - by Manjoor
    I need to upload a .csv file and save the records in bigtable. My application successfully parse 200 the records in the csv files and save to table. Here is my code to save the data. for (int i=0;i<lines.length -1;i++) //lines hold total records in csv file { String line = lines[i]; //The record have 3 columns integer,integer,Text if(line.length() > 15) { int n = line.indexOf(","); if (n>0) { int ID = lInteger.parseInt(ine.substring(0,n)); int n1 = line.indexOf(",", n + 2); if(n1 > n) { int Col1 = Integer.parseInt(line.substring(n + 1, n1)); String Col2 = line.substring(n1 + 1); myTable uu = new myTable(); uu.setId(ID); uu.setCol1(MobNo); Text t = new Text(Col2); uu.setCol2(t); PersistenceManager pm = PMF.get().getPersistenceManager(); pm.makePersistent(uu); pm.close(); } } } } But when no of records grow it gives timeout error. The csv file may have upto 800 records. Is it possible to do that in App-Engine? (something like batch update)

    Read the article

  • Google App Engine datastore encoding?

    - by sernaferna
    I'm using the GAE datastore for a Java application, and storing some text that will be in numerous languages. In my servlet, I'm first checking to see if there's any data in the data store, and, if not, I'm creating some, similar to the following: ArrayList<Lang> list = new ArrayList<Lang>(); list.add(new Lang("EN", "English", 1)); list.add(new Lang("ES", "Español", 0)); //more languages here... PersistenceManager pm = PMF.get().getPersistenceManager(); for(Lang l : list) { pm.makePersistent(l); } Since this is using JDO, I guess I should include the relevent parts of the Lang class too: @PersistenceCapable public class Lang { @PrimaryKey private String code; @Persistent private String name; @Persistent private int popularity; // getters & setters & constructors... } However, the non-ASCII characters are giving me grief. I've set my Eclipse project to use the UTF-8 encoding instead of the default Cp1252, so I think I'm okay from that perspective, but when I use the App Engine Data Viewer to look at my data, that Español entry becomes Español, and when I click on it to view it, I get a 500 Server Error. (There are some other entries with right-to-left text that don't even show up in the Data Viewer at all, but one problem at a time...) Is there anything special I can do in my code to set the character encoding, or specify to GAE that the data I'm storing is UTF-8? Or is the problem on the Eclipse side, and is there something I should be doing with my Java code?

    Read the article

  • GWT + JDO + ArrayList

    - by dvieira
    Hi, I'm getting a Null ArrayList in a program i'm developing. For testing purposes I created this really small example that still has the same problem. I already tried diferent Primary Keys, but the problem persists. Any ideas or suggestions? 1-Employee class @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Employee { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") private String key; @Persistent private ArrayList<String> nicks; public Employee(ArrayList<String> nicks) { this.setNicks(nicks); } public String getKey() { return key; } public void setNicks(ArrayList<String> nicks) { this.nicks = nicks; } public ArrayList<String> getNicks() { return nicks; } } 2-EmployeeService public class BookServiceImpl extends RemoteServiceServlet implements EmployeeService { public void addEmployee(){ ArrayList<String> nicks = new ArrayList<String>(); nicks.add("name1"); nicks.add("name2"); Employee employee = new Employee(nicks); PersistenceManager pm = PMF.get().getPersistenceManager(); try { pm.makePersistent(employee); } finally { pm.close(); } } /** * @return * @throws NotLoggedInException * @gwt.typeArgs <Employee> */ public Collection<Employee> getEmployees() { PersistenceManager pm = getPersistenceManager(); try { Query q = pm.newQuery("SELECT FROM " + Employee.class.getName()); Collection<Employee> list = pm.detachCopyAll((Collection<Employee>)q.execute()); return list; } finally { pm.close(); } } }

    Read the article

  • App Engine - Query using a class member as parameter

    - by Zach
    I have a simple class, relevant details below: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class SimpleCategory implements Serializable{ ... public static enum type{ Course, Category, Cuisine } @Persistent public type t; ... } I am attempting to query all SimpleCategory objects of the same type. public SimpleCategory[] getCategories(SimpleCategory.type type) { PersistenceManager pm = PMF.get().getPersistenceManager(); try{ Query q = pm.newQuery(SimpleCategory.class); q.setFilter("t == categoryType"); q.declareParameters("SimpleCategory.type categoryType"); List<SimpleCategory> cats = (List<SimpleCategory>) q.execute(type); ... } This results in a ClassNotResolvedException for SimpleCategory.type. The google hits I've found so far recommended to: Use query.declareImports to specify the class i.e. q.declareImports("com.test.zach.SimpleCategory.type"); Specify the fully qualified name of SimpleCategory in declareParameters Neither of these suggestions has worked. By removing .type and recompiling, I can verify that declareParameters can see SimpleCategory just fine, it simply cannot see the SimpleCategory.type, despite the fact that the remainder of the method has full visibility to it. What am I missing?

    Read the article

  • ArrayList throwing exception on retrieval from google datastore (with gwt, java)

    - by sumeet
    I'm using Google Web Toolkit with java and google datastore as database. The entity class has arraylist and on trying to retrieve the data from data base I'm getting the exception: Type 'org.datanucleus.sco.backed.ArrayList' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized. I'm using JPA. Entity code: package com.ver2.DY.client; import java.io.Serializable; import java.util.ArrayList; import javax.jdo.annotations.IdGeneratorStrategy; import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.Persistent; import javax.jdo.annotations.PrimaryKey; import com.google.gwt.user.client.rpc.IsSerializable; @PersistenceCapable public class ChatInfo implements Serializable, IsSerializable{ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long topicId; @Persistent private String chatTopic; @Persistent private ArrayList messages = new ArrayList(); @Persistent private boolean isFirstPost; public ChatInfo() { } public Long getTopicId() { return topicId; } public void setTopicId(Long topicId) { this.topicId = topicId; } public String getChatTopic() { return chatTopic; } public void setChatTopic(String chatTopic) { this.chatTopic = chatTopic; } public ArrayList getMessages() { return messages; } public void addMessage(String newMsg) { messages.add(newMsg); } public boolean isFirstPost() { return isFirstPost; } public void setFirstPost(boolean isFirstPost) { this.isFirstPost = isFirstPost; } } Method in db class: @Transactional public ChatInfo[] getAllChat() { PersistenceManager pm = PMF.get().getPersistenceManager(); List chats = null; ChatInfo[] infos = null; String query = "select from " + ChatInfo.class.getName(); try{ chats = (List) pm.newQuery(query).execute(); infos = new ChatInfo[chats.size()]; for(int i=0;i } It is a bit strange because earlier I was able to insert and retrieve the data but it now throwing an exception. On searching the web I could find that I need to convert the Arraylist from some DataNucleus type to java util but not sure how to do that.

    Read the article

  • Why can't Java servlet sent out an object ?

    - by Frank
    I use the following method to send out an object from a servlet : public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException { String Full_URL=request.getRequestURL().append("?"+request.getQueryString()).toString(); String Contact_Id=request.getParameter("Contact_Id"); String Time_Stamp=Get_Date_Format(6),query="select from "+Contact_Info_Entry.class.getName()+" where Contact_Id == '"+Contact_Id+"' order by Contact_Id desc"; PersistenceManager pm=null; try { pm=PMF.get().getPersistenceManager(); // note that this returns a list, there could be multiple, DataStore does not ensure uniqueness for non-primary key fields List<Contact_Info_Entry> results=(List<Contact_Info_Entry>)pm.newQuery(query).execute(); Write_Serialized_XML(response.getOutputStream(),results.get(0)); } catch (Exception e) { Send_Email(Email_From,Email_To,"Check_License_Servlet Error [ "+Time_Stamp+" ]",new Text(e.toString()+"\n"+Get_Stack_Trace(e)),null); } finally { pm.close(); } } /** Writes the object and CLOSES the stream. Uses the persistance delegate registered in this class. * @param os The stream to write to. * @param o The object to be serialized. */ public static void writeXMLObject(OutputStream os,Object o) { // Classloader reference must be set since netBeans uses another class loader to loead the bean wich will fail in some circumstances. ClassLoader oldClassLoader=Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(Check_License_Servlet.class.getClassLoader()); XMLEncoder encoder=new XMLEncoder(os); encoder.setExceptionListener(new ExceptionListener() { public void exceptionThrown(Exception e) { e.printStackTrace(); }}); encoder.writeObject(o); encoder.flush(); encoder.close(); Thread.currentThread().setContextClassLoader(oldClassLoader); } private static ByteArrayOutputStream writeOutputStream=new ByteArrayOutputStream(16384); /** Writes an object to XML. * @param out The boject out to write to. [ Will not be closed. ] * @param o The object to write. */ public static synchronized void writeAsXML(ObjectOutput out,Object o) throws IOException { writeOutputStream.reset(); writeXMLObject(writeOutputStream,o); byte[] Bt_1=writeOutputStream.toByteArray(); byte[] Bt_2=new Des_Encrypter().encrypt(Bt_1,Key); out.writeInt(Bt_2.length); out.write(Bt_2); out.flush(); out.close(); } public static synchronized void Write_Serialized_XML(OutputStream Output_Stream,Object o) throws IOException { writeAsXML(new ObjectOutputStream(Output_Stream),o); } At the receiving end the code look like this : File_Url="http://"+Site_Url+App_Dir+File_Name; try { Contact_Info_Entry Online_Contact_Entry=(Contact_Info_Entry)Read_Serialized_XML(new URL(File_Url)); } catch (Exception e) { e.printStackTrace(); } private static byte[] readBuf=new byte[16384]; public static synchronized Object readAsXML(ObjectInput in) throws IOException { // Classloader reference must be set since netBeans uses another class loader to load the bean which will fail under some circumstances. ClassLoader oldClassLoader=Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(Tool_Lib_Simple.class.getClassLoader()); int length=in.readInt(); readBuf=new byte[length]; in.readFully(readBuf,0,length); byte Bt[]=new Des_Encrypter().decrypt(readBuf,Key); XMLDecoder dec=new XMLDecoder(new ByteArrayInputStream(Bt,0,Bt.length)); Object o=dec.readObject(); Thread.currentThread().setContextClassLoader(oldClassLoader); in.close(); return o; } public static synchronized Object Read_Serialized_XML(URL File_Url) throws IOException { return readAsXML(new ObjectInputStream(File_Url.openStream())); } But I can't get the object from the Java app that's on the receiving end, why ? The error messages look like this : java.lang.ClassNotFoundException: PayPal_Monitor.Contact_Info_Entry Continuing ... java.lang.NullPointerException: target should not be null Continuing ... java.lang.NullPointerException: target should not be null Continuing ... java.lang.NullPointerException: target should not be null Continuing ...

    Read the article

1