I am facing some problems while I am trying to fetch data through the program. I am using objectDB as my database. Also, my database is already set up and I have dropped the laptop.odb file in the db folder of my objectDB installation. Also, when I go to the explorer and fire the query:
select this.modelName == "HP Pavillion"
correct results comes up. But, when I try to do the same thing with my code as in the following
public static void main(String argv[]) {
PersistenceManager pm = Utilities.getPersistenceManager("laptop.odb");
System.out.println("-- TEST --\n");
Query query = pm.newQuery(Laptop.class,"this.modelName == \"HP Pavillion\"");
Collection result = (Collection)query.execute();
System.out.println("Result is >> "+result);
Here no results are returned. My output is :
-- TEST find --
Result is >> []
My code for the class is the following.
package com.project;
import java.util.*;
import javax.annotation.processing.Processor;
import javax.jdo.*;
import com.objectdb.Utilities;
public class Laptop {
String modelName; // key
public static void main(String argv[]) {
PersistenceManager pm = Utilities.getPersistenceManager("laptop.odb");
System.out.println("-- TEST find --\n");
Query query = pm.newQuery(Laptop.class,"this.modelName == \"HP Pavillion\"");
Collection result = (Collection)query.execute();
System.out.println("Result is >> "+result);
}
Any suggestions ?
The reason could be that "laptop.odb" refers to a non existing ObjectDB database. In that case a new database is automatically created. Because the new database it is created empty, no results are returned from the query.
Try specifying an absolute path to the existing database.