0

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 ?

ObjectDB
  • 1,312
  • 8
  • 9
Nikhil Sharma
  • 2,221
  • 6
  • 25
  • 31

1 Answers1

1

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.

ObjectDB
  • 1,312
  • 8
  • 9
  • What is the default location of creation of the database so that I can put laptop.odb file over there and hence the program does not create it again ? Thanks – Nikhil Sharma May 16 '12 at 03:26
  • The default location is the current directory (an operating system concept), but if you use "$objectdb/laptop.odb" then the location is the ObjectDB home directory, as defined on http://www.objectdb.com/java/jpa/setting – ObjectDB May 16 '12 at 14:07
  • Thanks. Can you please answer another question by me posted at http://stackoverflow.com/questions/10637513/query-in-objectdb#comment13789895_10637513. Thanks in advance. – Nikhil Sharma May 17 '12 at 14:34