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 ?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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
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 objectdb.com/java/jpa/setting
Thanks. Can you please answer another question by me posted at stackoverflow.com/questions/10637513/…. Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.